Search query in a list of texts

Hello everyone,

I have a search problem in ES. In the index i have a field that is a list of texts like the following:

list_field = [text1, text2, text3, …]

I want to search for a number of terms that all belong to the same text entry. If one term is in text1 and another is in text2 for example, the search should not return any results.

Is this possible with the current mapping or do i have to come up with a different representation of this field?

Thanks in advance for any tip.

What is the current mapping for that field?

Hello @Christian_Dahlqvist

The mapping is:

"skepseis": {
"type": "text",
"analyzer": "greek"
}

During the ingest process i build a list with all that texts and send them to ES.

Thank you for answering.

As far as I know the functionality you are asking for would require a mapping change, but maybe someone else may have a solution.

I suspect the solution is to use phrase queries and a big “position increment gap”.

Make the phrase queries not require an order and have a “slop” factor greater than the max number of words in a text value but less than the large position increment gap used to put artificial space between the text elements in your array

1 Like

Hello @Mark_Harwood1

Thank you for your suggestions. I will try them. Hope will fix the issue.

Hi there,

If your index is not huge, maybe you can use a script_query

GET yourindex/_search
{
  "query": {
    "script_score": {
      "query": {
        "match_all": {}
      },
      "script": {
        "source": """
          String[] terms = new String[] { "γιαούρτι", "ελληνικά" };
          for (item in params._source.list_field) {
            boolean allMatch = true;
            for (term in terms) {
              if (!item.contains(term)) {
                allMatch = false;
                break;
              }
            }
            if (allMatch) return 1.0;
          }
          return 0.0;
        """
      }
    }
  }
}

Regards,