我正在使用context suggester,我想知道我们是否可以设置用于建议的上下文的范围,而不是使用所有上下文。
目前,查询需要匹配所有上下文。我们可以在上下文上添加"OR“操作和/或指定用于特定查询的上下文吗?
以here:Mapping中的示例为例:
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
}
}
}
}
}
}如果我只使用一个上下文(上面例子中的“location”)进行查询,它会给出一个错误,我需要传递两个上下文,是否可以指定使用哪个上下文?或者传递类似于设置为" Or“的"Context_Operation”参数。
发布于 2015-05-22 00:33:00
您有两个选择:
首先,在映射中添加所有可用的类型值作为默认值(不可伸缩)
{
"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"]
}
}
}https://stackoverflow.com/questions/29842492
复制相似问题