我有一個查詢,我正在ElasticSearch中掙扎。事實上,我有兩個疑問,第一個作品,但第二個沒有。ElasticSearch嵌套[AND OR]篩選器
這裏的基礎知識第一次查詢,這是很好的(查詢實際上比這更大的不少,我已經剝離下來,爲了便於理解):
{
"query": {
"filtered": {
"query": {
"match_all":{}
},
"filter": {
"and": [{
"term":{
"relatedID":"214"
}
},
{
"term":{
"relatedType":"deal"
}
}]
}
}
}
}
所以基本上,抓住所有的項目其中relatedID == 214 & & relatedType == 「交易」
不過,我也想這樣做,是這樣的:
{
"query": {
"filtered": {
"query": {
"match_all":{}
},
"filter": {
"and": [{
{
"or":[{
"and":[{
"relatedID":"528"
},
{
"relatedType":"company"
}]
},{
"and":[{
"relatedID":"214"
},
{
"relatedType":"deal"
}
]}
]}
]}
}
}
}
}
}
}
小號o基本上,抓住一切交易AND 214,或公司AND 528.
這是我似乎陷入困境。
正如我所說的,有一個在查詢了很多(見下文完整的查詢,這可能有助於理解爲什麼我試圖構建它上面):
{
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"and":[
{
"or":[
{
"term":{
"timeSensitive":false
}
}
,
{
"range":{
"validTo":{
"gt":"20140513T153030Z"
},
"validFrom":{
"lt":"20140513T153030Z"
}
}
}
]
}
,
{
"term":{
"categoryTree.NAME":"Promotions"
}
}
,
{
"or":[
{
"and":[
{
"relatedID":"528"
}
,
{
"relatedType":"company"
}
]
}
,
{
"and":[
{
"relatedID":"214"
}
,
{
"relatedType":"deal"
}
]
}
]
}
,
{
"terms":{
"permissions": ["member","supplier"]
}
}
,
{
"term":{
"siteID":6
}
}
]
}
}
}
}
}
}
你知道'bool'濾波器是由ES文件建議,而不是'和'和'或'過濾器? –