# Counting the frequency of matching fields

**URL:** <https://discuss.elastic.co/t/counting-the-frequency-of-matching-fields/60170>\
**Category:** Elasticsearch\
**Created:** [September 9, 2016, 2:16pm UTC](https://discuss.elastic.co/t/counting-the-frequency-of-matching-fields/60170 "2016-09-09T14:16:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaabo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaabo/32/12218_2.png) [@Kaabo](https://discuss.elastic.co/u/Kaabo)\
**Post date:** [September 9, 2016, 2:16pm UTC](https://discuss.elastic.co/t/counting-the-frequency-of-matching-fields/60170/1 "2016-09-09T14:16:41Z")

</div>

Hi,

I am quite much a beginner with Elastic (and this forum).

I have an index, where conversations are stored into documents per user in the following way:

Document #1:

\_id: 1  
nickname: John\_the\_man  
topic\_1.comment\_1: "This is great..."  
topic\_1.comment\_2: "This is even better..."  
topic\_2.comment\_1: "This new topic..."  
...

Document #2:

\_id: 2  
nickname: Mary\_the\_boss  
topic\_1.comment\_1: "Might be, yes..."  
topic\_2.comment\_1: "On the other hand..."  
topic\_2.comment\_2: "Actually..."  
topic\_3.comment\_1: "Well..."  
...

Document #3  
...

Now I would like to understand the activity levels of the conversations. The challenge I see here is that there are multiple fields in a single document that need to be counted even in "wildcard" fashion.

Is there a way to count the number of comments by topic (or even the total number) over the whole index?

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 12, 2016, 9:10am UTC](https://discuss.elastic.co/t/counting-the-frequency-of-matching-fields/60170/2 "2016-09-12T09:10:06Z")

</div>

I think it is tricky to count the number of comments per topic given that each document can contain multiple comments for the same topic. I would try and restructure the documents so that it is easier to get out the info you need when querying. Maybe have a document per topic or even one per comment, depending on what other queries you need to run.

---

<div class="post-metadata">

**Author:** ![Kaabo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaabo/32/12218_2.png) [@Kaabo](https://discuss.elastic.co/u/Kaabo)\
**Post date:** [September 14, 2016, 7:43am UTC](https://discuss.elastic.co/t/counting-the-frequency-of-matching-fields/60170/3 "2016-09-14T07:43:54Z")

</div>

Thanks javanna. I agree the best way is to restructure my index or actually make a second index to to place the discussion comments as separate documents.

---

<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 5, 2017, 10:20pm UTC](https://discuss.elastic.co/t/counting-the-frequency-of-matching-fields/60170/4 "2017-07-05T22:20:23Z")

</div>


