Created
September 5, 2012 14:23
-
-
Save lukas-vlcek/3637424 to your computer and use it in GitHub Desktop.
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
# ######################## | |
# Create mapping for Parent / Child | |
curl -X POST 'http://localhost:9200/families/' -d '{ | |
"mappings" : { | |
"family" : { | |
"properties" : { | |
"name" : {"type" : "string", "store" : "yes"} | |
} | |
}, | |
"member" : { | |
"_parent" : { | |
"type" : "family" | |
}, | |
"properties" : { | |
"name" : {"type" : "string", "store" : "yes"}, | |
"role" : {"type" : "string", "index" : "not_analyzed"} | |
} | |
} | |
}, | |
"settings" : { | |
"number_of_shards" : 1, | |
"number_of_replicas" : 0 | |
} | |
}' | |
# ######################## | |
# Index parent | |
curl -X PUT 'localhost:9200/families/family/1' -d ' | |
{ | |
"name" : "Collins", | |
"motto" : "Happy day" | |
}' | |
# ######################## | |
# Index children | |
curl -X POST 'localhost:9200/families/member?parent=1' -d ' | |
{ | |
"name" : "Jan", | |
"role" : "dad" | |
}' | |
curl -X POST 'localhost:9200/families/member?parent=1' -d ' | |
{ | |
"name" : "Rudy", | |
"role" : "mom" | |
}' | |
# ######################## | |
# Flush | |
curl -X POST 'http://localhost:9200/_flush?refresh=true' | |
# ######################## | |
# Use "Has Child Filter" | |
curl -X GET 'http://localhost:9200/families/family/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"constant_score" : { | |
"filter" : { | |
"has_child" : { | |
"type" : "member", | |
"query" : { | |
"query_string" : { | |
"query" : "dad AND jan" | |
} | |
} | |
} | |
} | |
} | |
}, | |
"fields" : [ | |
"name" | |
], | |
"explain" : true | |
}' | |
# ######################## | |
# Use "Has Child Query" | |
curl -X GET 'http://localhost:9200/families/family/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"has_child" : { | |
"type" : "member", | |
"query" : { | |
"query_string" : { | |
"query" : "dad AND jan" | |
} | |
} | |
} | |
}, | |
"fields" : [ | |
"name" | |
], | |
"explain" : true | |
}' | |
## Explanation from **filter** | |
"_explanation" : { | |
"value" : 1.0, | |
"description" : "ConstantScore(NotDeleted(child_filter[member/family](filtered(+_all:dad +_all:jan)->cache(_type:member)))), product of:", | |
"details" : [ { | |
"value" : 1.0, | |
"description" : "boost" | |
}, { | |
"value" : 1.0, | |
"description" : "queryNorm" | |
} ] | |
} | |
## Explanation from **query** | |
"_explanation" : { | |
"value" : 1.0, | |
"description" : "ConstantScore(child_filter[member/family](filtered(+_all:dad +_all:jan)->cache(_type:member))), product of:", | |
"details" : [ { | |
"value" : 1.0, | |
"description" : "boost" | |
}, { | |
"value" : 1.0, | |
"description" : "queryNorm" | |
} ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the answer:
https://github.com/elasticsearch/elasticsearch/blob/v0.19.9/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java#L111