Unable to match by value in array field

Hello,

I have a field where I store an array of strings (categories). When querying the categories I only receive a result when I'm searching for the first element of the categories' array (in my example below: hello).

When searching for any other element than the first one I won't receive any results.

I have a field named categories that is mapped like this:

PUT /products/_mapping/_doc

...
"categories": {
      "type": "text"
    },
...

My document has an array of categories:

PUT /products/_doc/42

{
    "_index": "products",
    "_type": "_doc",
    "_id": "42",
    "_version": 1,
    "found": true,
    "_source": {
        ...
        "categories": [
            "hello",
            "world"
        ],
        ...
    }
}

This is the search query:
POST /products/_search

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "categories": {
              "query": "hello",
              "boost": 100
            }
          }
        }
      ]
    }
  }
}

one result (product with id 42)

This one produces no results:
POST /products/_search

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "categories": {
              "query": "world",
              "boost": 100
            }
          }
        }
      ]
    }
  }
}

no result

I'm on Elastic Search 6.3.

Any ideas?

Thanks,
Christian

Ok, it seems to work. Probably I had a problem in my data fields with the last import!

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