Distinct Values from Elasticsearch

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.

Have a look at terms aggregation

HTH

@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 !!!

SSo I think you are looking for:

Look at top hits.

https://www.elastic.co/guide/en/elasticsearch/guide/master/top-hits.html

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

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

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