0

When using simple_query_string with the prefix operator * and a fuzziness value ~N on the same word the prefix search appears seems to be disabled.

{
  "query": {
    "simple_query_string": {
      "query": "Abcd*~2",
      "fields": ["name"]
    }
  }
}

It's very obvious that prefix gets disabled whenever you set the fuzziness to 0 and the query becomes Abcd*~0 then there is no prefix search and no fuzziness.

This isn't mentioned in the docs so I'm not sure if I'm doing it wrong.

I've tried:

  • swapping the operator order: Abcd~2* -- in _explain this introduces fuzziness variations but omits the prefix operator
  • using parens for precedence: (Abcd*)~2 -- in _explain this uses the prefix but omits the fuzziness operator1
  • duplicating the word: (Abcd* Abcd~2) -- this works, it obviously shows the reunion of both queries instead of the composition of both effects2.

1 I'm assuming that in this case ~2 shouldn't be interpreted as the SLOP operator because there is no phrase (no quotes).

2 I can understand that compositing those effects may generate too many possible variants -- fuzzy adds 50 variants then prefix searches for each of those, that

Mihai Stancu
  • 15,848
  • 2
  • 33
  • 51
  • 1
    In query string it is mentioned that "Avoid mixing fuzziness with wildcards Mixing fuzzy and wildcard operators is not supported. When mixed, one of the operators is not applied" https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#avoid-widlcards-fuzzy-searches. I think this will apply to simple_query_string too – jaspreet chahal May 27 '20 at 09:24
  • It probably shares an underlying implementation. Thank you @jaspreetchahal Can you please write your comment as an answer so I can accept it? – Mihai Stancu May 27 '20 at 09:33

1 Answers1

2

As per query-string docs

Mixing fuzzy and wildcard operators is not supported. When mixed, one of the operators is not applied. For example, you can search for app~1 (fuzzy) or app* (wildcard), but searches for app*~1 do not apply the fuzzy operator (~1).

It considers either wildcard or fuzzy whichever is first. For Abcd~2* It is just returning all the documents

jaspreet chahal
  • 8,817
  • 2
  • 11
  • 29