【发布时间】:2018-01-13 03:44:19
【问题描述】:
我们正在使用 ElasticSearch completion suggester 和 Standard Analyzer,但似乎文本没有被标记。
例如
文本:“第一个示例”、“第二个示例”
搜索:“Fi”返回“第一个示例”
虽然
搜索:“Ex”不返回任何结果返回“First Example”
【问题讨论】:
标签: elasticsearch autocomplete autosuggest
我们正在使用 ElasticSearch completion suggester 和 Standard Analyzer,但似乎文本没有被标记。
例如
文本:“第一个示例”、“第二个示例”
搜索:“Fi”返回“第一个示例”
虽然
搜索:“Ex”不返回任何结果返回“First Example”
【问题讨论】:
标签: elasticsearch autocomplete autosuggest
作为 Elastic 关于完成建议的文档:Completion Suggester
补全提示器就是所谓的前缀提示器。
因此,当您发送关键字时,它会查找您的文本的前缀。
例如:
搜索:“Fi”=>“第一个示例”
搜索:“秒”=>“第二个例子”
但如果你给 Elastic “Ex”,它不会返回任何内容,因为它找不到以“Ex”开头的文本。
您可以尝试其他一些建议,例如:Term Suggester
【讨论】:
一个很好的解决方法是自己标记字符串并将其放在单独的标记字段中。 然后,您可以在建议查询中使用 2 条建议来搜索这两个字段。
示例:
PUT /example
{
"mappings": {
"doc": {
"properties": {
"full": {
"type": "completion"
},
"tokens": {
"type": "completion"
}
}
}
}
}
POST /example/doc/_bulk
{ "index":{} }
{"full": {"input": "First Example"}, "tokens": {"input": ["First", "Example"]}}
{ "index":{} }
{"full": {"input": "Second Example"}, "tokens": {"input": ["Second", "Example"]}}
POST /example/_search
{
"suggest": {
"full-suggestion": {
"prefix" : "Ex",
"completion" : {
"field" : "full",
"fuzzy": true
}
},
"token-suggestion": {
"prefix": "Ex",
"completion" : {
"field" : "tokens",
"fuzzy": true
}
}
}
}
搜索结果:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": 0,
"hits": []
},
"suggest": {
"full-suggestion": [
{
"text": "Ex",
"offset": 0,
"length": 2,
"options": []
}
],
"token-suggestion": [
{
"text": "Ex",
"offset": 0,
"length": 2,
"options": [
{
"text": "Example",
"_index": "example",
"_type": "doc",
"_id": "Ikvk62ABd4o_n4U8G5yF",
"_score": 2,
"_source": {
"full": {
"input": "First Example"
},
"tokens": {
"input": [
"First",
"Example"
]
}
}
},
{
"text": "Example",
"_index": "example",
"_type": "doc",
"_id": "I0vk62ABd4o_n4U8G5yF",
"_score": 2,
"_source": {
"full": {
"input": "Second Example"
},
"tokens": {
"input": [
"Second",
"Example"
]
}
}
}
]
}
]
}
}
【讨论】: