Distinct Values from Elasticsearch

(ashit pupu) #1

Hi Everyone,
I am indexing documents to index which is having the following structure. Providing an example below :-

{"content" : "xyz", "id" : "1234" , "iterationid" : "678001"}
{"content" : "xyz", "id" : "1234" , "iterationid" : "678003"}

when I do a term query on content field like
"query": {
"term": {
"content": "xyz"

The result I get is above two Json, but I want to restrict the result to one result just like giving a distinct on id in this example.

(David Pilato) #2

Have a look at terms aggregation


(ashit pupu) #3

@dadoonet term aggregation gives me distinct result , that I have already used. I am trying to achieve distinct in the search only, rather than depending on the aggregation. If any other ideas its welcome !!!

(David Pilato) #4

SSo I think you are looking for:

Look at top hits.


(ashit pupu) #5

@dadoonet yes its similar to this . Is this functionality currently available. Can I use this feature now??

(David Pilato) #6

Yes. https://www.elastic.co/guide/en/elasticsearch/reference/5.1/search-aggregations-metrics-top-hits-aggregation.html

(system) #7

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.