# Get distinct data

**URL:** <https://discuss.elastic.co/t/get-distinct-data/19566>\
**Category:** Elasticsearch\
**Created:** [September 2, 2014, 6:37am UTC](https://discuss.elastic.co/t/get-distinct-data/19566 "2014-09-02T06:37:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_T](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_t/32/1305_2.png) [@Alex\_T](https://discuss.elastic.co/u/Alex_T)\
**Post date:** [September 2, 2014, 6:37am UTC](https://discuss.elastic.co/t/get-distinct-data/19566/1 "2014-09-02T06:37:30Z")

</div>

Hi all!

I have problem with getting unique data from elasticsearch. I have the  
following documents:

[  
{  
"message": "Message 1",  
"author": {  
"id": 4,  
"name": "Author Name"  
},  
"sourceId": "123456789",  
"userId": "123456"  
},  
{  
"message": "Message 1",  
"author": {  
"id": 4,  
"name": "Author Name"  
},  
"sourceId": "123456789",  
"userId": "654321"  
}  
]

Different between this documents in userId. When I send query by  
"author.id", I get response with 2 documents.

Can I get distinct data by sourceId field?

--  
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/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [September 2, 2014, 6:45am UTC](https://discuss.elastic.co/t/get-distinct-data/19566/2 "2014-09-02T06:45:35Z")

</div>

Hello Alex ,

Term aggregation is here to save your day -

> **[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.

Thanks  
Vineeth

On Tue, Sep 2, 2014 at 12:07 PM, Alex T [atrigub@gmail.com](mailto:atrigub@gmail.com) wrote:

> Hi all!
> 
> I have problem with getting unique data from elasticsearch. I have the  
> following documents:
> 
> [  
> {  
> "message": "Message 1",  
> "author": {  
> "id": 4,  
> "name": "Author Name"  
> },  
> "sourceId": "123456789",  
> "userId": "123456"  
> },  
> {  
> "message": "Message 1",  
> "author": {  
> "id": 4,  
> "name": "Author Name"  
> },  
> "sourceId": "123456789",  
> "userId": "654321"  
> }  
> ]
> 
> Different between this documents in userId. When I send query by "  
> author.id", I get response with 2 documents.
> 
> Can I get distinct data by sourceId field?
> 
> --  
> 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/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%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/CAGdPd5n\_qZicXZp--7jX5vaip%3DJdadCrPQU0wzKmCYL494xmmA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5n_qZicXZp--7jX5vaip%3DJdadCrPQU0wzKmCYL494xmmA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Alex\_T](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_t/32/1305_2.png) [@Alex\_T](https://discuss.elastic.co/u/Alex_T)\
**Post date:** [September 2, 2014, 7:18am UTC](https://discuss.elastic.co/t/get-distinct-data/19566/3 "2014-09-02T07:18:47Z")

</div>

Hi Vineeth! Thanks for your answer.

I use term aggregation, but I get anyway response with 2 documents,  
response data for example:

{  
"took":23,  
"timed\_out":false,  
"\_shards":{"total":5,"successful":5,"failed":0},  
"hits":{  
"total":2,  
"max\_score":null,  
"hits":[  
{  
"\_index":"feeditem\_local",  
"\_type":"FeedItem",  
"\_id":"53dbe9cf1d7859e15f8b4599",  
"\_score":null,  
"\_source":{  
"sourceId":"123456789",  
"message":"Message 1",  
"author":{"id":"120816414"},  
"userId": "123456"  
},  
"sort":[1406921136000]  
},  
{  
"\_index":"feeditem\_local",  
"\_type":"FeedItem",  
"\_id":"53dbe9cf1d7859e15f8b4599",  
"\_score":null,  
"\_source":{  
"sourceId":"123456789",  
"message":"Message 1",  
"author":{"id":"120816414"},  
"userId": "654321"  
},  
"sort":[1406921136000]  
}  
]  
},  
"aggregations":{  
"source":{  
"buckets":[  
{"key":"123456789","doc\_count":2}  
]  
}  
}  
}

вторник, 2 сентября 2014 г., 9:45:41 UTC+3 пользователь vineeth mohan  
написал:

> Hello Alex ,
> 
> Term aggregation is here to save your day -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation)
> 
> Thanks  
> Vineeth
> 
> On Tue, Sep 2, 2014 at 12:07 PM, Alex T \<[atr...@gmail.com](mailto:atr...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > Hi all!
> > 
> > I have problem with getting unique data from elasticsearch. I have the  
> > following documents:
> > 
> > [  
> > {  
> > "message": "Message 1",  
> > "author": {  
> > "id": 4,  
> > "name": "Author Name"  
> > },  
> > "sourceId": "123456789",  
> > "userId": "123456"  
> > },  
> > {  
> > "message": "Message 1",  
> > "author": {  
> > "id": 4,  
> > "name": "Author Name"  
> > },  
> > "sourceId": "123456789",  
> > "userId": "654321"  
> > }  
> > ]
> > 
> > Different between this documents in userId. When I send query by "  
> > author.id", I get response with 2 documents.
> > 
> > Can I get distinct data by sourceId field?
> > 
> > --  
> > 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/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%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/8dccd0b8-972f-419c-bb94-3291d412844b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8dccd0b8-972f-419c-bb94-3291d412844b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [September 2, 2014, 8:55am UTC](https://discuss.elastic.co/t/get-distinct-data/19566/4 "2014-09-02T08:55:18Z")

</div>

Hello Alex ,

Aggregate based on sourceId field and you should get distinct sourceId  
values.

Thanks  
Vineeth

On Tue, Sep 2, 2014 at 12:48 PM, Alex T [atrigub@gmail.com](mailto:atrigub@gmail.com) wrote:

> Hi Vineeth! Thanks for your answer.
> 
> I use term aggregation, but I get anyway response with 2 documents,  
> response data for example:
> 
> {  
> "took":23,  
> "timed\_out":false,  
> "\_shards":{"total":5,"successful":5,"failed":0},  
> "hits":{  
> "total":2,  
> "max\_score":null,  
> "hits":[  
> {  
> "\_index":"feeditem\_local",  
> "\_type":"FeedItem",  
> "\_id":"53dbe9cf1d7859e15f8b4599",  
> "\_score":null,  
> "\_source":{  
> "sourceId":"123456789",  
> "message":"Message 1",  
> "author":{"id":"120816414"},  
> "userId": "123456"  
> },  
> "sort":[1406921136000]  
> },  
> {  
> "\_index":"feeditem\_local",  
> "\_type":"FeedItem",  
> "\_id":"53dbe9cf1d7859e15f8b4599",  
> "\_score":null,  
> "\_source":{  
> "sourceId":"123456789",  
> "message":"Message 1",  
> "author":{"id":"120816414"},  
> "userId": "654321"  
> },  
> "sort":[1406921136000]  
> }  
> ]  
> },  
> "aggregations":{  
> "source":{  
> "buckets":[  
> {"key":"123456789","doc\_count":2}  
> ]  
> }  
> }  
> }
> 
> вторник, 2 сентября 2014 г., 9:45:41 UTC+3 пользователь vineeth mohan  
> написал:
> 
> > Hello Alex ,
> > 
> > Term aggregation is here to save your day - [http://www.elasticsearch](http://www.elasticsearch).  
> > org/guide/en/elasticsearch/reference/current/search-  
> > aggregations-bucket-terms-aggregation.html#search-  
> > aggregations-bucket-terms-aggregation
> > 
> > Thanks  
> > Vineeth
> > 
> > On Tue, Sep 2, 2014 at 12:07 PM, Alex T [atr...@gmail.com](mailto:atr...@gmail.com) wrote:
> > 
> > > Hi all!
> > > 
> > > I have problem with getting unique data from elasticsearch. I have the  
> > > following documents:
> > > 
> > > [  
> > > {  
> > > "message": "Message 1",  
> > > "author": {  
> > > "id": 4,  
> > > "name": "Author Name"  
> > > },  
> > > "sourceId": "123456789",  
> > > "userId": "123456"  
> > > },  
> > > {  
> > > "message": "Message 1",  
> > > "author": {  
> > > "id": 4,  
> > > "name": "Author Name"  
> > > },  
> > > "sourceId": "123456789",  
> > > "userId": "654321"  
> > > }  
> > > ]
> > > 
> > > Different between this documents in userId. When I send query by "  
> > > author.id", I get response with 2 documents.
> > > 
> > > Can I get distinct data by sourceId field?
> > > 
> > > --  
> > > 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/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%  
> > > [40googlegroups.com](http://40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1b59b2a2-484b-46cc-a95b-695e84e6d6eb%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/8dccd0b8-972f-419c-bb94-3291d412844b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8dccd0b8-972f-419c-bb94-3291d412844b%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/8dccd0b8-972f-419c-bb94-3291d412844b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/8dccd0b8-972f-419c-bb94-3291d412844b%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/CAGdPd5kJ01uFysDPvYBh1ufdaER%3DniTO3hp26HRyS1kcFJU3%3Dg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kJ01uFysDPvYBh1ufdaER%3DniTO3hp26HRyS1kcFJU3%3Dg%40mail.gmail.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:05am UTC](https://discuss.elastic.co/t/get-distinct-data/19566/5 "2017-07-06T01:05:01Z")

</div>


