# Can I filter an array in elastic?

**URL:** <https://discuss.elastic.co/t/can-i-filter-an-array-in-elastic/262198>\
**Category:** Elasticsearch\
**Created:** [January 26, 2021, 7:27am UTC](https://discuss.elastic.co/t/can-i-filter-an-array-in-elastic/262198 "2021-01-26T07:27:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShreyaBhat](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@ShreyaBhat](https://discuss.elastic.co/u/ShreyaBhat)\
**Post date:** [January 26, 2021, 7:27am UTC](https://discuss.elastic.co/t/can-i-filter-an-array-in-elastic/262198/1 "2021-01-26T07:27:51Z")

</div>

is there a way to filter an array in elastic ?  
I have inserted the following data into elastic

```auto
"_source":{
"FileName": "fileName.log"
"logData": [
                        {
                            "LineNumber": 1,
                            "Data": "data1"
                        },
                        {
                            "LineNumber": 2,
                            "Data": "Data2"
                        },
                        {
                            "LineNumber": 3,
                            "Data": "Data3"
                        },
                        {
                            "LineNumber": 4,
                            "Data": "Data4"
                        },
                        {
                            "LineNumber": 5,
                            "Data": "Data5"
                        },
                        {
                            "LineNumber": 6,
                            "Data": "Data6"
                        }
]}

```

is there a way to query such that I get the following response ?

```auto
"_source":{
"FileName": "fileName.log"
"logData": [
                        {
                            "LineNumber": 1,
                            "Data": "data1"
                        },
                        {
                            "LineNumber": 2,
                            "Data": "Data2"
                        },
                        {
                            "LineNumber": 3,
                            "Data": "Data3"
                        }
]
}

```

---

<div class="post-metadata">

**Author:** ![kavierkoo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kavierkoo/32/86555_2.png) [@kavierkoo](https://discuss.elastic.co/u/kavierkoo)\
**Post date:** [January 26, 2021, 8:00am UTC](https://discuss.elastic.co/t/can-i-filter-an-array-in-elastic/262198/2 "2021-01-26T08:00:45Z")

</div>

Using bool's Should or Must allow you to use match multiple time

> **[Boolean query | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)**

An example here by @ [reswob](https://discuss.elastic.co/u/reswob)

> [@Search multiple values against multiple fields](https://discuss.elastic.co/t/search-multiple-values-against-multiple-fields/137980/2):
>
> Hmm, after some more reading and googling, it looks like the following will work: GET index/\_search { "query" : { "bool" : { "should" : [{"terms" : { "user" : ["john", "jack", "bill"]}}, {"terms" : { "fullname" : ["john", "jack", "bill"]}}, {"terms" : { "firstname" : ["john", "jack", "bill"]}} ] } } }

Hope this help to answer your questions.

---

<div class="post-metadata">

**Author:** ![ShreyaBhat](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@ShreyaBhat](https://discuss.elastic.co/u/ShreyaBhat)\
**Post date:** [January 26, 2021, 8:33am UTC](https://discuss.elastic.co/t/can-i-filter-an-array-in-elastic/262198/3 "2021-01-26T08:33:41Z")

</div>

yes but it returns me the whole object.  
The Logdata object is a list of objects, Can I not fetch just few elements from the list?  
all my \_search queries work fine, just that it returns the whole object with a 100 lines for LogData instead of just the ones that matched the criteria,

---

<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:** [February 23, 2021, 8:33am UTC](https://discuss.elastic.co/t/can-i-filter-an-array-in-elastic/262198/4 "2021-02-23T08:33:54Z")

</div>

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