Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@my3sons
Created March 21, 2012 19:59
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 my3sons/2152146 to your computer and use it in GitHub Desktop.
Save my3sons/2152146 to your computer and use it in GitHub Desktop.
query root and nested documents
curl -X DELETE "http://localhost:9200/deals_near_me"
curl -XPOST localhost:9200/deals_near_me -d '
{"index":
{ "number_of_shards": 2,
"number_of_replicas" : 1
}
}
}'
curl -XPUT localhost:9200/deals_near_me/deals/_mapping -d '{
"type1" : {
"properties" : {
"stores" : {
"type" : "nested",
"include_in_root" : "true"
}
}
}
}'
curl -X POST "http://localhost:9200/deals_near_me/deals" -d '{
"skuid": "123456",
"name": "Samsung 55 inch TV",
"desc": "Samsung Smart HDTV that really looks nice and is super thin",
"price2" : 300,
"stores":
[
{ "id": "1001", "price": 599, "inv_status" : "avail" },
{ "id": "1002", "price": 699, "inv_status" : "avail" },
{ "id": "1003", "price": 799, "inv_status" : "avail" }
]
}'
curl -X POST "http://localhost:9200/deals_near_me/deals" -d '{
"skuid": "123457",
"name": "Toshiba 60 inch TV",
"desc": "Toshiba HDTV that really rocks",
"price2" : 400,
"stores":
[
{ "id": "1001", "price": 395, "inv_status" : "avail" },
{ "id": "1004", "price": 399, "inv_status" : "avail" }
]
}'
curl 'localhost:9200/deals_near_me/deals/_search?pretty=1' -d '{
"query": {
"nested": {
"_scope": "my_scope",
"path": "stores",
"score_mode": "avg",
"query": {
"filtered" : {
"query" : {
"match_all": {}
},
"filter" : {
"term" : { "stores.id" : "1001" }
}
}
}
}
},
"facets" : {
"range1" : {
"range" : {
"stores.price" : [
{ "to" : 200.0 },
{ "from" : 200.0, "to" : 500.0 },
{ "from" : 500.1, "to" : 700.0 },
{ "from" : 700, "to" : 900.0 },
{ "from" : 900, "to" : 1000.0 },
{ "from" : 1000.0 }
]
},
"scope": "my_scope"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment