Skip to content

Instantly share code, notes, and snippets.

@lukas-vlcek
Created September 5, 2012 14:23
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 lukas-vlcek/3637424 to your computer and use it in GitHub Desktop.
Save lukas-vlcek/3637424 to your computer and use it in GitHub Desktop.
# ########################
# 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