Forked from radu-gheorghe/multiple_child_levels.bash
Created
October 30, 2014 15:54
-
-
Save jaymecd/a06cd64e6988161b6261 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -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