弹性搜索匹配列表 [英] Elasticsearch match list against field

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

问题描述

我有一个列表,数组或者你熟悉的语言。例如。名称: [John,Bas,Peter] ,我想查询名称它匹配其中一个名称。



一种方法是使用OR Filter。例如

  {
filtered:{
query:{
match_all :{}
},
过滤器:{
或:[
{
term:{name:John}
},
{
term:{name:Bas}
},
{
term:{name :彼得}
}
]
}
}
}

任何鸽友的方式?

解决方案

  {
查询:{
filtered:{
filter:{
terms:{
name:[John,Bas,Peter ]
}
}
}
}
}

哪个弹性搜索重写,就好像你使用这个帽子一样

  {
query:{
filtered:{
filter:{
bool:{
should:[
{
term:{
name:John
}
},
{
term:{
name:Bas
}
},
{
term:{
name:Peter
}
}
]
}
}
}
}
}

当使用布尔过滤器时,大多数情况下,使用 bool 过滤器比。原因在Elasticsearch博客中解释: http://www.elasticsearch.org/blog/ all-about-elasticsearch-filter-bitsets /


I have a list, array or whichever language you are familiar. E.g. names : ["John","Bas","Peter"] and I want to query the name field if it matches one of those names.

One way is with OR Filter. e.g.

{
    "filtered" : {
        "query" : {
            "match_all": {}
        },
        "filter" : {
            "or" : [
                {
                    "term" : { "name" : "John" }
                },
                {
                    "term" : { "name" : "Bas" }
                },
                {
                    "term" : { "name" : "Peter" }
                }
            ]
        }
    }
}

Any fancier way? Better if it's a query than a filter.

解决方案

{
  "query": {
    "filtered" : {
      "filter" : {
        "terms": {
          "name": ["John","Bas","Peter"]
        }
      }
    }
  }
}

Which Elasticsearch rewrites as if you hat used this one

{
  "query": {
    "filtered" : {
      "filter" : {
        "bool": {
          "should": [
            {
              "term": {
                "name": "John"
              }
            },
            {
              "term": {
                "name": "Bas"
              }
            },
            {
              "term": {
                "name": "Peter"
              }
            }
          ]
        }
      }
    }
  }
}

When using a boolean filter, most of the time, it is better to use the bool filter than and or or. The reason is explained on the Elasticsearch blog: http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/

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

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