问题描述
我正在尝试在这个查询上建立一点点。我正在搜索的索引还有一个带有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
}
使用条款
而不是术语
。
{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, ... ] }}
这篇关于在弹性搜索中使用一个值的属性上的多个值进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!