Here is en examples about join
type in elasticsearch. I have insert mapping, parents and children:
PUT my_index
{
"mappings": {
"doc": {
"properties": {
"my_join_field": {
"type": "join",
"relations": {
"question": "answer"
}
}
}
}
}
}
PUT my_index/doc/1?refresh
{
"text": "This is a question",
"my_join_field": {
"name": "question"
}
}
PUT my_index/doc/2?refresh
{
"text": "This is a another question",
"my_join_field": {
"name": "question"
}
}
PUT my_index/doc/1?refresh
{
"text": "This is a question",
"my_join_field": "question"
}
PUT my_index/doc/2?refresh
{
"text": "This is another question",
"my_join_field": "question"
}
Now I am trying to search for parents by children:
GET /my_index/doc/_search
{
"query": {
"has_child": {
"type": "my_join_field",
"query": {
"match" : {
"text": "question"
}
},
"ignore_unmapped": true
}
},
"highlight" : {
"fields" : {
"content" : {}
}
}
}
And I got no results. :( >:(
First of all what type
fields should be??? They are told that types are removed
Second, I have to add ignore_unmapped
(look here) and still no results
So how to find parent by has_child
query for data in elasticsearch example?
Look at 11_parent_child.yml file. It contains indexing of parent, child and performs query for children. It is yaml
but I think conversion to json
is obvious.