首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch context suggester,bool on context

Elasticsearch context suggester,bool on context
EN

Stack Overflow用户
提问于 2015-04-24 16:35:00
回答 1查看 1.9K关注 0票数 8

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

目前,查询需要匹配所有上下文。我们可以在上下文上添加"OR“操作和/或指定用于特定查询的上下文吗?

here:Mapping中的示例为例:

代码语言:javascript
复制
PUT /venues/poi/_mapping
{
  "poi" : {
    "properties" : {
      "suggest_field": {
        "type": "completion",
        "context": {
          "type": { 
            "type": "category"
          },        
          "location": { 
            "type": "geo",
            "precision" : "500m"
          }
        }
      }
    }
  }
}

然后我索引一个文档:

代码语言:javascript
复制
 {
  "suggest_field": {
    "input": ["The Shed", "shed"],
    "output" : "The Shed - fresh sea food",
    "context": {
      "location": {
        "lat": 51.9481442,
        "lon": -5.1817516
      },      
      "type" : "restaurant"
    }
  }
}

查询:

代码语言:javascript
复制
{
  "suggest" : {
    "text" : "s",
    "completion" : {
      "field" : "suggest_field",
      "context": {
        "location": {
          "value": {
            "lat": 51.938119,
            "lon": -5.174051
          }
        }
      }
    }
  }
}

如果我只使用一个上下文(上面例子中的“location”)进行查询,它会给出一个错误,我需要传递两个上下文,是否可以指定使用哪个上下文?或者传递类似于设置为" Or“的"Context_Operation”参数。

EN

回答 1

Stack Overflow用户

发布于 2015-05-22 00:33:00

您有两个选择:

首先,在映射中添加所有可用的类型值作为默认值(不可伸缩)

代码语言:javascript
复制
{
  "poi" : {
    "properties" : {
      "suggest_field": {
        "type": "completion",
        "context": {
          "type": { 
            "type": "category",
            "default": ["restaurant", "pool", "..."]
          },        
          "location": { 
            "type": "geo",
            "precision" : "500m"
          }
        }
      }
    }
  }
}

第二种选择是,向每个索引文档添加一个默认值,然后仅将该值添加为默认值

映射:

代码语言:javascript
复制
{
  "poi" : {
    "properties" : {
      "suggest_field": {
        "type": "completion",
        "context": {
          "type": { 
            "type": "category",
            "default": "any"
          },        
          "location": { 
            "type": "geo",
            "precision" : "500m"
          }
        }
      }
    }
  }
}

文档:

代码语言:javascript
复制
{
  "suggest_field": {
    "input": ["The Shed", "shed"],
    "output" : "The Shed - fresh sea food",
    "context": {
      "location": {
        "lat": 51.9481442,
        "lon": -5.1817516
      },      
      "type" : ["any", "restaurant"]
    }
  }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29842492

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档