Created
June 3, 2012 22:38
-
-
Save r10r/2865256 to your computer and use it in GitHub Desktop.
Elasticsearch 0.20.0.Beta1-SNAPSHOT with has_parent merged : Search for childs with "has_parent" filter
This file contains 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
{ "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" } |
This file contains 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
{ | |
"query": { | |
"filtered": { | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"trademark": "tiger" | |
} | |
} | |
] | |
} | |
}, | |
"filter": { | |
"has_parent": { | |
"type": "department", | |
"query": { | |
"filtered": { | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"name": "toys" | |
} | |
} | |
] | |
} | |
}, | |
"filter": { | |
"has_parent": { | |
"type": "store", | |
"query": { | |
"term": { | |
"name": "auchan" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains 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
#!/bin/bash | |
# create the index with mappings and parent field definitions | |
curl -XPOST 'http://localhost:9200/parent_child' -d @mapping.json | |
# bulk insert data into the index | |
curl -s -XPOST localhost:9200/_bulk?pretty=true --data-binary @bulk_data.json | |
# execute the query with 'has_parent | |
curl -XPOST 'http://localhost:9200/parent_child/_search?pretty=true' -d @has_parent_query.json |
This file contains 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
{ | |
"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" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements
Usage