【问题标题】:Elasticsearch context suggester, bool on contextsElasticsearch 上下文建议器,基于上下文的布尔值
【发布时间】:2015-04-24 08:34:59
【问题描述】:

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

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

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”。

【问题讨论】:

  • 是否可以像这样对类别进行索引:[any, restaurant](“any”将默认包含在所有索引文档中)并且当您执行查询时,将“any”作为类别传递+“位置”?

标签: elasticsearch


【解决方案1】:

你有两个选择:

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

{
  "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"]
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 2016-10-03
    相关资源
    最近更新 更多