Skip to content

Instantly share code, notes, and snippets.

@pkrakowiak
Created November 20, 2012 07:37
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 pkrakowiak/4116598 to your computer and use it in GitHub Desktop.
Save pkrakowiak/4116598 to your computer and use it in GitHub Desktop.
Parent/child queries in ElasticSearch
curl -XPUT localhost:9200/authors/bare_author/1 -d'{
"name": "Multi G. Enre"
}'
curl -XPUT localhost:9200/authors/bare_author/2 -d'{
"name": "Alastair Reynolds"
}'
curl -XPOST localhost:9200/authors/book/_mapping -d '{
"book":{
"_parent": {"type": "bare_author"}
}
}'
curl -XPOST localhost:9200/authors/book/1?parent=2 -d '{
"name": "Revelation Space",
"genre": "scifi",
"publisher": "penguin"
}'
curl -XPOST localhost:9200/authors/book/2?parent=1 -d '{
"name": "Guns and lasers",
"genre": "scifi",
"publisher": "orbit"
}'
curl -XPOST localhost:9200/authors/book/3?parent=1 -d '{
"name": "Dead in the night",
"genre": "thriller",
"publisher": "penguin"
}'
curl -XPOST localhost:9200/authors/bare_author/_search -d '{
"query": {
"has_child": {
"type": "book",
"query" : {
"filtered": {
"query": { "match_all": {}},
"filter" : {
"and": [
{"term": {"publisher": "penguin"}},
{"term": {"genre": "scifi"}}
]
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment