【发布时间】:2015-04-11 23:25:01
【问题描述】:
在开始之前,让我先声明一下,我不是 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 时,有没有办法让特定字段中的单词被建议?
【问题讨论】:
标签: elasticsearch tokenize analyzer search-suggestion