How to Implement Flexible Value Filters for a Field in Elastic App Search?

Hello,

We're currently facing a challenge with a client who requires a filter for their App Search search query.

We've already consulted the Elastic documentation and have implemented a value filter. However, our issue lies in the specificity of the value filter, which doesn't align with our use case.

In our scenario:

We have a field named available_languages.

This field can contain values like fr:de:en or potentially nl:de and various other combinations.

Our goal is to apply a value filter to the available_languages field using a specific value, for instance, fr However, the current setup only works when there's an exact match with fr in the available_languages field, rather than matching all values like fr:en…

Is there a way to achieve this flexibility in the value filter or with another filter?

Hi there @Chenko - I think the easiest solution here would be to reformulate your data if possible to index the available languages as an array rather than as a delimited string.

So instead of indexing available_languages as fr:de:en you would index something that looked like this:

PUT /my-stuff/_doc/1
{
  "available_languages": [ "fr", "de", "en" ]
}

Then the filter query will work as expected:

curl -X POST '<your host>/api/as/v1/engines/<your engine name>/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-<your key>' \
-d '{
  "query": "...",
  "filters" : {
    "available_languages": [ "fr" ]
  }
}'

Hi, Thanks for your reply.
That would be the easiest indeed, thanks!

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