首页 > 解决方案 > 在弹性搜索中按权重过滤拼写建议结果

问题描述

首先,我使用以下映射索引了一些文档:

{
    "test_index": {
        "mappings": {
            "dynamic": "strict",
            "properties": {
                "content_completion": {
                    "type": "completion",
                    "analyzer": "hashtag_analyzer",
                    "preserve_separators": true,
                    "preserve_position_increments": true,
                    "max_input_length": 50,
                    "fields": {
                        "content": {
                            "type": "text",
                            "analyzer": "shingle_analyzer"
                        }
                    }
                }
            }
        }
    }
}

然后我使用以下方法在其中放入了一些文档:

    PUT test/_doc/1?refresh
{
 "content_completion" : {
  "input": "nobel",
  "weight" : 5
 },
 "content_completion" : {
  "input": "nobel marathon",
  "weight" : 5
 },
 "content_completion" : {
  "input": "nobel is good",
  "weight" : 5
 },
 "content_completion" : {
  "input": "nobel is life",
  "weight" : 5
 },
 "content_completion" : {
  "input": "no bei",
  "weight" : 1000000000
  }
 }

(索引中没有重复的文档。)我有以下拼写建议查询:

{
    "suggest": {
        "text": "nobei",
        "spell-checker-suggest": {
            "phrase": {
                "field": "content_completion.content",
                "gram_size": 2,
                "size": 10,
                "analyzer": "hashtag_analyzer",
                "real_word_error_likelihood": 0.95,
                "direct_generator": [
                        {
                        "field": "content_completion.content",
                        "min_doc_freq": "1",
                        "suggest_mode": "missing",
                        "prefix_length": 0,
                        "sort": "score",
                        "min_word_length": 2
                        }
                    ],
                "highlight": {
                    "pre_tag": "<em>",
                    "post_tag": "</em>"
                }
            }
        }
    }
}

并得到这样的结果:

   {
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "suggest": {
    "spell-checker-suggest_1": [
      {
        "text": "nobei",
        "offset": 0,
        "length": 5,
        "options": [
          {
            "text": "nobel",
            "highlighted": "<em>nobel</em>",
            "score": 0.45925426
          }
        ]
      }
    ]
  }
}

elsaticsearch 不使用权重进行评分,而只是应用频率。如果可能的话,我想要做以下其中一项:

标签: elasticsearch

解决方案


推荐阅读