模糊匹配中具有编辑距离的模糊性参数中的Elasticsearch不一致

如何解决模糊匹配中具有编辑距离的模糊性参数中的Elasticsearch不一致

我正在尝试使用span_near多个子句来理解模糊搜索在模糊搜索中的作用。

我在这里计算文件数。这是一个查询

.data

这给了我预期的结果:

GET wikipedia-20200820/_search
{  
   "query":{  
      "bool":{  
         "must":[  
            {  
               "span_near":{  
                  "clauses":[
                     {  
                        "span_multi":{  
                           "match":{  
                              "fuzzy":{  
                                 "text":{  
                                    "value":"labor","fuzziness":"2"
                                 }
                              }
                           }
                        }
                     },{  
                        "span_multi":{  
                           "match":{  
                              "fuzzy":{  
                                 "text":{  
                                    "value":"unionism",{  
                        "span_multi":{  
                           "match":{  
                              "fuzzy":{  
                                 "text":{  
                                    "value":"among",{  
                        "span_multi":{  
                           "match":{  
                              "fuzzy":{  
                                 "text":{  
                                    "value":"negros","fuzziness":"2"
                                 }
                              }
                           }
                        }
                     }
                  ],"slop":1,"in_order":true
               }
            }
         ],"filter": [ 
        { "term":  { "ns": 0 }},{ "range": { "timestamp": { "gte": "2020-01-01" }}}
      ]
      }
   }
}

尽管{ "took" : 284,"timed_out" : false,"_shards" : { "total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0 },"hits" : { "total" : { "value" : 1,"relation" : "eq" },"max_score" : 2238.6646,"hits" : [ { "_index" : "wikipedia-20200820","_type" : "_doc","_id" : "GhxaT3UBz_UQYd3DEAJT","_score" : 2238.6646,"_source" : { "page_title" : "National Brotherhood of Workers of America","ns" : 0,"page_id" : 28365131,"redirect" : null,"revision_id" : 965097134,"revision_parent_id" : 891907364,"timestamp" : "2020-06-29T11:26:55Z","contributor" : { "username" : "JJMC89 bot III","id" : 35936988 },"comment" : "Moving [[:Category:African-American history between emancipation and the Civil Rights Movement]] to [[:Category:African-American history between emancipation and the civil rights movement]] per [[Wikipedia:Categories for discussion/Speedy]]","sha1" : "q1rz1h5n6qk9cpdt5qf0zqrydd9vx7e","minor" : "TRUE","model" : "wikitext","format" : "text/x-wiki","text" : """The '''National Brotherhood of Workers of America''' (NBWA) was the largest body of organised [[African American]] workers in the [[United States of America]] in 1919.<ref>''Revolutionary radicalism: its history,purpose and tactics with an exposition and discussion of the steps being taken and required to curb it,being the report of the Joint Legislative Committee Investigating Seditious Activities'',filed 24 April 1920,in the Senate of the State of New York</ref> ==First congress== The organisation was formed by T.J. Pree and R.T. Sims. [[Philip Randolph]] was also on the board.<ref name=yho>[http://hierographics.org/yourhistoryonline/yourhistoryonlineVIII.htm Your History online],accessed 17 August 2010</ref> The NBWA held its congress in [[Washington DC]] from 8–14 September 1919. There were 115 delegates primarily from the South. Three delegates were from the [[Industrial Workers of the World]] and fifteen from the Society for the Advancement of Trade Unionism among Negroes. No delegates were accepted from the [[American Federation of Labor]].<ref>''Revolutionary radicalism: its history,in the Senate of the State of New York</ref> ==Resolutions== They passed resolutions to the effect that: ". . . The combination of black and white workers will be a powerful lesson to the capitalists of the solidarity of labor. It will show that labor,black and white,is conscious of its interests and power. This will serve to convert a class of worker,which has been used by the capitalist class to defeat organised labor,into an ardent,class-conscious,intelligent,militant group." "and be it further resolved,that we recommend to all the working people of our race,that they immediately make themselves acquainted more in detail with the aims,objects and methods of said organization,the National Association for the Protection of Labor Unionism Among Negroes,in order that we may,as speedily as possible,align ourselves with and join the industrial unions that have already organized,and help to organize new industrial unions in such industries where they do not yet exist. "and be it further resolved,that we shall henceforth devote all our energies to building up the new order of society along lines above indicated,to the exclusion of efforts hitherto expended in other directions." <ref>''Revolutionary radicalism: its history,in the Senate of the State of New York</ref> The NBWA functioned as an independent Union,drawing most of its support from shipyard and dock workers in the [[Tidewater region of Virginia]] area.<ref>''Crisis'',November 1951,p626</ref> The union dissolved in 1921,under pressure from the American Federation of Labor.<ref name=yho/> ==References== {{reflist}} [[Category:African-American leftism]] [[Category:African-American history between emancipation and the civil rights movement]] [[Category:Trade unions established in 1919]] [[Category:Trade unions disestablished in 1921]] [[Category:African-American trade unions]]""" } } ] } } 参数是documented代表“编辑距离” /“ Levenshtein距离”,但对我来说似乎不一致。然后,为了了解模糊性的影响,我尝试更改查询中的某些单个术语,有时还更改了fuzziness参数,使其他所有参数保持不变。

我正在汇总下表中我在查询中尝试的一些更改以及该查询是否导致相同的结果:

fuzziness

有人可以解释+----------------+---------------+-----------+---------------+-----------------------------+ | iniatial_query | updated_query | fuzziness | edit_distance | elastic_returns_same_result | +----------------+---------------+-----------+---------------+-----------------------------+ | "labor" | "labot" | 2 | 1 | Yes | | "labor" | "labori" | 2 | 1 | No | | "labor" | "lab" | 2 | 2 | No | | "labor" | "lab" | 3 | 2 | No | | "labor" | "lab" | 4 | 2 | No | | "labor" | " labor" | 2 | 1 (1 space) | Yes | | "labor" | " labor" | 1 | 1 (1 space) | Yes | | "labor" | " labor" | 2 | 2 (2 space) | No | | "unionism" | "unionismi" | 2 | 1 | Yes | | "unionism" | "unionismi" | 1 | 1 | Yes | | "among" | "amonng" | 2 | 1 | Yes | | "among" | "amonng" | 1 | 1 | Yes | | "among" | "amonnng" | 2 | 2 | No | | "among" | "amonnng" | 3 | 2 | No | | "among" | "amonnng" | 10 | 2 | No | +----------------+---------------+-----------+---------------+-----------------------------+ 参数对查询的影响吗?

解决方法

Fuzziness Parameters

自动

根据术语的长度生成编辑距离。低和 可以选择提供高距离参数AUTO:[low],[high]。 如果未指定,则默认值为3和6,等效于 AUTO:3,6的长度:

0..2必须完全匹配

3..5允许一次编辑

5允许的两次编辑AUTO通常应为以下选项的首选值 模糊。

在问题中,您提到过,当updated_value为lab时,elasticsearch不会返回与以前相同的结果。但是正如您在下面看到的那样,结果是准确的。这是因为编辑距离是2。

lab --> labo --> labor

类似地,对于labori laboramonnng来说,结果是准确的

索引数据:

{
  "text":"The organisation was formed by T.J. Pree and R.T. Sims. [[Philip Randolph]] was also on the board.<ref name=yho>[http://hierographics.org/yourhistoryonline/yourhistoryonlineVIII.htm Your History online],accessed 17 August 2010</ref> The NBWA held its congress in [[Washington DC]] from  8–14 September 1919. There were 115 delegates primarily from the South. Three delegates were from the [[Industrial Workers of the World]] and fifteen from the Society for the Advancement of Trade Unionism among Negroes. No delegates were accepted from the [[American Federation of Labor]].<ref>''Revolutionary radicalism: its history,purpose and tactics with an exposition and discussion of the steps being taken and required to curb it,being the report of the Joint Legislative Committee Investigating Seditious Activities'',filed 24 April 1920,in the Senate of the State of New York</ref>"
}

搜索查询:

{
  "query": {
    "bool": {
      "must": [
        {
          "span_near": {
            "clauses": [
              {
                "span_multi": {
                  "match": {
                    "fuzzy": {
                      "text": {
                        "value": "lab",<-- note this
                        "fuzziness": "2"
                      }
                    }
                  }
                }
              }
            ],"slop": 1,"in_order": true
          }
        }
      ]
    }
  }
}

搜索结果:

 "hits": [
      {
        "_index": "64492853","_type": "_doc","_id": "1","_score": 2.2105305,"_source": {
          "text": "The organisation was formed by T.J. Pree and R.T. Sims. [[Philip Randolph]] was also on the board.&lt;ref name=yho&gt;[http://hierographics.org/yourhistoryonline/yourhistoryonlineVIII.htm Your History online],in the Senate of the State of New York&lt;/ref&gt;"
        }
      }
    ]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-