Skip to content

Instantly share code, notes, and snippets.

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 jaymecd/a06cd64e6988161b6261 to your computer and use it in GitHub Desktop.
Save jaymecd/a06cd64e6988161b6261 to your computer and use it in GitHub Desktop.
curl -XDELETE localhost:9200/test/
curl -XPUT localhost:9200/test/
curl -XPUT localhost:9200/test/son/_mapping -d '{
"son": {
"_parent": {
"type": "mother"
}
}
}'
curl -XPUT localhost:9200/test/daughter/_mapping -d '{
"daughter": {
"_parent": {
"type": "mother"
}
}
}'
curl -XPUT localhost:9200/test/grandson/_mapping -d '{
"daughter": {
"_parent": {
"type": "daughter"
}
}
}'
curl -XPUT localhost:9200/test/mother/1 -d '{"name": "mommy"}'
curl -XPUT localhost:9200/test/son/1?parent=1 -d '{"name": "le son"}'
curl -XPUT localhost:9200/test/daughter/1?parent=1 -d '{"name": "le daughter"}'
curl -XPUT localhost:9200/test/grandson/1?parent=1 -d '{"name": "le baby"}'
curl -XPOST localhost:9200/test/_refresh
#############
#search for sons by filtering on mother, daughter and grandson
#############
curl -XPOST localhost:9200/test/son/_search?pretty -d '{
"filter": {
"has_parent": {
"parent_type": "mother",
"filter": {
"and": [
{
"term": {
"name":"mommy"
}
},
{
"has_child": {
"type": "daughter",
"filter": {
"and": [
{
"term": {
"name": "daughter"
}
},
{
"has_child": {
"type": "grandson",
"filter": {
"term" : {
"name": "baby"
}
}
}
}
]
}
}
}
]
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment