我想使用来自elasticSearch 的上下文建议器,但是我的建议结果需要匹配2个上下文值。
从文档扩展示例,我想做类似的事情:
POST place/_search?pretty
{
"suggest": {
"place_suggestion" : {
"prefix" : "tim",
"completion" : {
"field" : "suggest",
"size": 10,
"contexts": {
"place_type": [ "cafe", "restaurants" ],
"rating": ["good"]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想获得的结果的place_type的上下文为“ cafe”或“ restaurant”,而评分的上下文为“ good”。
当我尝试类似的操作时,elastic对上下文执行“或”操作,并为我提供上下文“ cafe”,“餐厅”或“ good”的所有建议。
我能以某种方式指定组合多个上下文需要使用哪种BOOL运算符elastic吗?
从 Elasticsearch 5.x 开始,似乎不再支持此功能: https://github.com/elastic/elasticsearch/issues/21291#issuecomment-375690371
最好的选择是创建一个composite context,这似乎是 Elasticsearch 2.x 在查询中实现多个上下文的方式:
https://github.com/elastic/elasticsearch/pull/26407#issuecomment-326771608
为此,我想您的映射中需要一个新字段。我们称它为cat-rating:
PUT place
{
"mappings": {
"properties": {
"suggest": {
"type": "completion",
"contexts": [
{
"name": "place_type-rating",
"type": "category",
"path": "cat-rating"
}
]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当您为新文档建立索引时,您需要将字段连接place_type在一起rating,并用-,分隔cat-rating字段。完成后,您的查询将需要如下所示:
POST place/_search?pretty
{
"suggest": {
"place_suggestion": {
"prefix": "tim",
"completion": {
"field": "suggest",
"size": 10,
"contexts": {
"place_type-rating": [
{
"context": "cafe-good"
},
{
"context": "restaurant-good"
}
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这将返回好的咖啡馆或好的餐馆的建议。
| 归档时间: |
|
| 查看次数: |
323 次 |
| 最近记录: |