Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch- get all values for a given field?

Is it possible to query for all of the values a specific field? Say I have "articles" and each article has an author, is there a query I can perform to find a list of all authors?

like image 776
eric Avatar asked Jan 17 '13 17:01

eric


People also ask

How do I extract data from Elasticsearch?

Here are three popular methods, you use to export files from Elasticsearch to any desired warehouse or platform of your choice: Elasticsearch Export: Using Logstash-Input-Elasticsearch Plugin. Elasticsearch Export: Using Elasticsearch Dump. Elasticsearch Export: Using Python Pandas.

What is _source field in Elasticsearch?

The _source field contains the original JSON document body that was passed at index time. The _source field itself is not indexed (and thus is not searchable), but it is stored so that it can be returned when executing fetch requests, like get or search.

How do I get Elasticsearch index data?

You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API's query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query. This query matches documents with a user.id value of kimchy .


1 Answers

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.

like image 157
kgf3JfUtW Avatar answered Oct 17 '22 19:10

kgf3JfUtW