Skip to content

Instantly share code, notes, and snippets.

@rukshanperera
Last active August 29, 2015 13:57
Show Gist options
  • Save rukshanperera/9492610 to your computer and use it in GitHub Desktop.
Save rukshanperera/9492610 to your computer and use it in GitHub Desktop.
Term query to get children using parent id
#Remove old index
curl -XDELETE "http://localhost:9200/myindex"
#Create index
curl -XPUT "http://localhost:9200/myindex"
curl -XPOST "http://localhost:9200/myindex/Parent/_mapping" -d '
{ "Parent" :
{ "properties" : {
"name" : {
"type" :"string",
"index":"analyzed"
}
}
}
}'
curl -XPOST "http://localhost:9200/myindex/Child/_mapping" -d '
{
"Child" :{
"_parent": {
"type": "Parent"
},
"properties" : {
"name" : {
"type" :"string",
"index":"analyzed"
}
}
}
}'
curl -XPOST "http://localhost:9200/myindex/GrandChild/_mapping" -d '
{
"GrandChild" :{
"_parent": {
"type": "Child"
},
"properties" : {
"name" : {
"type" :"string",
"index":"analyzed"
}
}
}
}'
curl -s -XPOST "http://localhost:9200/_bulk?pretty=true" --data-binary '
{ "index" : { "_index" : "myindex", "_type" : "Parent", "_id" : "alice" } }
{ "name" : "Alice" }
{ "index" : { "_index" : "myindex", "_type" : "Child", "_id" : "bob", "parent" : "alice" } }
{ "name" : "Bob"}
{ "index" : { "_index" : "myindex", "_type" : "GrandChild", "_id" : "gc1", "parent" : "bob", "routing" : "alice" } }
{ "name" : "grand child 1" }
{ "index" : { "_index" : "myindex", "_type" : "GrandChild", "_id" : "gc2", "parent" : "bob", "routing" : "alice" } }
{ "name" : "grand child 2"}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment