如何生成多字搜索建议

时间:2016-04-30 18:50:12

标签: elasticsearch match-phrase

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

我主要得到单词建议,但当我点击空格键时 - 它会杀死建议。

例如,如果我键入" fast"如果我键入" fast"它可以正常工作 - 停止出现建议。

我正在使用Edge N Gramsmatch_phrase_prefix,并按照示例herehere来构建它。对于_all中的match_phrase_prefix字段,只使用了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"
      ]

1 个答案:

答案 0 :(得分:0)

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

curl 'localhost:9200/test/_analyze?pretty=1&analyzer=my_edge_ngram_analyzer' -d 'FC Schalke 04'

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

默认情况下,它的标准分析器会在空格上分割 您可以查看{{1}}参考https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenizer.html

等令牌
相关问题