Created
June 4, 2013 14:50
-
-
Save q42jaap/5706508 to your computer and use it in GitHub Desktop.
Reproduction of faceting of has_child query
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
#!/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 | |
}' | |
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
#!/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