我正在使用上下文建议器,我想知道我们是否可以设置上下文的范围用于建议而不是使用所有上下文.
目前,查询需要匹配所有上下文.我们可以在上下文中添加"OR"操作和/或指定用于特定查询的上下文吗?
以这里为例:映射:
PUT /venues/poi/_mapping
{
"poi" : {
"properties" : {
"suggest_field": {
"type": "completion",
"context": {
"type": {
"type": "category"
},
"location": {
"type": "geo",
"precision" : "500m"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我索引一个文件:
{
"suggest_field": {
"input": ["The Shed", "shed"],
"output" : "The Shed - fresh sea food",
"context": {
"location": {
"lat": 51.9481442,
"lon": -5.1817516
},
"type" : "restaurant"
}
}
}
Run Code Online (Sandbox Code Playgroud)
查询:
{
"suggest" : {
"text" : "s",
"completion" : {
"field" : "suggest_field",
"context": {
"location": {
"value": {
"lat": 51.938119,
"lon": -5.174051
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我只使用一个Context(上例中的"location")查询它会给出错误,我需要传递两个上下文,是否可以指定使用哪个上下文?或者将"Context_Operation"参数设置为"OR".
你有2个选择:
首先,将所有可用类型值添加为映射中的默认值(不可扩展)
{
"poi" : {
"properties" : {
"suggest_field": {
"type": "completion",
"context": {
"type": {
"type": "category",
"default": ["restaurant", "pool", "..."]
},
"location": {
"type": "geo",
"precision" : "500m"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
第二个选项,您向每个索引文档添加默认值,并且仅添加该值作为默认值
映射:
{
"poi" : {
"properties" : {
"suggest_field": {
"type": "completion",
"context": {
"type": {
"type": "category",
"default": "any"
},
"location": {
"type": "geo",
"precision" : "500m"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
文档:
{
"suggest_field": {
"input": ["The Shed", "shed"],
"output" : "The Shed - fresh sea food",
"context": {
"location": {
"lat": 51.9481442,
"lon": -5.1817516
},
"type" : ["any", "restaurant"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1321 次 |
| 最近记录: |