Elasticsearch模糊查询 - 最大编辑不能按预期工作

时间:2015-10-19 08:50:50

标签: elasticsearch fuzzy-search

我最近在搜索查询字符串中添加了“模糊运算符”和模糊查询设置,以涵盖用户错误输入(例如“zamestnanost”“zamestnani”)< / p>

POST /my_index/_search
{
   "query": {
      "query_string": {
         "query": "+(content:zamestnanost~)",
         "fuzzy_prefix_length": 3,
         "fuzzy_min_sim": 0.5, 
         "fuzzy_max_expansions": 50
      }
   }
}

据我了解模糊查询设置,fuzzy_min_sim = 0.5应允许length(query)*0.5原始查询的编辑(在本例中为6编辑)。

然而,它甚至与“更接近”的单词(令牌)不匹配,如

  • “zamestnani”
  • “zamestnany”

我有这种奇怪的感觉,它仍然只匹配索引中最大的单词。原始查询字符串中的2次编辑(这是模​​糊查询中的默认编辑计数)。

我也对我的查询进行了解释,结果支持这个假设,我想。 _explanation看起来像这样:

"_explanation": {
   "value": 0.057083897,
   "description": "sum of:",
   "details": [
      {
         "value": 0.023866946,
         "description": "weight(content:zamestnano^0.8 in 0) [PerFieldSimilarity], result of:",
         "details": [
            {
               "value": 0.023866946,
               "description": "score(doc=0,freq=4.0), product of:",
               "details": [
                  {
                     "value": 0.66062796,
                     "description": "queryWeight, product of:",
                     "details": [
                        {
                           "value": 0.8,
                           "description": "boost"
                        },
                        {
                           "value": 4.624341,
                           "description": "idf(docFreq=1, maxDocs=75)"
                        },
                        {
                           "value": 0.17857353,
                           "description": "queryNorm"
                        }
                     ]
                  },
                  {
                     "value": 0.036127664,
                     "description": "fieldWeight in 0, product of:",
                     "details": [
                        {
                           "value": 2,
                           "description": "tf(freq=4.0), with freq of:",
                           "details": [
                              {
                                 "value": 4,
                                 "description": "termFreq=4.0"
                              }
                           ]
                        },
                        {
                           "value": 4.624341,
                           "description": "idf(docFreq=1, maxDocs=75)"
                        },
                        {
                           "value": 0.00390625,
                           "description": "fieldNorm(doc=0)"
                        }
                     ]
                  }
               ]
            }
         ]
      },
      {
         "value": 0.03321695,
         "description": "weight(content:zamestnanos^0.9090909 in 0) [PerFieldSimilarity], result of:",
         "details": [
            {
               "value": 0.03321695,
               "description": "score(doc=0,freq=6.0), product of:",
               "details": [
                  {
                     "value": 0.7507135,
                     "description": "queryWeight, product of:",
                     "details": [
                        {
                           "value": 0.9090909,
                           "description": "boost"
                        },
                        {
                           "value": 4.624341,
                           "description": "idf(docFreq=1, maxDocs=75)"
                        },
                        {
                           "value": 0.17857353,
                           "description": "queryNorm"
                        }
                     ]
                  },
                  {
                     "value": 0.044247173,
                     "description": "fieldWeight in 0, product of:",
                     "details": [
                        {
                           "value": 2.4494898,
                           "description": "tf(freq=6.0), with freq of:",
                           "details": [
                              {
                                 "value": 6,
                                 "description": "termFreq=6.0"
                              }
                           ]
                        },
                        {
                           "value": 4.624341,
                           "description": "idf(docFreq=1, maxDocs=75)"
                        },
                        {
                           "value": 0.00390625,
                           "description": "fieldNorm(doc=0)"
                        }
                     ]
                  }
               ]
            }
         ]
      }
   ]
}

仅使用模糊查询编辑创建查询“zamestnano”“zemestnanos”

我理解模糊查询设置吗?你能指出我的错误吗?

非常感谢每个想法!

1 个答案:

答案 0 :(得分:1)

来自the documentation

  

0.0..1.0

     

[1.7.0]在1.7.0中弃用。 Elasticsearch 2.0将删除对相似性的支持。使用以下公式转换为编辑距离:length(term)*(1.0 - fuzziness),例如0.6的模糊度和长度为10的项将导致编辑距离为4. 注意:在所有API中除外Fuzzy Like This Query,允许的最大编辑距离为2

最简单的方法是使用validate API:

GET _validate/query?explain&index=my_index
{
  "query": {
    "query_string": {
      "query": "+(content:zamestnanost~)",
      "fuzzy_prefix_length": 3,
      "fuzzy_min_sim": 0.5,
      "fuzzy_max_expansions": 50
    }
  }
}

这给出了这个结果:

   "explanations": [
      {
         "index": "test",
         "valid": true,
         "explanation": "+content:zamestnanost~2"
      }
   ]

显示ES将在查询中使用的实际编辑距离:zamestnanost~2