gpt4 book ai didi

Elasticsearch context suggester,bool on contexts

转载 作者:行者123 更新时间:2023-11-29 02:46:53 28 4
gpt4 key购买 nike

我正在使用上下文建议器,我想知道我们是否可以设置用于建议的上下文范围,而不是使用所有上下文。

目前查询需要匹配所有上下文。我们能否在上下文中添加“或”运算和/或指定用于特定查询的上下文?

here为例:映射:

PUT /venues/poi/_mapping
{
"poi" : {
"properties" : {
"suggest_field": {
"type": "completion",
"context": {
"type": {
"type": "category"
},
"location": {
"type": "geo",
"precision" : "500m"
}
}
}
}
}
}

然后我索引一个文档:

 {
"suggest_field": {
"input": ["The Shed", "shed"],
"output" : "The Shed - fresh sea food",
"context": {
"location": {
"lat": 51.9481442,
"lon": -5.1817516
},
"type" : "restaurant"
}
}
}

查询:

{
"suggest" : {
"text" : "s",
"completion" : {
"field" : "suggest_field",
"context": {
"location": {
"value": {
"lat": 51.938119,
"lon": -5.174051
}
}
}
}
}
}

如果我只使用一个上下文(上例中的“位置”)进行查询,则会出错,我需要传递两个上下文,是否可以指定使用哪个上下文?或者将类似“Context_Operation”的参数设置为“OR”。

最佳答案

你有两个选择:

首先,您将所有可用类型值添加为映射中的默认值(不可扩展)

{
"poi" : {
"properties" : {
"suggest_field": {
"type": "completion",
"context": {
"type": {
"type": "category",
"default": ["restaurant", "pool", "..."]
},
"location": {
"type": "geo",
"precision" : "500m"
}
}
}
}
}
}

第二个选项,你为每个索引文档添加一个默认值,并且你只添加这个值作为默认值

映射:

{
"poi" : {
"properties" : {
"suggest_field": {
"type": "completion",
"context": {
"type": {
"type": "category",
"default": "any"
},
"location": {
"type": "geo",
"precision" : "500m"
}
}
}
}
}
}

文档:

{
"suggest_field": {
"input": ["The Shed", "shed"],
"output" : "The Shed - fresh sea food",
"context": {
"location": {
"lat": 51.9481442,
"lon": -5.1817516
},
"type" : ["any", "restaurant"]
}
}
}

关于Elasticsearch context suggester,bool on contexts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29842492/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com