Skip to content

Instantly share code, notes, and snippets.

@q42jaap
Created June 4, 2013 14:50
Show Gist options
  • Save q42jaap/5706508 to your computer and use it in GitHub Desktop.
Save q42jaap/5706508 to your computer and use it in GitHub Desktop.
Reproduction of faceting of has_child query
#!/bin/sh
# assume the index products doesn't exist
# otherwise uncomment the following line
# curl -XDELETE localhost:9200/products
curl -XPUT localhost:9200/products/product/1 -d'{
"property1": "value1"
}'
curl -XPUT localhost:9200/products/product/2 -d'{
"property1": "value2"
}'
curl -XPOST localhost:9200/products/offer/_mapping -d '{
"book":{
"_parent": {"type": "product"}
}
}'
curl -XPOST localhost:9200/products/offer/1?parent=1 -d '{
"color": "blue",
"size": 1
}'
curl -XPOST localhost:9200/products/offer/2?parent=1 -d '{
"color": "red",
"size": 2
}'
curl -XPOST localhost:9200/products/offer/3?parent=2 -d '{
"color": "blue",
"size": 3
}'
#!/bin/sh
curl -s -XPOST 'localhost:9200/products/_search?pretty=true' -d '{
"query" : {
"bool" : {
"must" : [
{
"term" : { "property1" : "value1" }
},
{
"has_child" : {
"type" : "offer",
"query" : {
"term" : {
"color" : "blue"
}
}
}
}
]
}
},
"facets" : {
"size" : {
"terms" : {
"field" : "size"
},
"global" : true,
"facet_filter" : {
"bool" : {
"must" : [
{ "term" : { "color" : "blue" } },
{ "term" : { "property1" : "value1" } }
]
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment