【问题标题】:Prevent Keyword Stuffing Elasticsearch防止关键字填充 Elasticsearch
【发布时间】:2020-01-20 19:14:00
【问题描述】:

我使用的是 ES 7.3。我有一个包含标题、部件、型号等的产品索引。我遇到了关键字填充问题,因为某些产品可能在整个文档中多次包含相同的单词、部件或型号。

例如,型号可能在标题中出现两次,在型号字段中也可能出现。某些产品可能仅在标题中包含型号而不在型号字段中包含。由于该问题,这些产品难以排名。如何防止这种类型的关键字填充?这是我的代码。

字段:

fields = [
          'name^10','name.ngram',
          'part_number^10',


          'mod_name^5', 

          'model_number^5', 

          'brand^10',
          'category^5',
          'product_type^5',
          'search_variations^1'                  
         ]  

fuzzy_fields = [
         'name',
          'part_number',
          'mod_name', 
          'model_number', 
          'brand',
          'category',
          'product_type',
          'search_variations'                  
         ]

查询:

{
         explain: true,
         query:{
           function_score: { 
              "query": {
                "bool": {
                  "should": 
                    [{
                      multi_match:{
                         fields: fields,
                         type: "most_fields", 
                         query: "#{query}"
                       }
                    },
                    {
                      multi_match:{
                         fields: fuzzy_fields,
                         type: "most_fields", 
                         fuzziness: "AUTO",
                         query: "#{query}"
                       }
                    }],
                  "filter": {
                    "bool": { 
                      "must": filters
                    }
                  }
               }
             },field_value_factor:{
                    field: "popularity",
                    modifier: "log1p",
                    factor: 5

                 },
                 boost_mode: "sum"
             }
       },highlight: {
            fields: {
              :"*" => {}
            }
          },
        aggs: {categories: { terms: { field: "category.raw"} }} 

      }

更新

unique 过滤器添加到我的映射中确实可以防止在同一字段上匹配重复值,但不会跨越多个字段,这是我需要的。

【问题讨论】:

    标签: elasticsearch elasticsearch-rails


    【解决方案1】:

    我认为您在查询中想要的是option best_fields on the multi_match query

    best_fields 类型使用单个最佳匹配字段的得分

    所以只有最好的字段才算数,如果某些文档在多个字段中匹配,则不会影响分数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 2013-06-02
      • 2011-07-07
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      相关资源
      最近更新 更多