# Query nested array having n matching elements

**URL:** <https://discuss.elastic.co/t/query-nested-array-having-n-matching-elements/324744>\
**Category:** Elasticsearch\
**Created:** [February 5, 2023, 4:00pm UTC](https://discuss.elastic.co/t/query-nested-array-having-n-matching-elements/324744 "2023-02-05T16:00:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frankk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frankk/32/116789_2.png) [@Frankk](https://discuss.elastic.co/u/Frankk)\
**Post date:** [February 5, 2023, 4:00pm UTC](https://discuss.elastic.co/t/query-nested-array-having-n-matching-elements/324744/1 "2023-02-05T16:00:24Z")

</div>

Is this possible?  
I am indexing web site user activity focusing on user comments across multiple web sites and databases.  
I am "fairly" new to ES and am addressing quite a large problem.  
So basic question...  
Along with user name data and email in each document, comments on various topics are in a nested array as objects with basic fields like comment\_topic and comment\_text (text fields).  
eg.  
{  
"name": "user name",  
"id": "123",  
"[email":"abc@eample.com](mailto:email%22:%22abc@eample.com),"  
"comments": [  
{  
"comment\_topic": "topic 1",  
"comment\_text": "whatever"  
},  
{  
"comment\_topic": "topic 2",  
"comment\_text": "whatever"  
},  
{  
"comment\_topic": "topic 1",  
"comment\_text": "further more ...."  
},  
]  
}

Is it possible to query documents where, say , 10 or more comments array elements in a document match a given topic? Looking for users really active on a topic.

This brings up a basic question of matching on a term frequency minimum value. I am not familiar with how to to this. I have seen some related but dated solutions, not sure if they are still viable or best practice...  
ie.

```auto
{
  "query": {
    "filtered": {
      "filter": {
        "script": {
          "script": "_index['name'][term_to_lookup].tf() > occurrences",
          "params": {
            "term_to_lookup": "copyright",
            "occurrences": 1
          }
        }
      }
    }
  }
}

```

Any thoughts would be greatly appreciated.  
Cheers,  
Frank

---

<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:** [March 5, 2023, 4:01pm UTC](https://discuss.elastic.co/t/query-nested-array-having-n-matching-elements/324744/2 "2023-03-05T16:01:23Z")

</div>

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