我使用 elasticsearch 搜索来检索一些文档,我想做一个简单的语句,例如:
if ((a == "1" || b == "2") || (c == "3" && d == "4"))
我使用第一个语句((a == "1" || b == "2"))
$filter ['bool'] ['must'] [] = array (
'bool' => array (
'should' => array (
array (
'terms' => array (
'a' => $aName
)
),
array (
'terms' => array (
'b' => $bName
)
),
),
)
);
但是在我迷路之后。我不知道如何添加:
(c == "3" && d == "4")
看看嵌套布尔过滤器。对于您的情况,我相信这样的事情会起作用:
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"term": {
"a": 1
}
},
{
"bool": {
"must": {
"term": {
"b": 2
}
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"c": 3
}
},
{
"term": {
"d": 4
}
}
]
}
}
]
}
}
}
}
}
从这里开始将其转换回php应该很容易。