弹性搜索上下文,在上下文中 [英] Elasticsearch context suggester, bool on contexts

查看:156
本文介绍了弹性搜索上下文,在上下文中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



此处
映射:

  PUT /场馆/ poi / _mapping 
{
poi:{
properties:{
suggest_field:{
type:completion,
context:{
type:{
type:category
},
位置:{
type:geo,
precision:500m
}
}
}
}
}
}

然后我索引一个文档:

  {
suggest_field:{
input:[The Shed,shed],
输出:The Shed - fresh sea food,
context:{
location:{
lat:51.9481442,
lon:-5.1817516
},
type:restaurant
}
}
}
/ pre>

查询:

  {
:{
text:s,
completion:{
field:suggest_field,
context:{
位置:{
value:{
lat:51.938119,
lon:-5.174051
}
}
}
}
}
}

如果我仅使用一个上下文查询位置在上面的例子中)它给出了一个错误,我需要通过两个上下文,是否可以指定使用哪个上下文?或者传递类似Context_Operation参数设置为OR的内容。

解决方案

您有两种选择:



首先在映射中添加所有可用的类型值(不可扩展)

  {
poi:{
properties:{
suggest_field:{
type:completion,
context b $ btype:{
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
}
}
}
}
}
}

文件: p>

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


I'm using context suggester and am wondering if we can set the scope of the context to be used for suggestions rather that using all contexts.

Currently the query needs to match all contexts. Can we add an "OR" operation on the contexts and/or specify which context to use for a particular query?

Taking the example from here : Mapping :

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

Then I index a document :

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

Query:

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

If I query using only one Context ("location" in the above example) it gives an error, I need to pass both the contexts, is it possible to specify which context to use? Or pass something like a "Context_Operation" parameter set to "OR".

解决方案

You have 2 choices:

First you add all available type values as default in your mapping (not scalable)

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

Second option, you add a default value to every indexed document, and you add only this value as default

Mapping:

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

Document:

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

这篇关于弹性搜索上下文,在上下文中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