Created
April 15, 2013 09:13
-
-
Save damienalexandre/5386906 to your computer and use it in GitHub Desktop.
Facets example with ElasticSearch. Building a Filtered Query manualy (or via Elastica) is hell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for real, I have a mapping and my color is not "indexed" | |
curl -XPUT 'http://localhost:9200/pony_index_tmp' -d ' | |
{ | |
settings: { | |
number_of_shards: 1, | |
number_of_replicas: 0 | |
} | |
}' | |
curl -XPOST "http://localhost:9200/pony_index_tmp/pony/1" -d ' | |
{ | |
"name":"Dark pony", | |
"color":"black" | |
} | |
' | |
curl -XPOST "http://localhost:9200/pony_index_tmp/pony/2" -d ' | |
{ | |
"name":"Pink pony !", | |
"color":"pink" | |
} | |
' | |
curl -XPOST "http://localhost:9200/pony_index_tmp/pony/3" -d ' | |
{ | |
"name":"Another pony", | |
"color":"brown" | |
} | |
' | |
curl -XGET 'http://localhost:9200/pony_index_tmp/_search?pretty=true' -d ' | |
{"query": { | |
"match_all" : {} | |
}, | |
"facets" : { | |
"color" : { "terms" : {"field" : "color"} } | |
}}' | |
curl -XGET 'http://localhost:9200/pony_index_tmp/_search?pretty=true' -d ' | |
{"query": { | |
"filtered" : { | |
"query" : { "match_all" : {} }, | |
"filter" : { | |
"term" : { "color" : "black" } | |
} | |
} | |
}, | |
"facets" : { | |
"color" : { "terms" : {"field" : "color"} } | |
}}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment