Skip to content

Instantly share code, notes, and snippets.

@andreasch
Created September 25, 2012 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andreasch/3783212 to your computer and use it in GitHub Desktop.
Save andreasch/3783212 to your computer and use it in GitHub Desktop.
Querying a parent type that is also a child type for another type
#!/bin/bash
echo "Performing a has_child search on contacts"
curl -XGET 'http://localhost:9200/contact/_search?pretty=true' -d '
{
"query" : {
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"has_child" : {
"query" : {
"match_all" : { }
},
"type" : "orderType"
}
}
}
}
}'
#!/bin/bash
echo "Performing a has_child search on orders"
curl -XGET 'http://localhost:9200/contact/_search?pretty=true' -d '
{
"query" : {
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"has_child" : {
"query" : {
"match_all" : { }
},
"type" : "productType"
}
}
}
}
}'
#!/bin/bash
echo "Creating contacts"
curl -XPUT 'http://localhost:9200/contact/contactType/1?pretty=true' -d '
{
"contactId":"1",
"firstName":"First name 1",
"lastName":"Last name 1"
}
'
echo
curl -XPUT 'http://localhost:9200/contact/contactType/2?pretty=true' -d '
{
"contactId":"2",
"firstName":"First name 2",
"lastName":"Last name 2"
}'
echo
echo
echo "Creating orders"
curl -XPUT 'http://localhost:9200/contact/orderType/1?pretty=true&parent=1' -d '
{
"orderId":"1",
"total":"50"
}'
echo
curl -XPUT 'http://localhost:9200/contact/orderType/2?pretty=true&parent=1' -d '
{
"orderId":"2",
"total":"30"
}'
echo
curl -XPUT 'http://localhost:9200/contact/orderType/3?pretty=true&parent=2' -d '
{
"orderId":"3",
"total":"1080"
}'
echo
curl -XPUT 'http://localhost:9200/contact/orderType/4?pretty=true&parent=2' -d '
"orderId":"4",
"total":"500"
}'
echo
echo
echo "Creating products"
curl -XPUT 'http://localhost:9200/contact/productType/1?pretty=true&parent=1' -d '{
"productId":"1",
"productName":"Slingshot",
"productCategory":"Weapon"
}'
echo
curl -XPUT 'http://localhost:9200/contact/productType/2?pretty=true&parent=1' -d '
{
"productId":"2",
"productName":"Boomerang",
"productCategory":"Toy"
}'
echo
curl -XPUT 'http://localhost:9200/contact/productType/3?pretty=true&parent=2' -d '
{
"productId":"3",
"productName":"Boomerang",
"productCategory":"Toy"
}'
echo
curl -XPUT 'http://localhost:9200/contact/productType/4?pretty=true&parent=3' -d '
{
"productId":"4",
"productName":"Boomerang",
"productCategory":"Toy"
}'
echo
curl -XPUT 'http://localhost:9200/contact/productType/5?pretty=true&parent=3' -d '
{
"productId":"5",
"productName":"Boomerang",
"productCategory":"Weapon"
}'
echo
curl -XPUT 'http://localhost:9200/contact/productType/6?pretty=true&parent=3' -d '
{
"productId":"6",
"productName":"Sword",
"productCategory":"Weapon"
}'
echo
curl -XPUT 'http://localhost:9200/contact/productType/7?pretty=true&parent=3' -d '
{
"productId":"7",
"productName":"Sword",
"productCategory":"Weapon"
}'
echo
curl -XPUT 'http://localhost:9200/contact/productType/8?pretty=true&parent=4' -d '
{
"productId":"8",
"productName":"Sword",
"productCategory":"Weapon"
}'
echo
echo
echo "Refreshing indices"
curl -XPOST 'http://localhost:9200/contact/_refresh'
#!/bin/bash
clear
echo "Deleting contact index"
curl -XDELETE 'http://localhost:9200/contact?pretty=true'
echo
echo
echo "Creating parent mappings"
curl -XPUT 'http://localhost:9200/contact?pretty=true' -d '
{
"mappings": {
"orderType": {
"_parent": {
"type":"contactType"
}
},
"productType": {
"_parent": {
"type":"orderType"
}
}
}
}'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment