elasticsearch禁用词频评分

2023-11-23

我想更改 Elasticsearch 中的评分系统,以摆脱对某个术语多次出现的计数。例如,我想要:

“德克萨斯州 德克萨斯州 德克萨斯州”

and

"texas"

得出相同的分数。我发现这个映射,elasticsearch 说会禁用术语频率计数,但我的搜索结果并不相同:

"mappings":{
"business": {   
   "properties" : {
       "name" : {
          "type" : "string",
          "index_options" : "docs",
          "norms" : { "enabled": false}}
        }
    }
}

}

任何帮助将不胜感激,我无法找到很多这方面的信息。

我正在添加我的搜索代码以及使用解释时返回的内容。

我的搜索代码:

Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "escluster").build();
    Client client = new TransportClient(settings)
    .addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300));

    SearchRequest request =  Requests.searchRequest("businesses")
            .source(SearchSourceBuilder.searchSource().query(QueryBuilders.boolQuery()
            .should(QueryBuilders.matchQuery("name", "Texas")
            .minimumShouldMatch("1")))).searchType(SearchType.DFS_QUERY_THEN_FETCH);
    
    ExplainRequest request2 = client.prepareIndex("businesses", "business")

当我用解释搜索时我得到:

  "took" : 14,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_shard" : 1,
      "_node" : "BTqBPVDET5Kr83r-CYPqfA",
      "_index" : "businesses",
      "_type" : "business",
      "_id" : "AU9U5KBks4zEorv9YI4n",
      "_score" : 1.0,
      "_source":{
"name" : "texas"
}
,
      "_explanation" : {
        "value" : 1.0,
        "description" : "weight(_all:texas in 0) [PerFieldSimilarity], result of:",
        "details" : [ {
          "value" : 1.0,
          "description" : "fieldWeight in 0, product of:",
          "details" : [ {
            "value" : 1.0,
            "description" : "tf(freq=1.0), with freq of:",
            "details" : [ {
              "value" : 1.0,
              "description" : "termFreq=1.0"
            } ]
          }, {
            "value" : 1.0,
            "description" : "idf(docFreq=2, maxDocs=3)"
          }, {
            "value" : 1.0,
            "description" : "fieldNorm(doc=0)"
          } ]
        } ]
      }
    }, {
      "_shard" : 1,
      "_node" : "BTqBPVDET5Kr83r-CYPqfA",
      "_index" : "businesses",
      "_type" : "business",
      "_id" : "AU9U5K6Ks4zEorv9YI4o",
      "_score" : 0.8660254,
      "_source":{
"name" : "texas texas texas"
}
,
      "_explanation" : {
        "value" : 0.8660254,
        "description" : "weight(_all:texas in 0) [PerFieldSimilarity], result of:",
        "details" : [ {
          "value" : 0.8660254,
          "description" : "fieldWeight in 0, product of:",
          "details" : [ {
            "value" : 1.7320508,
            "description" : "tf(freq=3.0), with freq of:",
            "details" : [ {
              "value" : 3.0,
              "description" : "termFreq=3.0"
            } ]
          }, {
            "value" : 1.0,
            "description" : "idf(docFreq=2, maxDocs=3)"
          }, {
            "value" : 0.5,
            "description" : "fieldNorm(doc=0)"
          } ]
        } ]
      }
    } ]
  }
    

看起来它仍在考虑频率和文档频率。有任何想法吗?抱歉,格式错误,我不知道为什么它看起来如此怪诞。

我的代码来自浏览器搜索 http://localhost:9200/businesses/business/_search?pretty=true&qname=texas 是:

    {
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "businesses",
      "_type" : "business",
      "_id" : "AU9YcCKjKvtg8NgyozGK",
      "_score" : 1.0,
      "_source":{"business" : {
"name" : "texas texas texas texas" }
}
    }, {
      "_index" : "businesses",
      "_type" : "business",
      "_id" : "AU9YateBKvtg8Ngyoy-p",
      "_score" : 1.0,
      "_source":{
"name" : "texas" }

    }, {
      "_index" : "businesses",
      "_type" : "business",
      "_id" : "AU9YavVnKvtg8Ngyoy-4",
      "_score" : 1.0,
      "_source":{
"name" : "texas texas texas" }

    }, {
      "_index" : "businesses",
      "_type" : "business",
      "_id" : "AU9Yb7NgKvtg8NgyozFf",
      "_score" : 1.0,
      "_source":{"business" : {
"name" : "texas texas texas" }
}
    } ]
  }
}

