Skip to content

Instantly share code, notes, and snippets.

@hariinfo
Last active December 15, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hariinfo/5342031 to your computer and use it in GitHub Desktop.
Save hariinfo/5342031 to your computer and use it in GitHub Desktop.
#Delete the index if one exists
curl -XDELETE 'http://localhost:9200/mastercatalog' && echo
curl -XPOST 'http://localhost:9200/mastercatalog' -d '{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1
},
"mappings": {
"10101": {
"properties": {
"name": {
"type": "string"
},
"owner": {
"type": "string"
}
}
},
"product": {
"_parent": {
"type": "10101"
},
"properties": {
"name": {
"type": "string"
},
"numberOfProducts": {
"type": "long"
},
"partnumber" : {"type" : "string", "index" : "not_analyzed"}
}
},
"variation": {
"_parent": {
"type": "product"
},
"_routing": {
"required": true,
"path": "store_id"
},
"properties": {
"name": {
"type": "string"
},
"trademark": {
"type": "string"
},
"price": {
"type": "long"
},
"partnumber" : {"type" : "string", "index" : "not_analyzed"},
"store_id": {
"type": "string"
}
}
}
}
}' && echo
-- Load Data
curl -s -XPOST localhost:9200/_bulk?pretty=true --data-binary '
{ "index" : { "_index" : "mastercatalog", "_type" : "10101", "_id" : "10101" } }
{ "name" : "auchan", "owner" : "chris" }
{ "index" : { "_index" : "mastercatalog", "_type" : "product", "_id" : "department1", "parent" : "10101" } }
{ "name" : "toys", "numberOfProducts" : 150,"partnumber" : "EI-01G-1" }
{ "index" : { "_index" : "mastercatalog", "_type" : "variation", "_id" : "product1", "parent" : "department1", "routing" : "10101" } }
{ "name" : "gun", "trademark" : "tiger", "price" : 9, "partnumber" : "EI-01G-2", "store_id" : "10101" }' && echo
-- Query
curl -XPOST 'http://localhost:9200/mastercatalog/_search?pretty=true' -d '{
"query": {
"filtered": {
"query": {
"bool": {
"must": [{"term": {"name" :"auchan" }}]
}
},
"filter": {
"has_child": {
"type": "product",
"query": {
"filtered": {
"query": {
"bool": {
"must": [{"term": {"partnumber": "EI-01G-1"}}]
}
},
"filter": {
"has_child": {
"type": "variation",
"query": {
"term": {
"partnumber": "EI-01G-2"
}
}
}
}
}
}
}
}
}
}
}' && echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment