【问题标题】:How to generate multi-word search suggestions如何生成多词搜索建议
【发布时间】:2016-04-30 18:50:12
【问题描述】:

我正在使用 Elasticsearch 构建一个小型搜索应用程序,并试图弄清楚如何使用多词(短语)建议构建一个自动完成功能。我有它的工作......有点......

我收到的主要是单个单词的建议,但是当我点击空格键时 - 它会取消建议。

例如,如果我输入“fast”,它可以正常工作,如果我输入“fast” - 这会阻止建议出现。

我正在使用 Edge N Gramsmatch_phrase_prefix 并按照示例 herehere 进行构建。对于match_phrase_prefix 中的_all 字段,仅使用 include_in_all: false 取消除标题和内容之外的所有字段。我开始认为这只是因为我正在对一个小数据集进行测试,并且根本没有足够的标记化术语来产生多词建议。请查看下面的相关代码并告诉我哪里出错了,如果有的话?

"analysis": {
"filter": {
 "autocomplete_filter": {
  "type": "edge_ngram",
  "min_gram": "1",
  "max_gram": "20",
  "token_chars": [
    "letter",
    "digit"
  ]
 }
},
"analyzer": {
  "autocomplete": {
    "type": "custom",
    "tokenizer": "whitespace",
    "filter": [
       "lowercase",
       "asciifolding",
       "autocomplete_filter"
    ]     
  },
  "whitespace_analyzer": {
    "type": "custom",
    "tokenizer": "whitespace",
    "filter": [
      "lowercase",
      "asciifolding"
      ]

【问题讨论】:

    标签: elasticsearch match-phrase


    【解决方案1】:

    试试keyword分词器

    "autocomplete": {
        "type": "custom",
               "filter": [
           "lowercase",
           "asciifolding",
           "autocomplete_filter"
        ],
     "tokenizer": "keyword"     
      }
    

    供参考 elasticsearch mapping tokenizer keyword to avoid splitting tokens and enable use of wildcard

    因为默认情况下它的标准分析器会在空格上拆分 您可以检查您的令牌,例如 curl 'localhost:9200/test/_analyze?pretty=1&analyzer=my_edge_ngram_analyzer' -d 'FC Schalke 04' 参考 https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenizer.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-04
      • 2011-11-10
      • 1970-01-01
      • 2012-08-19
      • 2019-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多