Last active
August 29, 2015 13:57
-
-
Save hmrizin/9645816 to your computer and use it in GitHub Desktop.
Elasticsearch has_child queries throw error if queryName is set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cleanup | |
curl -XDELETE 'http://localhost:9200/twtest' | |
# create index mappings | |
curl -XPOST 'http://localhost:9200/twtest' -d '{ | |
"mappings": { | |
"account": { | |
"_id": { | |
"path": "accountid" | |
}, | |
"properties": { | |
"accountid": { | |
"type": "string", | |
"index": "not_analyzed" | |
} | |
} | |
}, | |
"post": { | |
"_id": { | |
"path": "postid" | |
}, | |
"_parent": { | |
"type": "account" | |
}, | |
"properties": { | |
"postid": { | |
"type": "string", | |
"index": "not_analyzed" | |
} | |
} | |
} | |
} | |
}' | |
# add documents | |
curl -XPOST "http://localhost:9200/twtest/account/" -d '{"accountid": "acc1"}' | |
curl -XPOST "http://localhost:9200/twtest/post?parent=acc1" -d '{"postid": "p1"}' | |
curl -XPOST "http://localhost:9200/twtest/post?parent=acc1" -d '{"postid": "p2"}' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# named has_child query | |
curl -XPOST "http://localhost:9200/twtest/account/_search?pretty=true" -d '{ | |
"query": { | |
"has_child": { | |
"query": { | |
"term": { | |
"postid": "p1" | |
} | |
}, | |
"child_type": "post", | |
"_name": "somename" | |
} | |
} | |
}' | |
# error response | |
{ | |
"took" : 4, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 4, | |
"failed" : 1, | |
"failures" : [ { | |
"index" : "twtest", | |
"shard" : 1, | |
"status" : 500, | |
"reason" : "ElasticSearchIllegalStateException[has_child filter hasn't executed properly]" | |
} ] | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 1.0, | |
"hits" : [ ] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# has_child query wrapped in named boolean query | |
curl -XPOST "http://localhost:9200/twtest/account/_search?pretty=true" -d '{ | |
"query": { | |
"bool": { | |
"should": { | |
"has_child": { | |
"query": { | |
"term": { | |
"postid": "p2" | |
} | |
}, | |
"child_type": "post" | |
} | |
}, | |
"_name": "somename" | |
} | |
} | |
}' | |
# error response | |
{ | |
"took" : 4, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 4, | |
"failed" : 1, | |
"failures" : [ { | |
"index" : "twtest", | |
"shard" : 1, | |
"status" : 500, | |
"reason" : "ElasticSearchIllegalStateException[has_child filter hasn't executed properly]" | |
} ] | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 1.0, | |
"hits" : [ ] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment