Skip to content

Instantly share code, notes, and snippets.

@RobDoan
Forked from ToulBoy/"parent child" data
Created April 12, 2013 10:29
Show Gist options
  • Save RobDoan/5371108 to your computer and use it in GitHub Desktop.
Save RobDoan/5371108 to your computer and use it in GitHub Desktop.

Revisions

  1. @ToulBoy ToulBoy created this gist Feb 29, 2012.
    8 changes: 8 additions & 0 deletions "parent child" data
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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" }
    '
    54 changes: 54 additions & 0 deletions "parent child" mapping
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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"
    }
    }
    }
    }
    }'
    47 changes: 47 additions & 0 deletions "parent child" query
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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"
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }'