Skip to content

Instantly share code, notes, and snippets.

@michaeldcruz
Created April 22, 2013 16:03
Show Gist options
  • Save michaeldcruz/5436325 to your computer and use it in GitHub Desktop.
Save michaeldcruz/5436325 to your computer and use it in GitHub Desktop.

Revisions

  1. michaeldcruz created this gist Apr 22, 2013.
    19 changes: 19 additions & 0 deletions bulk_load.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # 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" }
    '
    18 changes: 18 additions & 0 deletions has_child_query.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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"}}
    ]
    }
    }
    }
    }
    }
    }'
    26 changes: 26 additions & 0 deletions setup_mappings.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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" }
    }
    }
    }
    }
    }'