How can I use fuzzy search with synonyms?
Asked Answered
S

2

7

Fuzziness stopped working after me adding synonym file to the index. It seems like , it's not possible to use them at the same time. My query:

 "query": {
        "dis_max": {
            "queries": [{ 
                 "multi_match": {
                 "query": $('#searchterm').val(),
                 "fields": ["search_1"],
                 "fuzziness": "AUTO", 
                 "operator":  "and",
                 "max_expansions": 1
             }},
                { "match": { "search_2": $('#searchterm').val() }}
            ]
        }
    }

Mappings:

"mappings": {
"objs":{
  "properties": {
    "o":{
      "type": "string"
    },
    "loc":{
      "type":"geo_point"
    },
    "search_1":{
      "type": "string",
      "analyzer": "synonym"
    },
    "search_2":{
      "type": "string",
      "analyzer": "synonym"
    }
  }
}
Sheri answered 1/12, 2016 at 13:20 Comment(2)
Share your mappings.Tsan
I've just added it to the question. Could not share the complete mappings but the important partSheri
H
3

I just had the same issue, and it seems like you can't mix them, somebody already opened a github issue for this: https://github.com/elastic/elasticsearch/issues/25518 The issue was closed and they updated the docs: https://github.com/elastic/elasticsearch/blob/master/docs/reference/query-dsl/match-query.asciidoc

Here is the interesting part:

Note that fuzzy matching is not applied to terms with synonyms, as under the hood these terms are expanded to a special synonym query that blends term frequencies, which does not support fuzzy expansion.

Hothouse answered 9/5, 2019 at 14:50 Comment(0)
A
0

I had the same issue, and what I did as a workaround was creating an index for all synonyms then searching over the synonyms index with fuzziness, to get the correct spelling of it, then let's say that you got 2 or 3 hits, now these hits are the correct spelling for your synonyms on the original index, now you can search for them without using fuzziness on the original index.

like that, you are searching with fuzziness only on synonyms.

Allegra answered 22/4 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.