Error: [400] Filters contains an invalid set of keys for object inside of field: filters root; can only have clauses or a single field name

I'm trying to get filtered result from elastic/app-search.

Below is facets data from first search.

<h3>Brand</h3>
<input type="checkbox" name="brand1" value="brand1">
<input type="checkbox" name="brand2" value="brand2">

<h3>Price</h3>
<input type="checkbox" name="price1" value="price1">
<input type="checkbox" name="price2" value="price2">

When user click any checkbox, the value is contained to product_options's filter.
It's working if filter has one condition like this:

product_options {
    result_fields: {...},
    facets: {...},
    page: {...},
    sort: {...},
    filteres: {
        brand: ["brand1"] 
    }
}

And it still working when there's 2 or more brands. like this:

product_options {
    result_fields: {...},
    facets: {...},
    page: {...},
    sort: {...},
    filteres: {
        brand: ["brand1", "brand2"...] 
    }
}

but, when the filters object has 2 or more conditions in its root, the error occurred like this:

Error: [400] Filters contains an invalid set of keys for object inside of field: filters root; can only have clauses or a single field name

If I want to use multi condition like below:

filters: {
    brand: ["brand1"],
    price: ["price1"]
}

What should I do?

Thank you for reading and helping!

When applying one filter you can use the shorthand syntax as you have above.

When applying multiple filters, you need to use the full filter syntax documented here: https://swiftype.com/documentation/app-search/api/search/filters#combining-filters

"filters": {
  "all": [
    { "brand": ["brand1"] },
    { "price": ["price1"] }
  ]
]}
2 Likes

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