Skip to content

Instantly share code, notes, and snippets.

@hmrizin
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmrizin/9645816 to your computer and use it in GitHub Desktop.
Save hmrizin/9645816 to your computer and use it in GitHub Desktop.
Elasticsearch has_child queries throw error if queryName is set.
# 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"}'
# 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" : [ ]
}
}
# 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