Last active
August 29, 2015 13:57
-
-
Save rukshanperera/9492610 to your computer and use it in GitHub Desktop.
Term query to get children using parent id
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
#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" | |
} | |
} | |
} | |
}' |
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 -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"} | |
' |
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
#this query works | |
curl -s -XPOST "http://localhost:9200/myindex/Child/_search?routing=alice" -d ' | |
{ | |
"query" : { | |
"term" : { "_parent" : "alice" } | |
} | |
}' | |
#but not this one. What am I doing wrong? | |
curl -s -XPOST "http://localhost:9200/myindex/GrandChild/_search?routing=alice" -d ' | |
{ | |
"query" : { | |
"term" : { "_parent" : "bob" } | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment