# I need a query to get one document from 3 documents

**URL:** <https://discuss.elastic.co/t/i-need-a-query-to-get-one-document-from-3-documents/17625>\
**Category:** Elasticsearch\
**Created:** [May 20, 2014, 2:34pm UTC](https://discuss.elastic.co/t/i-need-a-query-to-get-one-document-from-3-documents/17625 "2014-05-20T14:34:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravikumar\_kotta](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@ravikumar\_kotta](https://discuss.elastic.co/u/ravikumar_kotta)\
**Post date:** [May 20, 2014, 2:34pm UTC](https://discuss.elastic.co/t/i-need-a-query-to-get-one-document-from-3-documents/17625/1 "2014-05-20T14:34:45Z")

</div>

Hi,

{"query":{"bool":{"must":[{"term":{"cmd":"addmember"}},{"term":{"user":"admin1"}},{"range":{"time":{"gte":1399985905,"lte":1400590215}}}],"must\_not":[],"should":[]}},"from":0,"size":50,"sort":[],"facets"  
: {"chatId" : {"terms" : {"field" : "chatId", "size" : 10}}}}}

I am writing query to get documents of distinct _chatId._ But that is not  
working. its giving all 3 documents. Can any body help me about same.

[{"lastName":"Admin1","index":"graph","resource":"admin1","from":"admin1","es\_metadata\_id":"8L4y5bFPScObTmUs9bTD5g","type":"normal","cmd":"addMember","time":1.400590215E9,"ticket":"19145","role":"operator","queueName":"","firstName":"Training","user":"admin1",  
_"chatId":"cv6D2QOh"_  
},{"lastName":"Admin1","index":"graph","resource":"admin1","from":"admin1","es\_metadata\_id":"ukExn7gNQ6ykMVXuPoDZRA","type":"normal","cmd":"addMember","time":1.400590215E9,"ticket":"19145","role":"operator","queueName":"","firstName":"Training","user":"admin1",  
_"chatId":"cv6D2QOh"_  
},{"lastName":"Admin1","index":"graph","resource":"admin1","from":"admin1","es\_metadata\_id":"PtC3r7EYR1GstrsfWqQxzg","type":"normal","cmd":"addMember","time":1.400590215E9,"ticket":"19145","role":"operator","queueName":"","firstName":"Training","user":"admin1",  
_"chatId":"cv6D2QOh"_}]

--  
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/56dea746-6c64-4d52-873f-ea4fd12f0f25%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/56dea746-6c64-4d52-873f-ea4fd12f0f25%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Telax](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@Telax](https://discuss.elastic.co/u/Telax)\
**Post date:** [May 21, 2014, 6:26am UTC](https://discuss.elastic.co/t/i-need-a-query-to-get-one-document-from-3-documents/17625/2 "2014-05-21T06:26:16Z")

</div>

I think in this case a terms facet would help you.

--  
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/497d9a93-c680-49da-87e4-63c4bc3a710f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/497d9a93-c680-49da-87e4-63c4bc3a710f%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:27am UTC](https://discuss.elastic.co/t/i-need-a-query-to-get-one-document-from-3-documents/17625/3 "2017-07-06T01:27:58Z")

</div>

Closed on July 6, 2017, 1:27am UTC


