Skip to content

Instantly share code, notes, and snippets.

@usman-ahmad
Created April 17, 2012 04:18
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 usman-ahmad/2403416 to your computer and use it in GitHub Desktop.
Save usman-ahmad/2403416 to your computer and use it in GitHub Desktop.
Facets are only showing local counts, I want to have counts like "linkedin.com" that are local but not include current term (i.e. color here).
# CREATE INDEX
curl -XPUT 'http://localhost:9200/computers/'
# CREATE MAPPING
curl -XPUT 'http://localhost:9200/computers/laptop/_mapping' -d '{
"laptop":{
"properties":{
"id":{
"type":"integer"
},
"processor":{
"type":"string"
},
"color":{
"type":"string"
},
"size_inches":{
"type":"integer"
}
}
}
}'
# INDEX DATA
curl -XPUT 'http://localhost:9200/computers/laptop/1' -d '
{ "id" : 1, "processor" : "core i5", "screen_inches" : 14, "color" : "silver" }'
curl -XPUT 'http://localhost:9200/computers/laptop/2' -d '
{ "id" : 2, "processor" : "core i7", "screen_inches" : 13, "color" : "black" }'
curl -XPUT 'http://localhost:9200/computers/laptop/3' -d '
{ "id" : 3, "processor" : "core i3", "screen_inches" : 15, "color" : "grey" }'
curl -XPUT 'http://localhost:9200/computers/laptop/4' -d '
{ "id" : 4, "processor" : "core i5", "screen_inches" : 14, "color" : "black" }'
curl -XPUT 'http://localhost:9200/computers/laptop/5' -d '
{ "id" : 5, "processor" : "core i5", "screen_inches" : 13, "color" : "white" }'
curl -XPUT 'http://localhost:9200/computers/laptop/6' -d '
{ "id" : 6, "processor" : "core i7", "screen_inches" : 13, "color" : "white" }'
curl -XPUT 'http://localhost:9200/computers/laptop/7' -d '
{ "id" : 7, "processor" : "core i7", "screen_inches" : 14, "color" : "black" }'
curl -XPUT 'http://localhost:9200/computers/laptop/8' -d '
{ "id" : 8, "processor" : "core i3", "screen_inches" : 15, "color" : "grey" }'
curl -XPUT 'http://localhost:9200/computers/laptop/9' -d '
{ "id" : 9, "processor" : "core i5", "screen_inches" : 14, "color" : "black" }'
# SEARCH DATA
curl -X GET "http://localhost:9200/computers_one/laptop_one/_search?pretty=true" -d '
{
"query":{ "bool":{ "must":[
{"query_string":{"query":"color: (black OR white) AND screen_inches: (13 OR 15)"}}
] } },
"facets":{
"processors":{ "terms":{ "field":"processor" } },
"colors":{ "terms":{ "field":"color" }, "global" : true },
"screen_inches":{ "terms":{ "field":"screen_inches" } }
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment