Skip to content

Instantly share code, notes, and snippets.

@jprante
Created July 4, 2012 15:35
Show Gist options
  • Save jprante/3047912 to your computer and use it in GitHub Desktop.
Save jprante/3047912 to your computer and use it in GitHub Desktop.
Elasticsearch parent/child
curl -XDELETE 'http://localhost:9200/test/'
curl -XPOST 'http://localhost:9200/_refresh'
curl -XPUT 'http://localhost:9200/test/' -d '{
"mappings" : {
"title" : {
},
"library" : {
"_parent" : {
"type" : "title"
}
}
}
}'
curl -XPUT 'http://localhost:9200/test/title/1' -d '{
"title" : "Book title"
}'
curl -XPUT 'http://localhost:9200/test/library/2?parent=1' -d '{
"name" : "Library One"
}'
curl -XPUT 'http://localhost:9200/test/library/3?parent=1' -d '{
"name" : "Library Two"
}'
curl -XPOST 'http://localhost:9200/test/_refresh'
echo
curl -XGET 'http://localhost:9200/test/_search?pretty' -d '{
"query": {
"text" : {
"title": "title"
}
}
}'
echo
curl -XGET 'http://localhost:9200/test/_search?pretty' -d '{
"query": {
"text" : {
"name": "Library"
}
}
}'
echo
curl -XGET 'http://localhost:9200/test/_search?pretty' -d '{
"query": {
"top_children" : {
"type" : "library",
"query" : {
"text" : {
"name" : "Library One"
}
}
}
}
}'
echo
curl -XGET 'http://localhost:9200/test/library/_search?pretty' -d '{
"query": {
"term" : {
"_parent" : "1"
}
}
}'
echo
curl -XGET 'http://localhost:9200/test/library/_search?pretty' -d '{
"query": {
"wildcard" : {
"_parent" : "title#1"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment