我试图从多字段中获取建议。我无法找到这样的例子,所以也许这不是最好的主意,但我对你的意见感兴趣。
映射:
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" } } }
要求是:
任何想法如何实现这些目标?
答案 0 :(得分:3)
首先,建议者在多领域不能很好地工作,所以你可能想把它放在外面。 其次,为了使您使用名称和名字进行查询工作,您必须在发布数据时选择输出/输入。
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。