Search arrays with arrays

Hi all,

I have an ES index where one of my mappings stores a simple array of named entities pre-set at the point of ingestion.

I'm trying to search my index using a given array of entities, to return documents where containing many of the same entities.

Some code for illustration...

GET /test_data/_search
{  
"query": {
    "match": {
      "entities": ['Trump', 'CNN', 'Oklahoma', 'Tiktok', 'Tulsa']
    }
  }
}

However, this returns a parse exception -- What would be the best method to search fields containing arrays using another array?

Thanks :slight_smile:

May be a terms query

GET test/_search
{
  "query": {
    "terms": {
      "addresses.city.keyword": [ "Brussels"],
      "boost": 1.0
    }
  }
}

Thanks for the quick response, I have tried a terms query, however, it returns zero responses when I know that there are documents that contain some/all of the terms provided -- this makes me think that terms provides only an exact match whereas I'm looking for a way to harness the score returned by ES to filter by similarity.

Any ideas? Sorry! :slight_smile: :smiley:

Then :slight_smile:

GET /test_data/_search
{  
"query": {
    "match": {
      "entities": "Trump CNN Oklahoma Tiktok Tulsa"
    }
  }
}

Perfect! Thank you so much! :))

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