diff --git a/lib/logstorage/filter_and.go b/lib/logstorage/filter_and.go index 27a9125b0..5d46151db 100644 --- a/lib/logstorage/filter_and.go +++ b/lib/logstorage/filter_and.go @@ -27,8 +27,7 @@ func (fa *filterAnd) String() string { a := make([]string, len(filters)) for i, f := range filters { s := f.String() - switch f.(type) { - case *filterOr: + if _, ok := f.(*filterOr); ok { s = "(" + s + ")" } a[i] = s diff --git a/lib/logstorage/parser_test.go b/lib/logstorage/parser_test.go index e7e773a7d..f31d0b2e3 100644 --- a/lib/logstorage/parser_test.go +++ b/lib/logstorage/parser_test.go @@ -594,6 +594,10 @@ func TestParseQuerySuccess(t *testing.T) { f(`NOT foo AND bar OR baz`, `!foo bar or baz`) f(`NOT (foo AND bar) OR baz`, `!(foo bar) or baz`) f(`foo OR bar AND baz`, `foo or bar baz`) + f(`foo bar or baz xyz`, `foo bar or baz xyz`) + f(`foo (bar or baz) xyz`, `foo (bar or baz) xyz`) + f(`foo or bar baz or xyz`, `foo or bar baz or xyz`) + f(`(foo or bar) (baz or xyz)`, `(foo or bar) (baz or xyz)`) f(`(foo OR bar) AND baz`, `(foo or bar) baz`) // parens