在弹性搜索中使用一个值的属性上的多个值进行查询 [英] Query with multiple values on a property with one value in Elasticsearch

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

问题描述

我正在尝试在这个查询上建立一点点。我正在搜索的索引还有一个带有id的字段entity。所以一些记录将有实体:16,实体156等,这取决于实体的id。我需要以这样一种方式扩展这个查询:我可以传递一个数组或一些值列表,例如{:term => {:entity => [1,16,100]}},并获得有这些整数之一作为其实体值。到目前为止,还没有任何运气,有人可以帮助我吗?

  {
query:{

bool:{
must:[
{
term:{user_type:alpha}
},
{
term:{area:16}
}
],
must_not:[],
should :[]
}
},
过滤器:{
或:[{
和:[
{term :{area:16}},
{term:{date:05072013​​}}
]
},{
:[
{term:{area:16}},
{term:{date:blank}}
]
}


]
},
from:0,
size:100
}


解决方案

使用条款而不是术语



https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html



{terms:{entity:[123,1234,...]}}


I am trying to build on this query a little bit. The index I am searching also has a field "entity" with an id. So a few records will have "entity" : 16, "entity" 156 etc, depending on the id of the entity. I need to expand this query in such a way that I can pass an array or some list of values in, such as {:term => {:entity => [1, 16, 100]}} and get back records that have one of these integers as their entity value. I haven't had any luck so far, can someone help me?

{ 
  "query" : {

    "bool" : {
      "must" : [
        {
          "term" : {"user_type" : "alpha"}
        }, 
        { 
          "term" :{"area" : "16"}
        }
      ], 
      "must_not" : [], 
      "should" :   []
    }
  }, 
  "filter": {
    "or" : [{
       "and" : [
          { "term" : { "area" : "16" } },
          { "term" : { "date" : "05072013" } }
       ]
    }, {
       "and" : [
          { "term" : { "area" : "16" } },
          { "term" : { "date" : "blank" } }
       ]
    }


    ]
  },
"from" : 0,
"size" : 100 
}

解决方案

Use "terms" instead of "term".

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html

{ "terms" : { "entity" : [ 123, 1234, ... ] }}

这篇关于在弹性搜索中使用一个值的属性上的多个值进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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