# Complex filters in app searchui

**URL:** https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922
**Category:** Elastic Search
**Created:** [August 11, 2022, 11:53am UTC](https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922 "2022-08-11T11:53:11Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Daniel\_Kozlowski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_kozlowski/32/87061_2.png) [@Daniel\_Kozlowski](https://discuss.elastic.co/u/Daniel_Kozlowski)
#### Post date: [August 11, 2022, 11:53am UTC](https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922/1 "2022-08-11T11:53:11Z")

</div>

I have a complex quiery that I have working find in the search API via post to elastic app search. Basically its a nested all and any query like so

I have a very complex nested query filter that i can get working in the api call like so (small example, its gets more complex)

```auto

{ "all": [
          {
              "pattern": "6x6"
          },
          {
              "core": {
                  "from": 78.1,
                  "to": 900
              }
          }
      ] ,
      "any": [
          {
              "all": [
                  {
                      "size": [
                          "20x10",
                          "10x4"
                      ]
                  },
                  {
                      "space": {
                          "from": 10,
                          "to": 35
                      }
                  }
              ]
          }
        ],
       .......etc
}

```

I want to set this filter in a page so that only these show in the APP search UI  
In the app search config you can set a filter like so, but I am not sure how to add the all/any for this to work

```auto
filters : [{field: 'pattern', values: ["6x6"]},
      {field:'core', values: [{name: "core", from: 78.1, to: 900}]},
     ?????
],

```

Any ideas how to get this full filter working?

---

<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: [August 11, 2022, 12:30pm UTC](https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922/2 "2022-08-11T12:30:39Z")

</div>

Have you tried copying your example query that you shared into the filters attribute within the app search config that you mentioned? If so, could you take a look at the network request within the browser? I think this could be a bug and its been highlighted on a somewhat seperate issue [Queries are hitting 32 filter limit prematurely. · Issue #837 · elastic/search-ui · GitHub](https://github.com/elastic/search-ui/issues/837)

Create a bug report within the search-ui repo with the XHR request thats performed and we can take a look!

Joe

---

<div class="post-metadata">

### Author: ![Daniel\_Kozlowski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_kozlowski/32/87061_2.png) [@Daniel\_Kozlowski](https://discuss.elastic.co/u/Daniel_Kozlowski)
#### Post date: [August 11, 2022, 2:08pm UTC](https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922/3 "2022-08-11T14:08:43Z")

</div>

Yes but It does not get to the network as when i do that is crashes the app. It appears the format is wrong. The data structure that works is an array of objects and the one I paste in is an object structure.

```auto
app.js:94 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'load')
    at app.js:94:42
    at Array.forEach (<anonymous>)
    at app.js:93:29
(anonymous) @ app.js:94
(anonymous) @ app.js:93
Promise.then (async)
(anonymous) @ app.js:92
e @ jquery.min.js:2
t @ jquery.min.js:2
setTimeout (async)
(anonymous) @ jquery.min.js:2
c @ jquery.min.js:2
fireWith @ jquery.min.js:2
fire @ jquery.min.js:2
c @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
B @ jquery.min.js:2
helpers.js:99 Uncaught TypeError: filters2.reduce is not a function
    at mergeFilters (helpers.js:99:1)
    at SearchDriver.js:178:126
    at later (DebounceManager.js:12:1)

```

---

<div class="post-metadata">

### Author: ![Daniel\_Kozlowski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_kozlowski/32/87061_2.png) [@Daniel\_Kozlowski](https://discuss.elastic.co/u/Daniel_Kozlowski)
#### Post date: [August 12, 2022, 4:27am UTC](https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922/4 "2022-08-12T04:27:47Z")

</div>

I just tried it with national parks and it gives an error

```auto
const config = {
  searchQuery: {
    facets: buildFacetConfigFromConfig(),
    ...buildSearchOptionsFromConfig(),
    filters: [{
      "any": [
        {
          "all": [
            { "states": "California" },
            { "world_heritage_site": "true" }
          ]
        }
      ]
    }]
  },

```

An unexpected error occurred: Cannot read properties of undefined (reading 'map')

This works

```auto
const config = {
  searchQuery: {
    facets: buildFacetConfigFromConfig(),
    ...buildSearchOptionsFromConfig(),
    filters : [{field: 'world_heritage_site', values: ["true"]}],
  },
  autocompleteQuery: buildAutocompleteQueryConfig(),
  apiConnector: connector,
  alwaysSearchOnInitialLoad: true
};

```

But i have no idea how to nest it

---

<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: [August 12, 2022, 9:58am UTC](https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922/5 "2022-08-12T09:58:12Z")

</div>

Im pretty positive that although the API supports nested, Search UI doesn't. Could you open a ticket in Search UI repo and we will take a look 🙂

Joe

---

<div class="post-metadata">

### Author: ![Daniel\_Kozlowski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_kozlowski/32/87061_2.png) [@Daniel\_Kozlowski](https://discuss.elastic.co/u/Daniel_Kozlowski)
#### Post date: [August 12, 2022, 12:32pm UTC](https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922/6 "2022-08-12T12:32:05Z")

</div>

Thanks I opened up #850.

Any suggestions on how to work around this? I have a use case for finding all parts that fit which requires a nested query that works fine in the api but no luck in the ui.

---

<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: [August 12, 2022, 5:58pm UTC](https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922/7 "2022-08-12T17:58:06Z")

</div>

Thanks @Daniel_Kozlowski

Sorry, I don't have any good workarounds atm for this issue. I can understand it is a blocker. We will try and investigate this next week and hopefully have a resolution for you by then.

Joe

---

<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 9, 2022, 5:59pm UTC](https://discuss.elastic.co/t/complex-filters-in-app-searchui/311922/8 "2022-09-09T17:59:00Z")

</div>

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