ElasticSearch:尝试获取正确名称的拼写建议

时间:2015-04-11 23:25:01

标签: elasticsearch tokenize analyzer search-suggestion

在开始之前,我要说的是我没有ElasticSearch专家,但我目前的任务是调整一些分析器以使拼写建议在几种不同的情况下更好地工作。我已经看过有关正确姓名的拼写建议的人的例子,所以我知道这一定是可能的,但我已经在这几天了,而且我必须遗漏一些东西,因为ElasticSearch似乎没有认出我正在寻找的名字。能帮我解决这个问题吗?提前谢谢!

这是我用于索引和搜索的分析器:

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

这应该证明该字段正在标记为一个我想要的长关键字。

{
    "query": {
       "match": {
           "_all": "combine 5"
       }
    },
    "script_fields": {
        "terms" : {
            "script": "doc[field].values",
            "params": {
                "field": "my_field"
            }
        }
    }
}

...并输出类似这样的内容,显示字段是如何被标记化的。看起来不错:

"took": 7,
"timed_out": false,
"_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
},
"hits": {
    "total": 75,
    "max_score": 0.58574116,
    "hits": [
        {
            "_index": "my_index",
            "_type": "thing",
            "_id": "1",
            "_score": 0.58574116,
            "fields": {
                "terms": [
                    [
                        "combine 5"
                    ]
                ]
            }
        }
    }
}

...但是当我做一个建议查询时,它并不建议该字段,即使它只是一个空格。

{
  "query": {
     "match": {
         "_all": "combine 5"
     }
  },
  "suggest": {
    "suggest-0": {
      "term": {
        "field": "_all",
        "size": 5
      },
      "text": "combine5"
    }
  }
}

返回了一堆文件和这个建议:

"suggest": {
    "suggest-0": [
        {
            "text": "combine5",
            "offset": 0,
            "length": 8,
            "options": [
                {
                    "text": "combined",
                    "score": 0.875,
                    "freq": 15
                },
                {
                    "text": "combine",
                    "score": 0.85714287,
                    "freq": 17
                }
            ]
        }
    ]
}

请注意,如果我将拼写建议更改为仅包含文本的字段,则会建议它,但不是在我使用_all时。在建议反对_all?

时,有没有办法让特定字段中的字词显示出来?

1 个答案:

答案 0 :(得分:0)

我不确定这是否符合我要求的答案,但我最终通过在文档中添加一个包含我正在寻找“combine5”的关键字值的字段来解决这个问题,所以现在它已经注册了作为一个单词,如果我在该字段上建议,或_all,建议使用该单词。在针对_all的查询中也可以找到它。