它找到了我在那里的所有 4 个物体,并且它们的得分都相同。 当我使用解释运行 java API 搜索时,我得到:

    {
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.287682,
    "hits" : [ {
      "_shard" : 1,
      "_node" : "BTqBPVDET5Kr83r-CYPqfA",
      "_index" : "businesses",
      "_type" : "business",
      "_id" : "AU9YateBKvtg8Ngyoy-p",
      "_score" : 1.287682,
      "_source":{
"name" : "texas" }
,
      "_explanation" : {
        "value" : 1.287682,
        "description" : "weight(name:texas in 0) [PerFieldSimilarity], result of:",
        "details" : [ {
          "value" : 1.287682,
          "description" : "fieldWeight in 0, product of:",
          "details" : [ {
            "value" : 1.0,
            "description" : "tf(freq=1.0), with freq of:",
            "details" : [ {
              "value" : 1.0,
              "description" : "termFreq=1.0"
            } ]
          }, {
            "value" : 1.287682,
            "description" : "idf(docFreq=2, maxDocs=4)"
          }, {
            "value" : 1.0,
            "description" : "fieldNorm(doc=0)"
          } ]
        } ]
      }
    }, {
      "_shard" : 1,
      "_node" : "BTqBPVDET5Kr83r-CYPqfA",
      "_index" : "businesses",
      "_type" : "business",
      "_id" : "AU9YavVnKvtg8Ngyoy-4",
      "_score" : 1.1151654,
      "_source":{
"name" : "texas texas texas" }
,
      "_explanation" : {
        "value" : 1.1151654,
        "description" : "weight(name:texas in 0) [PerFieldSimilarity], result of:",
        "details" : [ {
          "value" : 1.1151654,
          "description" : "fieldWeight in 0, product of:",
          "details" : [ {
            "value" : 1.7320508,
            "description" : "tf(freq=3.0), with freq of:",
            "details" : [ {
              "value" : 3.0,
              "description" : "termFreq=3.0"
            } ]
          }, {
            "value" : 1.287682,
            "description" : "idf(docFreq=2, maxDocs=4)"
          }, {
            "value" : 0.5,
            "description" : "fieldNorm(doc=0)"
          } ]
        } ]
      }
    } ]
  }
}

看起来好像无法覆盖index options对于在映射中初始设置字段后的字段

Example:

put test
put test/business/_mapping
{

      "properties": {
         "name": {
            "type": "string",
           "index_options": "freqs",
            "norms": {
               "enabled": false
            }
         }
      }

}
put test/business/_mapping
{

      "properties": {
         "name": {
            "type": "string",
            "index_options": "docs",
            "norms": {
               "enabled": false
            }
         }
      }

}
get  test/business/_mapping

   {
   "test": {
      "mappings": {
         "business": {
            "properties": {
               "name": {
                  "type": "string",
                  "norms": {
                     "enabled": false
                  },
                  "index_options": "freqs"
               }
            }
         }
      }
   }
}

您必须重新创建索引才能获取新映射

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

elasticsearch禁用词频评分 的相关文章

随机推荐

  • LNK1117:选项“VERSION:1.0.0”中的语法错误[重复]

    这个问题在这里已经有答案了 当我尝试构建时 我有一个非常好奇的问题Visual Studio 2013 有人可以帮助我吗 我做错了什么 原始消息 德语 1 gt Erstellen gestartet Projekt npworpg Kon
  • Scala 类型:A 类不等于 T,其中 T 为:类型 T = A

    我正在阅读 Scala 编程 一书的第 20 7 节 我想知道为什么这段代码编译时 class Food class Fish extends Food class Grass extends Food abstract class Ani
  • Logback - 启动时不创建空日志文件

    我有一个项目 其中有很多 工具 类 它们有自己的日志记录 这些日志文件是在应用程序启动时创建的 但在使用之前保持为空 是否可以告诉 logback 在启动时不应创建空文件 但只有当它们被使用时 不知何故 我找不到有关此主题的信息 谢谢 Lo
  • Xamarin.Forms - 将 CollectionView 的高度调整为适合儿童的最小尺寸

    I have a CollectionView with a few items in it I m trying to adjust the size of the CollectionView to be just big enough
  • 如何使用Python读取MS-Word文件中表格的内容?

    如何读取和处理 DOCX 文件中表格的每个单元格的内容 我在 Windows 7 和 PyWin32 上使用 Python 3 2 来访问 MS Word 文档 我是初学者 所以我不知道到达表格单元格的正确方法 到目前为止我刚刚这样做了 i
  • 如何在Android中检查特定设备是否支持4G网络?

    我想检查一下是否特定设备具有对 4G 网络的硬件支持 我将详细说明这个问题 在应用程序中 我们有一个设置页面 用户可以在其中进行选择并允许应用程序仅在选定的网络中运行 例如 用户可以选择该应用程序仅在 WiFi 网络或仅在 3G 网络等中运
  • webapi2 返回不带引号的简单字符串

    简单场景 public IHttpActionResult Get return Ok
  • ClosureCleaner.clean的目的

    Before sc runJob调用dagScheduler runJob 对 rdd 执行的 func 被 清理 为ClosureCleaner clean 为什么 Spark 必须这样做 目的是什么 Ankur Dave 一位 Spar
  • docker-compose + django + redis - 连接到 127.0.0.1:6379 时出现错误 111。连接被拒绝

    我已经看过了这个答案并且不知道如何将其应用于我的问题 所以如果答案存在 我们将不胜感激 我也是 docker 和 docker compose 的菜鸟 我有一个简单的 docker compose yml version 3 service
  • Php 从 C# .NET RIJNDAEL 解密字符串 256

    修复 data base64 decode str replace GET data 无论出于何种原因 Php 将 GET 变量中的 转换为空格 我正在尝试解密正在 C NET 中解密的字符串 代码的结果各不相同 有几次最终字符串的某些部分
  • 为什么我们使用system.out.flush()? [复制]

    这个问题在这里已经有答案了 有人可以解释一下我们为什么要使用system out flush 以更简单的方式 如果有可能丢失数据 请给我提供一个例子 如果您在下面的代码中注释它 则不会发生任何变化 class ReverseApp publ
  • 自动实现 Rust 新类型(具有一个字段的元组结构)的封闭类型的特征

    在 Rust 中 可以创建只有一个字段的元组结构 如下所示 struct Centimeters i32 我想做基本算术Centimeters无需每次通过模式匹配提取它们的 内部 值 也无需实现Add Sub 特征和重载运算符 我想做的是
  • 拦截 WPF 应用程序的每次鼠标点击

    我希望拦截 WPF 应用程序中的每次鼠标单击 似乎使用命令路由机制这应该很容易 但抱歉我没有找到任何东西 我的应用程序实现了多个安全级别 并且如果在 x 分钟内没有人与应用程序交互 单击 则需要自动恢复到最严格的级别 我的计划是添加一个计时
  • 检测设备是用密码锁还是人脸锁的指纹锁保护的?

    我的应用程序包含登录的用户身份验证 包括 pin 图案 指纹解锁 这取决于设备安全性 我正在使用生物识别管理器来检测设备是否支持指纹生物识别管理器并检查设备是否安全使用isDeviceSecure 我需要检测移动设备在哪种模式下受到保护 无
  • Python 3.2 中的暴力破解脚本

    我是编写代码的初学者 我从 Python 开始 因为它看起来最简洁 最容易上手 我目前使用的是 Python 3 2 现在我读了一些关于Python编码的在线书籍等等 我制作了一些小程序 仅此而已 但后来我想制作一个程序 可以暴力破解随机密
  • 获取 UIStackView 子视图的框架

    我在 IB 中创建了一个 UIStackView 其分布设置为 Fill Equally 我希望获取每个子视图的框架 但以下代码始终返回 0 0 0 0 class ViewController UIViewController IBOut
  • 每个浏览器的媒体查询

    我想根据浏览器调整输入字段的大小 我可以为每个浏览器编写媒体查询 以便在单独的浏览器上为输入字段设置单独的宽度 就像对于 mozilla 来说 它在 chrome 上将具有单独的宽度 而 Opera 则将具有单独的宽度 媒体查询 are m
  • 如何使用 kotlin android 更新我的 Recyclerview?

    我有一个显示数据的 Recyclerview 活动 现在我想更新我的RecyclerView一旦获得新数据 现在每次我关闭并重新打开我的应用程序时 都会显示新数据 但我希望它没有关闭更新我的观点 我试过这个 但什么都行不通 fun setu
  • Apache Spark 案例在不同列上具有多个 when 子句

    鉴于以下结构 val df Seq Color Shape Range Size map Tuple1 apply toDF color val df1 df withColumn Success when color lt gt whit
  • elasticsearch禁用词频评分

    我想更改 Elasticsearch 中的评分系统 以摆脱对某个术语多次出现的计数 例如 我想要 德克萨斯州 德克萨斯州 德克萨斯州 and texas 得出相同的分数 我发现这个映射 elasticsearch 说会禁用术语频率计数 但我