Comples proximity searches using the simple_query_string

Hello,

I am trying to use the simple_query_string to perform a proximity search using the ~ operator.
Something like the following works fine.

"simple_query_string": {"query": ""Arizona Diamondbacks"~8", "default_operator": "AND"}

However I need to be able to define the words being searched for as a complex expression such as the following.

"simple_query_string": {"query": ""Arizona (Brewers | Diamondbacks)"~8", "default_operator": "AND"}

The expression could get much more complex than this, with the proximity terms becoming recursive AND/OR type algebraic expressions.

Is this achievable using the simple_query_string, or should I be looking elsewhere?

Thanks

Hi @mgrishaber,

For complex logic with lots AND/ORs I think it's easier to use a boolean filter with fuzziness parameter:

GET my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "field1": {
              "query": "univers",
              "fuzziness": "8"
            }
          }
        }
      ],
      "should": [
        {
          "match": {
            "field1": {
              "query": "universe",
              "fuzziness": "8"
            }
          }
        },
        {
          "match": {
            "field1": {
              "query": "universo",
              "fuzziness": "8"
            }
          }
        }
      ]
    }
  }
}

Maybe it can help you.

Cheers,
LG

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