Skip to content

Commit

Permalink
Merge pull request #194 from Ixolit/fix_es_query_filters
Browse files Browse the repository at this point in the history
fixed filters when multiple filters are applied eg. date range and query string
  • Loading branch information
kiwiz authored Nov 7, 2018
2 parents 2009b42 + 9e84ce2 commit 2a94cbb
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions phplib/ESClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,13 @@ private function query($query, $fields=null, $from=null, $to=null, $scroll=false
$conds['lt'] = $to;
}
if(count($conds) > 0) {
$filter = [
$filter[] = [
'range' => [ 'alert_date' => $conds ]
];
}
$filter['query_string'] = [ 'query' => $query ];
$filter[] = [
'query_string' => [ 'query' => $query ]
];

$body = [
'query' => [
Expand Down Expand Up @@ -270,11 +272,11 @@ public function bootstrap($query, $from=null, $to=null) {
$conds['lt'] = $to;
}
if(count($conds) > 0) {
$filter = [
$filter[] = [
'range' => [ 'alert_date' => $conds ]
];
}
$filter['query_string'] = [ 'query' => $query ];
$filter[] = ['query_string' => ['query' => $query]];

try {
$data = $client->search([
Expand Down Expand Up @@ -326,8 +328,10 @@ public function getActiveAlertCounts() {
$client = self::getClient();

$filter = [
'terms' => [
'state' => [Alert::ST_NEW, Alert::ST_INPROG]
[
'terms' => [
'state' => [Alert::ST_NEW, Alert::ST_INPROG]
]
]
];
$aggs = [
Expand Down Expand Up @@ -412,19 +416,20 @@ public function getAlertActivityCounts($range, $search_id=0) {
$client = self::getClient();

$filter = [
'range' => [
'create_date' => [
'lt' => 'now',
'gte' => sprintf('now-%dd/d', $range)
[
'range' => [
'create_date' => [
'lt' => 'now',
'gte' => sprintf('now-%dd/d', $range)
]
]
]
];
if($search_id != 0) {
$filter = [
$filter,
['term' => [
$filter[] = [
'term' => [
'search_id' => $search_id
]]
]
];
}
$aggs = ['agg' => [
Expand Down Expand Up @@ -597,3 +602,4 @@ public function unflatten(array $data) {
return $ret;
}
}

0 comments on commit 2a94cbb

Please sign in to comment.