# Query most common conversation enders (Terms / Top Hits aggregation?)

**URL:** <https://discuss.elastic.co/t/query-most-common-conversation-enders-terms-top-hits-aggregation/97590>\
**Category:** Elasticsearch\
**Created:** [August 18, 2017, 1:24pm UTC](https://discuss.elastic.co/t/query-most-common-conversation-enders-terms-top-hits-aggregation/97590 "2017-08-18T13:24:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jminuscula](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jminuscula/32/21266_2.png) [@jminuscula](https://discuss.elastic.co/u/jminuscula)\
**Post date:** [August 18, 2017, 1:24pm UTC](https://discuss.elastic.co/t/query-most-common-conversation-enders-terms-top-hits-aggregation/97590/1 "2017-08-18T13:24:16Z")

</div>

Hi there!

I'm having a hard time coming up with a query [ES 2.3]. I have the following mapping (simplified):

```
{
  "user_id": 1234,
  "text": "bye bye",
  "created_on": "2017-08-18T00:00:00",
  "direction": "O"
}

```

I'm now trying to get the most common texts that end a conversation. That is, the number of times each texts appears on the documents with both `direction="O"` and max(created\_on) per `user_id`.

I thought I'd group all documents by contact with a terms aggregation, and then run a top hits subaggregation, but there are too many users and the query times out.

Is there something in ES that can help me achieve this? Is filtering and computing this offline my best option?

Thanks in advance!

---

<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:** [September 15, 2017, 1:24pm UTC](https://discuss.elastic.co/t/query-most-common-conversation-enders-terms-top-hits-aggregation/97590/2 "2017-09-15T13:24:46Z")

</div>

Closed on September 15, 2017, 1:24pm UTC

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