# Search result only with unique value of the specific field

**URL:** <https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124>\
**Category:** Elasticsearch\
**Created:** [August 6, 2014, 6:21pm UTC](https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124 "2014-08-06T18:21:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)\
**Post date:** [August 6, 2014, 6:21pm UTC](https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124/1 "2014-08-06T18:21:16Z")

</div>

Hi,  
Need some advise.  
I have indexed documents, each document has internal id that also indexed  
as just another indexed field, this id is not used as indexed document id  
(\_id).  
There could be situation when same document is indexed more than once (each  
of the indexed instances will have different elasticsearch \_id), when  
I search I'm getting result all those documents (including multiple  
instance of the same source document), is there any way to get kind of  
distinct results, I mean  
to get search result only unique documents, based on some field form the  
indexed document ?

Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 6, 2014, 7:06pm UTC](https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124/2 "2014-08-06T19:06:34Z")

</div>

Perhaps the top hits aggregation can help:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--  
Ivan

On Wed, Aug 6, 2014 at 11:21 AM, slavag [slavago@gmail.com](mailto:slavago@gmail.com) wrote:

> Hi,  
> Need some advise.  
> I have indexed documents, each document has internal id that also indexed  
> as just another indexed field, this id is not used as indexed document id  
> (\_id).  
> There could be situation when same document is indexed more than once  
> (each of the indexed instances will have different elasticsearch \_id), when  
> I search I'm getting result all those documents (including multiple  
> instance of the same source document), is there any way to get kind of  
> distinct results, I mean  
> to get search result only unique documents, based on some field form the  
> indexed document ?
> 
> Thanks
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDGEPns4eK0DPOp9pgOy0nO4RVS\_ZE%2Ba-rr-LOXk\_Nn8w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDGEPns4eK0DPOp9pgOy0nO4RVS_ZE%2Ba-rr-LOXk_Nn8w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)\
**Post date:** [August 6, 2014, 9:49pm UTC](https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124/3 "2014-08-06T21:49:19Z")

</div>

Hi, Thanks for the reply.  
I'm trying to define top hits aggregation but getting error : "Parse  
Failure [Could not find aggregator type [top\_hits] in [single\_result]]]; }]"  
This is my aggregation definition, first bucket is grouped by id and the  
nested bucket is grouped by date and then I want to get only one document  
from each nested bucket.

"aggs" : {  
"id" : {  
"terms" : {  
"field" : "id"  
},  
"aggs" : {  
"bckdate" : {  
"terms" : {  
"field" : "date"  
},  
"aggs" : {  
"single\_result" : {  
"top\_hits" : {  
"sort": [  
{  
"id": {  
"order":  
"desc"  
}  
}  
],  
"\_source": {  
"include": [  
"\*"  
]  
},  
"size" : 1  
}  
}  
}  
}  
}  
}  
}

What could be issue with my aggregation ? I'm using ES 1.2.1

Thanks

On Wednesday, August 6, 2014 10:06:40 PM UTC+3, Ivan Brusic wrote:

> Perhaps the top hits aggregation can help:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html)
> 
> --  
> Ivan
> 
> On Wed, Aug 6, 2014 at 11:21 AM, slavag \<[sla...@gmail.com](mailto:sla...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > Hi,  
> > Need some advise.  
> > I have indexed documents, each document has internal id that also indexed  
> > as just another indexed field, this id is not used as indexed document id  
> > (\_id).  
> > There could be situation when same document is indexed more than once  
> > (each of the indexed instances will have different elasticsearch \_id), when  
> > I search I'm getting result all those documents (including multiple  
> > instance of the same source document), is there any way to get kind of  
> > distinct results, I mean  
> > to get search result only unique documents, based on some field form the  
> > indexed document ?
> > 
> > Thanks
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 6, 2014, 9:59pm UTC](https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124/4 "2014-08-06T21:59:21Z")

</div>

