Searching/filtering by enums/tags/categories?

Hi all.

I've got a large set of food dishes. I'd like to tag each dish with things like 'vegetarian', 'vegan', 'gluten free', etc. and be able to search by these tags. I.e., if a user wants to search 'pasta' as their query but also filter by 'vegetarian and gluten free'.

As there are an indefinite number of tags it isn't feasible to give each tag its own field. I'd much prefer to put them all in one 'tags' field, comma separated.

However, app-search seems to only filter/boost by exact match. I would like instead to do something like "If my tags field does not contain the term 'vegetarian', do not return this result."

Any ideas here?

Thank you

Hey @Andrew_Bennett.

So just to clarify...

You're saying you will have a tags fields which might have a list of tags like: ['vegetarian', 'vegetarian friendly', 'vegan', 'gluten-free']

You'd essentially like to do some sort of contains filter... like:

"filters": {
    "all": [
      { "tags": "vegetarian" },

But where "vegetarian", instead of matching on just the "vegetarian" tag would match any tag that contains the term "vegetarian". So it would match on both the "vegetarian" tag and the "vegetarian friendly" tag.

Does that sound correct?

Hi Jason, thanks for the reply!

While that does sound like something I'd have to address, it's not the issue I was referring to.

I am hoping to have a tags field like you said, but since app-search doesn't have an array/enum type I believe i'm forced to have the field as a text type looking something like "vegetarian, vegetarian-friendly, vegan, gluten-free".

When using a Value filter, I must provide a field value to match the filter on:

image (

As a concrete example:

"filters" : {
  "all": [
      { "tags": "vegetarian" },

wont match against a document with

tags: "vegetarian, vegetarian-friendly, vegan, gluten-free"

because "The value must be an exact match", whereas this is only a partial match. (i.e., my tags field contains the term vegetarian but is not exactly equal to vegetarian.

I hope I'm overlooking something here. Thanks again for taking the time!


Ah I see. So App Search actually DOES support Array types. I'm not sure where in the docs it is discussed, I will follow up after I have a look.

But essentially, if you make the tag field a "Text" type, you can provide either individual strings OR arrays of strings.

So both of these would be valid for the field "tags":

"tags": "vegetarian"

"tags": ["vegetarian", "vegetarian-friendly]

If you indexed a document with the latter, your filter would then work as expected.

So in other words, just to be absolutely clear, if you indexed the following document:

  name: "cucumber juice",
  tags: ["vegetarian, vegetarian-friendly, vegan, gluten-free"]

The following filter would indeed match on that document:

"filters" : {
  "all": [
      { "tags": "vegetarian" },

Make sense?

1 Like

Follow up: We have a very small line here mentioning that arrays are supported: We may want to elaborate on that a bit in our docs.

Hey Jason! Your replies were exactly what I was hoping to hear.

Thank you for all of your help, this is a big relief :slight_smile:

Happy to help.

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