我正在嘗試使用elasticsearch
執行過濾器,並且得到一個我看起來無法更正的語法錯誤。我已經測試過各個班級,而且他們似乎工作得很好。我究竟做錯了什麼?elasticsearch使用'and'和'or'的過濾器語法錯誤
這裏的意圖是找到滿足三個同時條件的文檔:(field1 == VAL1)
,(field2 == VAL2)
和((field3 == VAL3) || (field3 == VAL4))
。
我得到的信息是:
「嵌套:QueryParsingException [[ⅩⅩⅩⅩ]解析失敗];嵌套: JsonParseException [意外字符( ':'(代碼58)):期待 逗號到單獨的數組項的\ n在[來源:[B @ 1acfee60;線:13, 柱:26]];}] 「 」狀態「:400}」
由於
curl -XGET 'localhost:9200/xxxx/yyyy/_search' -d '
{
"query":
{
"filtered":
{
"filter":
{
"and":
[
{ "term": { "field1":"VAL1" } },
{ "term": { "field2":"VAL2" } },
"or":
[
{ "term": { "field3":"VAL3" } },
{ "term": { "field3":"VAL4" } }
]
]
}
}
}
}
'
!
感謝Paige Cook,現在語法錯誤消失了(見下文)。但是過濾器仍然與文檔不匹配。我已經分別測試了「和」條款和「或」條款,它們都起作用。我很困惑。
curl -XGET 'localhost:9200/xxxx/users/_search' -d '
{
"query":
{
"filtered":
{
"filter":
{
"and":
[
{ "term": { "field1":"VAL1" } },
{ "term": { "field2":"VAL2" } }
],
"or":
[
{ "term": { "field3":"VAL3" } },
{ "term": { "field3":"VAL4" } }
]
}
}
}
}
'
非常感謝Geert-Jan。最後一個工作的例子是:
curl -XGET 'localhost:9200/xxxx/yyyy/_search' -d '
{
"query":
{
"filtered":
{
"filter":
{
"and":
[
{ "term": { "field1":"VAL1" } },
{ "term": { "field2":"VAL2" } },
{
"or":
[
{ "term": { "field3":"VAL3" } },
{ "term": { "field3":"VAL4" } }
]
}
]
}
}
}
}
'
耶!那樣做了。非常感謝Geert-Jan! –