Fuzziness not work with bool_prefix multi_match (search-as-you-type)

Hi everyone.
I struggling with a problem is that fuzziness not work with multi_match bool_prefix query , but I found on document that fuzziness option was supported:

https://www.elastic.co/guide/en/elasticsearch/reference/7.4/query-dsl-multi-match-query.html#type-bool-prefix

Here is my query:

{
  "_source": {},
  "query": {
    "multi_match": {
      "query": "dross",
      "type": "bool_prefix",
      "fields": [
        "title",
        "title._2gram",
        "title._3gram"
      ],
      "fuzziness": "AUTO"
    }
  }
}

I'm using Elasticsearch 7.4, and trying to use Search-as-you-type feature in Elasticsearch 7.4: https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-as-you-type.html

Here is my example to reproduce issue:

  • Create a index with a field has search-as-you-type field type, and indexing a document:
PUT my_index
{
  "mappings": {
    "properties": {
      "my_field": {
        "type": "search_as_you_type"
      }
    }
  }
}

PUT my_index/_doc/1?refresh
{
  "my_field": "dress"
}
  • After that I query with multi_match bool_prefix, with query term is "dross" (I assume that user when searing made mistake):
GET my_index/_search
{
  "query": {
    "multi_match": {
      "query": "dross",
      "type": "bool_prefix",
      "fields": [
        "my_field",
        "my_field._2gram",
        "my_field._3gram"
      ],
      "fuzziness": "AUTO"
    }
  }
}

The result is empty. But my expectation is that it should show the result is "dress" like this:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my_index",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "my_field" : "dress"
        }
      }
    ]
  }
}

Anyone can help? Thanks in advance.

Can you explain a bit more about whats not working? Do you get errors? Are certain documents you would expect to match not returned? In this case, can you give some examples?

HI @cbuescher
Thanks for your quick reply, here is my example:

  • Create a index with a field has search-as-you-type field type, and indexing a document:
PUT my_index
{
  "mappings": {
    "properties": {
      "my_field": {
        "type": "search_as_you_type"
      }
    }
  }
}

PUT my_index/_doc/1?refresh
{
  "my_field": "dress"
}
  • After that I query with multi_match bool_prefix, with query term is "dross" (I assume that user when searing made mistake):
GET my_index/_search
{
  "query": {
    "multi_match": {
      "query": "dross",
      "type": "bool_prefix",
      "fields": [
        "my_field",
        "my_field._2gram",
        "my_field._3gram"
      ],
      "fuzziness": "AUTO"
    }
  }
}

The result is empty. But my expectation is that it should show the result is "dress" like this:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my_index",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "my_field" : "dress"
        }
      }
    ]
  }
}

I think the explanation can be found in https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#type-bool-prefix

The fuzziness , prefix_length , max_expansions , rewrite , and fuzzy_transpositions parameters are supported for the terms that are used to construct term queries, but do not have an effect on the prefix query constructed from the final term.

If, for example, you index "dress" and "dress code" and search with "query": "dross c", you should find both documents (works at least for me on 7.6.2). I can understand that this is a bit counter-intuitive, but then again users typing should be able to find the correct terms after typing "dr".

Oh, I see , thank you @cbuescher :slight_smile:

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