This has been added in 1.3.0: [https://github.com/elasticsearch/elasticsearch/pull/6124](https://github.com/elasticsearch/elasticsearch/pull/6124)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 6 août 2014 à 23:49:25, slavag ([slavago@gmail.com](mailto:slavago@gmail.com)) a écrit:

Hi, Thanks for the reply.  
I'm trying to define top hits aggregation but getting error : "Parse Failure [Could not find aggregator type [top\_hits] in [single\_result]]]; }]"  
This is my aggregation definition, first bucket is grouped by id and the nested bucket is grouped by date and then I want to get only one document from each nested bucket.

"aggs" : {  
"id" : {  
"terms" : {  
"field" : "id"  
},  
"aggs" : {  
"bckdate" : {  
"terms" : {  
"field" : "date"  
},  
"aggs" : {  
"single\_result" : {  
"top\_hits" : {  
"sort": [  
{  
"id": {  
"order": "desc"  
}  
}  
],  
"\_source": {  
"include": [  
"\*"  
]  
},  
"size" : 1  
}  
}  
}  
}  
}  
}  
}

What could be issue with my aggregation ? I'm using ES 1.2.1

Thanks

On Wednesday, August 6, 2014 10:06:40 PM UTC+3, Ivan Brusic wrote:  
Perhaps the top hits aggregation can help: [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html)

--  
Ivan

On Wed, Aug 6, 2014 at 11:21 AM, slavag [sla...@gmail.com](mailto:sla...@gmail.com) wrote:  
Hi,  
Need some advise.  
I have indexed documents, each document has internal id that also indexed as just another indexed field, this id is not used as indexed document id (\_id).  
There could be situation when same document is indexed more than once (each of the indexed instances will have different elasticsearch \_id), when  
I search I'm getting result all those documents (including multiple instance of the same source document), is there any way to get kind of distinct results, I mean  
to get search result only unique documents, based on some field form the indexed document ?

## Thanks

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)\
**Post date:** [August 6, 2014, 10:06pm UTC](https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124/5 "2014-08-06T22:06:16Z")

</div>

Ooo, my bad, sorry.  
In the top\_hits explanation page  
: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html)  
There was top\_docs mentioned, but can't find any other reference to that  
aggregator, how can I use it ?

Thanks.

P.S. To include all fields in the \_source, \* is enough or should I use \_all  
?

Thanks.

On Thursday, August 7, 2014 12:59:39 AM UTC+3, David Pilato wrote:

