Created
April 22, 2013 16:03
-
-
Save michaeldcruz/5436325 to your computer and use it in GitHub Desktop.
Elasticsearch parent/child relationship example
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
| # Bulk Sample Data | |
| curl -s -XPOST localhost:9200/_bulk?pretty=true --data-binary ' | |
| { "index" : { "_index" : "products", "_type" : "style_variant", "_id" : "1" } } | |
| { "name" : "Style Variant 1" } | |
| { "index" : { "_index" : "products", "_type" : "style_variant", "_id" : "2" } } | |
| { "name" : "Style Variant 2" } | |
| { "index" : { "_index" : "products", "_type" : "style_variant", "_id" : "3" } } | |
| { "name" : "Style Variant 3" } | |
| { "index" : { "_index" : "products", "_type" : "product", "_id" : "1", "parent" : "1" } } | |
| { "name" : "Shirt 1", "vendor_name" : "Alternative Apparel", "size" : "S", "retail_price": 100, "tc_color" : "Black" } | |
| { "index" : { "_index" : "products", "_type" : "product", "_id" : "2", "parent" : "2" } } | |
| { "name" : "Shirt 2", "vendor_name" : "Alternative Apparel", "size" : "M", "retail_price": 120, "tc_color" : "Red" } | |
| { "index" : { "_index" : "products", "_type" : "product", "_id" : "3", "parent" : "2" } } | |
| { "name" : "Pants 1", "vendor_name" : "J Crew", "size" : "32", "retail_price": 280, "tc_color" : "Black" } | |
| { "index" : { "_index" : "products", "_type" : "product", "_id" : "4", "parent" : "3" } } | |
| { "name" : "Pants 2", "vendor_name" : "J Crew", "size" : "34", "retail_price": 220, "tc_color" : "Blue" } | |
| { "index" : { "_index" : "products", "_type" : "product", "_id" : "5", "parent" : "3" } } | |
| { "name" : "Shoes 1", "vendor_name" : "J Crew", "size" : "12", "retail_price": 250, "tc_color" : "Brown" } | |
| ' |
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 -XPOST 'http://localhost:9200/products/style_variant/_search?pretty=true' -d '{ | |
| "query": { | |
| "has_child": { | |
| "type" : "product", | |
| "query": { | |
| "filtered": { | |
| "query":= { "match_all": { }}, | |
| "filter": { | |
| "and": [ | |
| {"terms": {"size": ["12", "34"]}}, | |
| {"term": {"tc_color": "Blue"}} | |
| ] | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }' |
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 'http://localhost:9200/products/' | |
| curl -XPOST 'http://localhost:9200/products' -d '{ | |
| "mappings": { | |
| "style_variant": { | |
| "properties": { | |
| "name": { | |
| "type": "string" | |
| } | |
| } | |
| }, | |
| "product": { | |
| "_parent": { | |
| "type": "style_variant" | |
| }, | |
| "properties": { | |
| "name": { "type": "string" }, | |
| "vendor_name": { "type" : "string", "index" : "not_analyzed" }, | |
| "size": { "type" : "string" }, | |
| "retail_price": { "type" : "float" }, | |
| "tc_color": { "type" : "string", "index" : "not_analyzed" } | |
| } | |
| } | |
| } | |
| } | |
| }' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is line #7 is the has_child_query.json as typo or is there really an '=' after the colon?