【问题标题】:Highlight part of word with ngram and whitespace analyzers使用 ngram 和空白分析器突出显示部分单词
【发布时间】:2016-12-08 10:12:30
【问题描述】:

我有一个包含以下数据的弹性搜索索引:

“A-Team”(例如)

我的索引设置是:

"index": {
    "number_of_shards": "1",
    "provided_name": "tyh.tochniyot",
    "creation_date": "1481039136127",
    "analysis": {
      "analyzer": {
        "whitespace_analyzer": {
          "type": "whitespace"
        },
        "ngram_analyzer": {
          "type": "custom",
          "tokenizer": "ngram_tokenizer"
        }
      },
      "tokenizer": {
        "ngram_tokenizer": {
          "type": "ngram",
          "min_gram": "3",
          "max_gram": "7"
        }
      }
    },

当我搜索:

_search
{
"from": 0,
"size": 20,
"track_scores": true,
"highlight": {
  "fields": {
    "*": {
      "fragment_size": 100,
      "number_of_fragments": 10,
      "require_field_match": false
    }
  }
},
"query": {
  "match": {
    "_all": {
      "query": "Tea"
    }
  }
}

我希望得到高亮结果:

    "highlight": {
      "field": [
        "The A-<em>Tea</em>m"
      ]
}

但我根本没有得到任何亮点。

我使用空格进行搜索并使用 ngram 进行索引的原因是我不想在搜索阶段破坏我正在搜索的单词,就像如果我正在搜索“Team”它会找到我“Tea”、“eam” ","团队"

谢谢

【问题讨论】:

    标签: elasticsearch n-gram elasticsearch-net elasticsearch-5


    【解决方案1】:

    问题是我的分析器和搜索分析器在 _all 文件上运行。 当我将 Analyzer 属性放在特定字段上时,Highlight 开始工作。

    【讨论】:

      猜你喜欢
      • 2013-07-31
      • 2013-06-29
      • 2016-02-20
      • 2014-08-13
      • 2017-06-07
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 2017-10-27
      相关资源
      最近更新 更多