> This has been added in 1.3.0:  
> [Add top\_hits aggregation by martijnvg · Pull Request #6124 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/pull/6124)
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 6 août 2014 à 23:49:25, slavag ([sla...@gmail.com](mailto:sla...@gmail.com) \<javascript:\>) a  
> écrit:
> 
> Hi, Thanks for the reply.  
> I'm trying to define top hits aggregation but getting error : "Parse  
> Failure [Could not find aggregator type [top\_hits] in [single\_result]]]; }]"  
> This is my aggregation definition, first bucket is grouped by id and the  
> nested bucket is grouped by date and then I want to get only one document  
> from each nested bucket.
> 
> "aggs" : {  
> "id" : {  
> "terms" : {  
> "field" : "id"  
> },  
> "aggs" : {  
> "bckdate" : {  
> "terms" : {  
> "field" : "date"  
> },  
> "aggs" : {  
> "single\_result" : {  
> "top\_hits" : {  
> "sort": [  
> {  
> "id": {  
> "order":  
> "desc"  
> }  
> }  
> ],  
> "\_source": {  
> "include": [  
> "\*"  
> ]  
> },  
> "size" : 1  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> What could be issue with my aggregation ? I'm using ES 1.2.1
> 
> Thanks
> 
> On Wednesday, August 6, 2014 10:06:40 PM UTC+3, Ivan Brusic wrote:
> 
> > Perhaps the top hits aggregation can help:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html)
> > 
> > --  
> > Ivan
> > 
> > On Wed, Aug 6, 2014 at 11:21 AM, slavag [sla...@gmail.com](mailto:sla...@gmail.com) wrote:
> > 
> > > Hi,  
> > > Need some advise.  
> > > I have indexed documents, each document has internal id that also  
> > > indexed as just another indexed field, this id is not used as indexed  
> > > document id (\_id).  
> > > There could be situation when same document is indexed more than once  
> > > (each of the indexed instances will have different elasticsearch \_id), when  
> > > I search I'm getting result all those documents (including multiple  
> > > instance of the same source document), is there any way to get kind of  
> > > distinct results, I mean  
> > > to get search result only unique documents, based on some field form the  
> > > indexed document ?
> > > 
> > > ## Thanks
> > > 
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/cde9a830-5a72-47a2-abd2-114603199578%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cde9a830-5a72-47a2-abd2-114603199578%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 6, 2014, 10:06pm UTC](https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124/6 "2014-08-06T22:06:53Z")

</div>

Sorry, I meant to specify the version, but I forgot. If you do upgrade,  
here is another explanation of top hits:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--  
Ivan

On Wed, Aug 6, 2014 at 2:59 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> This has been added in 1.3.0:  
> [Add top\_hits aggregation by martijnvg · Pull Request #6124 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/pull/6124)
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 6 août 2014 à 23:49:25, slavag ([slavago@gmail.com](mailto:slavago@gmail.com)) a écrit:
> 
> Hi, Thanks for the reply.  
> I'm trying to define top hits aggregation but getting error : "Parse  
> Failure [Could not find aggregator type [top\_hits] in [single\_result]]]; }]"  
> This is my aggregation definition, first bucket is grouped by id and the  
> nested bucket is grouped by date and then I want to get only one document  
> from each nested bucket.
> 
> "aggs" : {  
> "id" : {  
> "terms" : {  
> "field" : "id"  
> },  
> "aggs" : {  
> "bckdate" : {  
> "terms" : {  
> "field" : "date"  
> },  
> "aggs" : {  
> "single\_result" : {  
> "top\_hits" : {  
> "sort": [  
> {  
> "id": {  
> "order":  
> "desc"  
> }  
> }  
> ],  
> "\_source": {  
> "include": [  
> "\*"  
> ]  
> },  
> "size" : 1  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> What could be issue with my aggregation ? I'm using ES 1.2.1
> 
> Thanks
> 
> On Wednesday, August 6, 2014 10:06:40 PM UTC+3, Ivan Brusic wrote:
> 
> > Perhaps the top hits aggregation can help: [http://www](http://www).  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/en/elasticsearch/reference/)  
> > current/search-aggregations-metrics-top-hits-aggregation.html
> > 
> > --  
> > Ivan
> > 
> > On Wed, Aug 6, 2014 at 11:21 AM, slavag [sla...@gmail.com](mailto:sla...@gmail.com) wrote:
> > 
> > > Hi,  
> > > Need some advise.  
> > > I have indexed documents, each document has internal id that also  
> > > indexed as just another indexed field, this id is not used as indexed  
> > > document id (\_id).  
> > > There could be situation when same document is indexed more than once  
> > > (each of the indexed instances will have different elasticsearch \_id), when  
> > > I search I'm getting result all those documents (including multiple  
> > > instance of the same source document), is there any way to get kind of  
> > > distinct results, I mean  
> > > to get search result only unique documents, based on some field form the  
> > > indexed document ?
> > > 
> > > ## Thanks
> > > 
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%  
> > > [40googlegroups.com](http://40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local)  
> [https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA%3DX4WZM2nLJP%3DZxCm94gJz5EkRJs%3DBBSXhrAM1iEOYyw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA%3DX4WZM2nLJP%3DZxCm94gJz5EkRJs%3DBBSXhrAM1iEOYyw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)\
**Post date:** [August 6, 2014, 10:09pm UTC](https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124/7 "2014-08-06T22:09:37Z")

</div>

I'll definitely upgrade.  
Thanks

On Thursday, August 7, 2014 1:07:01 AM UTC+3, Ivan Brusic wrote:

> Sorry, I meant to specify the version, but I forgot. If you do upgrade,  
> here is another explanation of top hits:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/top-hits.html)
> 
> --  
> Ivan
> 
> On Wed, Aug 6, 2014 at 2:59 PM, David Pilato \<[da...@pilato.fr](mailto:da...@pilato.fr)  
> \<javascript:\>\> wrote:
> 
> > This has been added in 1.3.0:  
> > [Add top\_hits aggregation by martijnvg · Pull Request #6124 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/pull/6124)
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > 
> > Le 6 août 2014 à 23:49:25, slavag ([sla...@gmail.com](mailto:sla...@gmail.com) \<javascript:\>) a  
> > écrit:
> > 
> > Hi, Thanks for the reply.  
> > I'm trying to define top hits aggregation but getting error : "Parse  
> > Failure [Could not find aggregator type [top\_hits] in [single\_result]]]; }]"  
> > This is my aggregation definition, first bucket is grouped by id and the  
> > nested bucket is grouped by date and then I want to get only one document  
> > from each nested bucket.
> > 
> > "aggs" : {  
> > "id" : {  
> > "terms" : {  
> > "field" : "id"  
> > },  
> > "aggs" : {  
> > "bckdate" : {  
> > "terms" : {  
> > "field" : "date"  
> > },  
> > "aggs" : {  
> > "single\_result" : {  
> > "top\_hits" : {  
> > "sort": [  
> > {  
> > "id": {  
> > "order":  
> > "desc"  
> > }  
> > }  
> > ],  
> > "\_source": {  
> > "include": [  
> > "\*"  
> > ]  
> > },  
> > "size" : 1  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > What could be issue with my aggregation ? I'm using ES 1.2.1
> > 
> > Thanks
> > 
> > On Wednesday, August 6, 2014 10:06:40 PM UTC+3, Ivan Brusic wrote:
> > 
> > > Perhaps the top hits aggregation can help: [http://www](http://www).  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/en/elasticsearch/reference/)  
> > > current/search-aggregations-metrics-top-hits-aggregation.html
> > > 
> > > --  
> > > Ivan
> > > 
> > > On Wed, Aug 6, 2014 at 11:21 AM, slavag [sla...@gmail.com](mailto:sla...@gmail.com) wrote:
> > > 
> > > > Hi,  
> > > > Need some advise.  
> > > > I have indexed documents, each document has internal id that also  
> > > > indexed as just another indexed field, this id is not used as indexed  
> > > > document id (\_id).  
> > > > There could be situation when same document is indexed more than once  
> > > > (each of the indexed instances will have different elasticsearch \_id), when  
> > > > I search I'm getting result all those documents (including multiple  
> > > > instance of the same source document), is there any way to get kind of  
> > > > distinct results, I mean  
> > > > to get search result only unique documents, based on some field form  
> > > > the indexed document ?
> > > > 
> > > > ## Thanks
> > > > 
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local)  
> > [https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer)  
> > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d7d48fd4-7865-4422-9767-c48316485db2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d7d48fd4-7865-4422-9767-c48316485db2%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)\
**Post date:** [August 7, 2014, 9:53am UTC](https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124/8 "2014-08-07T09:53:10Z")

</div>

Upgraded to 1.3.1 and top hits is working, here the aggs definition:  
"aggs" : {  
"id" : {  
"terms" : {  
"field" : "id"  
},  
"aggs" : {  
"bckdate" : {  
"terms" : {  
"field" : "bckdate"  
},  
"aggs" : {  
"single\_result" : {  
"top\_hits" : {"size": 1}  
}  
}  
}  
}  
}  
}

BUT, if I want to include include fields in the result, when I add  
"\_source" with just a single field (that is present in the search hist  
result) - "subj" I get next error :

ElasticsearchIllegalArgumentException[No matching content type for null]  
Here the aggs definition with "\_source" :

"aggs" : {  
"id" : {  
"terms" : {  
"field" : "id"  
},  
"aggs" : {  
"bckdate" : {  
"terms" : {  
"field" : "bckdate"  
},  
"aggs" : {  
"single\_result" : {  
"top\_hits" : {"\_source": "subj", "size": 1}  
}  
}  
}  
}  
}  
}

What could be an issue here ? And how can I tell \_source to include all  
fields.

Thanks.

On Thursday, August 7, 2014 1:09:37 AM UTC+3, slavag wrote:

> I'll definitely upgrade.  
> Thanks
> 
> On Thursday, August 7, 2014 1:07:01 AM UTC+3, Ivan Brusic wrote:
> 
> > Sorry, I meant to specify the version, but I forgot. If you do upgrade,  
> > here is another explanation of top hits:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/top-hits.html)
> > 
> > --  
> > Ivan
> > 
> > On Wed, Aug 6, 2014 at 2:59 PM, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> > 
> > > This has been added in 1.3.0:  
> > > [Add top\_hits aggregation by martijnvg · Pull Request #6124 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/pull/6124)
> > > 
> > > --  
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > 
> > > Le 6 août 2014 à 23:49:25, slavag ([sla...@gmail.com](mailto:sla...@gmail.com)) a écrit:
> > > 
> > > Hi, Thanks for the reply.  
> > > I'm trying to define top hits aggregation but getting error : "Parse  
> > > Failure [Could not find aggregator type [top\_hits] in [single\_result]]]; }]"  
> > > This is my aggregation definition, first bucket is grouped by id and the  
> > > nested bucket is grouped by date and then I want to get only one document  
> > > from each nested bucket.
> > > 
> > > "aggs" : {  
> > > "id" : {  
> > > "terms" : {  
> > > "field" : "id"  
> > > },  
> > > "aggs" : {  
> > > "bckdate" : {  
> > > "terms" : {  
> > > "field" : "date"  
> > > },  
> > > "aggs" : {  
> > > "single\_result" : {  
> > > "top\_hits" : {  
> > > "sort": [  
> > > {  
> > > "id": {  
> > > "order":  
> > > "desc"  
> > > }  
> > > }  
> > > ],  
> > > "\_source": {  
> > > "include": [  
> > > "\*"  
> > > ]  
> > > },  
> > > "size" : 1  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > What could be issue with my aggregation ? I'm using ES 1.2.1
> > > 
> > > Thanks
> > > 
> > > On Wednesday, August 6, 2014 10:06:40 PM UTC+3, Ivan Brusic wrote:
> > > 
> > > > Perhaps the top hits aggregation can help: [http://www](http://www).  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/en/elasticsearch/reference/)  
> > > > current/search-aggregations-metrics-top-hits-aggregation.html
> > > > 
> > > > --  
> > > > Ivan
> > > > 
> > > > On Wed, Aug 6, 2014 at 11:21 AM, slavag [sla...@gmail.com](mailto:sla...@gmail.com) wrote:
> > > > 
> > > > > Hi,  
> > > > > Need some advise.  
> > > > > I have indexed documents, each document has internal id that also  
> > > > > indexed as just another indexed field, this id is not used as indexed  
> > > > > document id (\_id).  
> > > > > There could be situation when same document is indexed more than once  
> > > > > (each of the indexed instances will have different elasticsearch \_id), when  
> > > > > I search I'm getting result all those documents (including multiple  
> > > > > instance of the same source document), is there any way to get kind of  
> > > > > distinct results, I mean  
> > > > > to get search result only unique documents, based on some field form  
> > > > > the indexed document ?
> > > > > 
> > > > > ## Thanks
> > > > > 
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%  
> > > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/afc78f11-6050-4471-baec-7e1d2faddb0b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > .  
> > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/edd95f65-c380-410b-9f0f-465dd78e1bad%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local)  
> > > [https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.53e2a53a.2ae8944a.18f0%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer)  
> > > .
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0f59ac8b-248c-4156-b4f7-3aa74a8972d1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0f59ac8b-248c-4156-b4f7-3aa74a8972d1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:10am UTC](https://discuss.elastic.co/t/search-result-only-with-unique-value-of-the-specific-field/19124/9 "2017-07-06T01:10:13Z")

</div>


