Created
November 20, 2012 07:37
-
-
Save pkrakowiak/4116598 to your computer and use it in GitHub Desktop.
Parent/child queries in ElasticSearch
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
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