我正在尝试从多领域获得建议。我找不到这样的示例,所以这可能不是最好的主意,但我对您的意见很感兴趣。
映射:
POST /authors { "mappings": { "author": { "properties": { "name": { "type": "multi_field", "fields": { "name": { "type": "string", "index": "analyzed" }, "ac": { "type": "completion", "index_analyzer": "simple", "search_analyzer": "simple", "payloads": true } } } } } } }
数据:
POST /authors/author/1 { "name": "Fyodor Dostoevsky" }
查询:
POST /authors/_suggest { "authorsAutocomplete": { "text": "fyodor", "completion": { "field": "name.ac" } } }
要求是:
- get 查询适用于文本“fyodor”,也适用于“dostoevsky”,此示例仅适用于“fyodor”
- 能够过滤建议
有什么想法可以实现这些吗?
最佳答案
首先,suggesters 在多领域效果不佳,所以你可能想把它放在外面。 其次,要让您同时使用名字和名字进行查询,您必须在索引数据时选择输出/输入。
SENSE 的工作代码示例:
POST authors
PUT authors/_mapping/author
{
"properties" : {
"name" : { "type" : "string" },
"suggest" : { "type" : "completion"}
}
}
POST authors/author/1
{
"name": "Fyodor Dostoevsky",
"suggest": {
"input": ["Dostoevsky", "Fyodor"],
"output": "Fyodor Dostoevsky"
}
}
POST authors/_suggest
{
"authorsAutocomplete": {
"text": "d",
"completion": {
"field": "suggest"
}
}
}
DELETE authors
结果:
{
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"authorsAutocomplete": [
{
"text": "d",
"offset": 0,
"length": 1,
"options": [
{
"text": "Fyodor Dostoevsky",
"score": 1
}
]
}
]
}
过滤器不适用于建议。要实现某种过滤,你可以看看这个 blog post关于在建议中使用上下文。
关于elasticsearch completion suggest on multifield,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25932669/