当前位置: 首页 > 面试题库 >

elasticsearch禁用词频计分

童浩言
2023-03-14
问题内容

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

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

“得克萨斯州”

得分相同。我发现elasticsearch表示该映射将禁用词频统计,但是我的搜索结果却不一样:

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

}

任何帮助将不胜感激,我无法找到很多有关此的信息。

编辑:

我正在添加搜索代码,并在使用解释时html" target="_blank">返回了什么。

我的搜索代码:

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在映射中初始设置字段后,似乎无法覆盖该字段的

例:

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"
               }
            }
         }
      }
   }
}

您将不得不重新创建索引以获取新的映射



 类似资料:
  • 本文向大家介绍Python英文文章词频统计(14份剑桥真题词频统计),包括了Python英文文章词频统计(14份剑桥真题词频统计)的使用技巧和注意事项,需要的朋友参考一下 Python剑桥真题词频统计 最好还是要学以致用,自主搜集了19年最近的14份剑桥真题之后,通过Python提供的jieba第三方库,对所有的文章信息进行了词频统计,并选择性地剔除了部分简易词汇,比如数字,普通冠词等,博主较懒,

  • 问题内容: 我有2个文档,并且正在搜索关键字“ Twitter”。假设两个文档都是带有“标签”字段的博客文章。 文档A在“标签”字段中只有1个术语,即“ Twitter”。文档B在“标签”字段中有100个术语,但其中3个是“ Twitter”。 即使文档B的出现频率较高,“elasticsearch”也会给文档A更高的分数。但是该分数是“稀释的”,因为它具有更多的术语。由于文档B的搜索词频率较高,

  • 问题内容: 我必须使用python计算文本中的单词频率。我想到将单词保留在字典中,并对每个单词进行计数。 现在,如果我必须根据出现次数对单词进行排序。我可以使用相同的词典来代替使用具有键作为计数和单词数组作为值的新词典吗? 问题答案: 您可以使用相同的字典: 第二行显示: 如果只需要排序的单词列表,请执行以下操作: 该行打印:

  • 问题内容: 我正在尝试计算特定术语在整个索引中出现的总次数(术语收集频率)。我试图通过使用术语向量来做到这一点,但是这仅限于单个文档。即使在指定文档中存在术语的情况下,响应似乎也达到了某个doc_count(在field_statistics之内)的最大值,这使我怀疑其准确性。 请求: 尽管术语统计不应该特定于文档,但此处使用的文档ID为“ AVmk-ky6XMskTDwIwpih”。 响应: 这

  • TF-IDF TF-IDF(Term Frequency and Inverse Document Frequency),是一种用于信息检索与数据挖掘的常用加权技术。它的主要思想是:如果某个词或短语在一篇文章中出现的频率(term frequency)高,并且在其他文章中很少出现,则认为此词或者短语具有很好的类别区分能力,适合用来分类。 计算公式是TF * IDF 而这里的: scikit-lea

  • 问题内容: 我正在研究Elasticsearch 7.2版,并且正在 改善 应用程序发出的ES调用的性能。 根据我的阅读,如果我们尚未设置“搜索分析器”,则默认情况下将设置标准分析器。 但是,在不需要分析仪的情况下,安装分析仪可能会影响性能。是否将所有字段都用作“关键字”可以防止这种情况? 还是有其他方法可以禁用此“搜索分析器” 附言:对于任何答案,如果您能指出我基于答案的ES官方文档,我将不胜感