【问题标题】:elasticsearch tf-idf and ignoring field length norm in searchelasticsearch tf-idf 并在搜索中忽略字段长度规范
【发布时间】:2016-07-14 05:46:31
【问题描述】:

我想在 elasticsearch 中执行搜索,忽略 tf-idf 搜索中的字段规范。您可以通过ignoring the field norms by setting the index mappings 完成此操作。但是,这似乎是通过更改索引来完成的,我只想修改搜索(我需要其他类型搜索的规范)。实现这一目标的最佳方法是什么?我使用 elasticsearch.js 作为我的弹性搜索接口。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您不能在每次搜索的基础上禁用规范,但您可以使用 Multi Fields API 添加一个额外的字段来禁用规范。

    PUT /my_index
    {
      "mappings": {
        "my_type": {
          "properties": {
            "my_field": {
              "type": "string",
              "fields": {
                "no_norms": { 
                  "type":  "string",
                  "norms": {
                    "enabled": false
                  }
                }
              }
            }
          }
        }
      }
    }
    

    现在,如果您需要规范,可以搜索 my_field,如果不需要,可以搜索 my_field.no_norms。您必须重新索引数据才能使新字段可用于所有文档,只需将其添加到映射不会更改现有文档的任何内容。

    【讨论】:

      【解决方案2】:

      这就是我最终使用的方法。我没有使用 tf-idf(当前的 elasticsearch 默认值),而是使用了 BM25,据说它更好。此外,它还有一个参数“b”,表示字段长度规范的重要性。对于“b=0”,字段长度规范被忽略,而默认值为 0.75。 BM25 的讨论可以在here 找到。在我的 elasticsearch.yml 我有

      index :
        similarity:
          default:
            type: BM25
            b: 0.0
            k1: 1.2
          norm_bm25:
            type: BM25
            b: 0.75
            k1: 1.2
      

      对于使用 elasticsearch javascript api 的用户,可以在创建索引时定义自定义相似度

      client.indices.create({
        index: "db",
        body: { 
              settings: { 
                number_of_shards: 1,
                similarity : "norm_bm25"
              } 
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-10-11
        • 1970-01-01
        • 1970-01-01
        • 2017-06-19
        • 1970-01-01
        • 1970-01-01
        • 2012-08-08
        • 1970-01-01
        相关资源
        最近更新 更多