Elasticsearch- get all values for a given field?
How to get all possible values for field
author
?
curl -XGET http://localhost:9200/articles/_search?pretty -d '
{
"aggs" : {
"whatever_you_like_here" : {
"terms" : { "field" : "author", "size":10000 }
}
},
"size" : 0
}'
Note
"size":10000
Get at most 10000 unique values. Default is 10."size":0
By default,"hits"
contains 10 documents. We don't need them.By default, the buckets are ordered by the
doc_count
in decreasing order.
Reference: bucket terms aggregation
Also note, according to this page, facets have been replaced by aggregations in Elasticsearch 1.0, which are a superset of facets.
I think what you want is a faceted search. Have a look at this example from the documentation:
http://www.elasticsearch.org/guide/reference/api/search/facets/index.html
curl -X POST "http://localhost:9200/articles/_search?pretty=true" -d '
{
"query" : { "query_string" : {"query" : "*"} },
"facets" : {
"tags" : { "terms" : {"field" : "author"} }
}
}
'
See if you can tailor this to work for you.