# App search - Filters - Arrays

**URL:** <https://discuss.elastic.co/t/app-search-filters-arrays/316881>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [October 18, 2022, 12:02pm UTC](https://discuss.elastic.co/t/app-search-filters-arrays/316881 "2022-10-18T12:02:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerardo\_Zenobi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerardo_zenobi/32/106790_2.png) [@Gerardo\_Zenobi](https://discuss.elastic.co/u/Gerardo_Zenobi)\
**Post date:** [October 18, 2022, 12:02pm UTC](https://discuss.elastic.co/t/app-search-filters-arrays/316881/1 "2022-10-18T12:02:42Z")

</div>

Hi there 👋

I want to know what is the best filtering approach for my scenario. ([**Search API Filters**](https://www.elastic.co/guide/en/app-search/current/filters.html))

**Scenario:**

Intro: I have arrays of values on the client side, and on the engine document schema one. I want documents to be returned only if there is an intersection between client side array and indexed document array.

Indexed document example:

```auto
    {
        id: "1",
        name: "name 1",
        author: "u1",
        idx_groups_a1: ["ga1", "ga2", "ga3", ..., "gaX000th"],
        idx_groups_b2: ["gb1", "gb2", "gb3", ..., "gbX000th"]
    }

```

On the client side let's say I have:

- `a1_groups = ["ga50", "ga51"]`
- `a2_groups = ["gb1000", "gb1001"]`

I want to return then: documents that match if there is an :

- intersection between `a1_groups` and `idx_groups_a1`  
**OR**
- intersection between `a2_groups` and `idx_groups_b2`.

**I understand there are at least 2 possible ways of achieving** , but I wanted to know which one is the preferred one in terms of performance, and in terms of limitations since `a1_groups` and `a2_groups` **could have thousands of values**.

### Option A

This option is based of the requests that the **[App Search Generated Search UI](https://www.elastic.co/blog/kickstart-search-with-the-elastic-app-search-reference-ui)** performs:

```json
    "filters": {
        "any": [
            {
                "any": [
                    {
                        "idx_groups_a1": "ga50"
                    },
                    {
                        "idx_groups_a1": "ga51"
                    }
                ]
            },
            {
                "any": [
                    {
                        "idx_groups_b2": "gb1000"
                    },
                    {
                        "idx_groups_b2": "gb1001"
                    }
                ]
            }
        ]
    },

```

### Option B

```json
    "filters": {
        "any": [
            {
                "idx_groups_a1": [
                    "ga50",
                    "ga51"
                ]
            },
            {
                "idx_groups_b2": [
                    "gb1000",
                    "gb1001"
                ]
            }
        ]
    }

```

Thanks in advance !

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [October 18, 2022, 2:05pm UTC](https://discuss.elastic.co/t/app-search-filters-arrays/316881/2 "2022-10-18T14:05:07Z")

</div>

hello @Gerardo_Zenobi

Thank you for your detailed question!

Just so im clear about your example above, you want a filter that:

a document that has either:

- "ga50" or "ga51" in idx\_groups\_a1
- "gb1000" or "gb1001" in idx\_groups\_b2

If so your suggestions should be correct. Option B is the most optimal but depending on how many filter groups you require, you could hit the 32 max filter limit ([Search API filters | Elastic App Search Documentation [8.4] | Elastic](https://www.elastic.co/guide/en/app-search/current/filters.html#filters-arrays-vs-objects)). With arrays you can have upto 1024 values before hitting the limit. Unfortunately there is no way to increase this limit AFAIK.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Gerardo\_Zenobi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerardo_zenobi/32/106790_2.png) [@Gerardo\_Zenobi](https://discuss.elastic.co/u/Gerardo_Zenobi)\
**Post date:** [October 19, 2022, 6:45am UTC](https://discuss.elastic.co/t/app-search-filters-arrays/316881/3 "2022-10-19T06:45:38Z")

</div>

Hi @joemcelroy , thanks for the rapid response!

> a document that has either:
> 
> - "ga50" or "ga51" in idx\_groups\_a1
> - "gb1000" or "gb1001" in idx\_groups\_b2

Yes, your interpretation was correct: It is any match between 2 given arrays: as long as there is an `intersection.length > 0`, then the condition is true and the document **should not** be filtered out.

> With arrays you can have upto 1024 values before hitting the limit.

With this you mean that within my filters in the query to EAP:

```auto
"idx_groups_a1": ["v1", "v2","v3", ..., "v1024-MAX ! ! "]

```

A given value filter, stated in the array form like above, can't pass more than 1024 values ? Then if my use case needs to pass more than the limit, I would need to divide as follows ? :

(taking only **idx\_groups\_a1** as example for the more than 1024 values case)

```auto
        "any": [
            {
                "idx_groups_a1": ["v1", "v2","v3", ..., "v1024-MAX ! ! "]
            },
            {
                "idx_groups_a1": ["v1024", "v1024","v1024", ..., "v2048-MAX ! ! "]
            },
            {
                "idx_groups_b2": [...]
            },
            // ...
        ]

```

Is this legit ? (and possibly the only workaround provided we stay within the 32 max filters)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [October 19, 2022, 7:22am UTC](https://discuss.elastic.co/t/app-search-filters-arrays/316881/4 "2022-10-19T07:22:32Z")

</div>

Hey Gerardo!

> [@Gerardo\_Zenobi](#):
>
> With this you mean that within my filters in the query to EAP:
> 
> ```auto
> "idx_groups_a1": ["v1", "v2","v3", ..., "v1024-MAX ! ! "]
> 
> ```
> 
> A given value filter, stated in the array form like above, can't pass more than 1024 values ?

Yes, you understood perfectly!

> [@Gerardo\_Zenobi](#):
>
> A given value filter, stated in the array form like above, can't pass more than 1024 values ? Then if my use case needs to pass more than the limit, I would need to divide as follows ? :

Yes! That is a good solution to mitigate the 1024 filter limit per array.

Thanks  
Joe

---

<div class="post-metadata">

**Author:** ![Gerardo\_Zenobi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerardo_zenobi/32/106790_2.png) [@Gerardo\_Zenobi](https://discuss.elastic.co/u/Gerardo_Zenobi)\
**Post date:** [October 19, 2022, 7:26am UTC](https://discuss.elastic.co/t/app-search-filters-arrays/316881/5 "2022-10-19T07:26:08Z")

</div>

Thanks again @joemcelroy 👍

---

<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:** [November 16, 2022, 7:26am UTC](https://discuss.elastic.co/t/app-search-filters-arrays/316881/6 "2022-11-16T07:26:18Z")

</div>

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