public
Last active

Elasticsearch 0.18.6 : My example of "parent child"

  • Download Gist
"parent child" data
1 2 3 4 5 6 7 8
curl -s -XPOST localhost:9200/_bulk?pretty=true --data-binary '
{ "index" : { "_index" : "parent_child", "_type" : "store", "_id" : "store1" } }
{ "name" : "auchan", "owner" : "chris" }
{ "index" : { "_index" : "parent_child", "_type" : "department", "_id" : "department1", "parent" : "store1" } }
{ "name" : "toys", "numberOfProducts" : 150 }
{ "index" : { "_index" : "parent_child", "_type" : "product", "_id" : "product1", "parent" : "department1", "routing" : "store1" } }
{ "name" : "gun", "trademark" : "tiger", "price" : 9, "store_id" : "store1" }
'
"parent child" mapping
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
curl -XPOST 'http://localhost:9200/parent_child' -d '{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1
},
"mappings": {
"store": {
"properties": {
"name": {
"type": "string"
},
"owner": {
"type": "string"
}
}
},
"department": {
"_parent": {
"type": "store"
},
"properties": {
"name": {
"type": "string"
},
"numberOfProducts": {
"type": "long"
}
}
},
"product": {
"_parent": {
"type": "department"
},
"_routing": {
"required": true,
"path": "store_id"
},
"properties": {
"name": {
"type": "string"
},
"trademark": {
"type": "string"
},
"price": {
"type": "long"
},
"store_id": {
"type": "string"
}
}
}
}
}'
"parent child" query
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
curl -XPOST 'http://localhost:9200/parent_child/_search?pretty=true' -d '{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"term": {
"name": "auchan"
}
}
]
}
},
"filter": {
"has_child": {
"type": "department",
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"term": {
"name": "toys"
}
}
]
}
},
"filter": {
"has_child": {
"type": "product",
"query": {
"term": {
"trademark": "tiger"
}
}
}
}
}
}
}
}
}
}
}'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.