Skip to content

Fix filter clicks on array-valued JSON fields#182

Merged
Sh4d1 merged 5 commits intoquickwit-oss:mainfrom
xrl:179-fix-array-filter-queries
Apr 28, 2026
Merged

Fix filter clicks on array-valued JSON fields#182
Sh4d1 merged 5 commits intoquickwit-oss:mainfrom
xrl:179-fix-array-filter-queries

Conversation

@xrl
Copy link
Copy Markdown
Contributor

@xrl xrl commented Apr 25, 2026

Summary

  • When Grafana passes a stringified JSON array (e.g. ["paperclip"]) as a filter value, the = operator wrapped it in quotes producing attributes.tags:"[\"paperclip\"]" — a phrase query matching no documents
  • Detects JSON array values and unwraps them into term queries on individual elements
  • Single element: attributes.tags:paperclip
  • Multiple elements: attributes.tags:IN ["paperclip" "stapler"] (tantivy TermSetQuery)
  • Empty arrays are a no-op
  • Non-array values starting with [ that aren't valid JSON pass through unchanged

Note: tantivy indexes array elements as individual terms — there's no way to match on array length, order, or exact composition. For multi-element arrays we use IN (match any), which is the most useful behavior for log exploration filters.

Test plan

  • 18 unit tests covering all ad-hoc filter operators and array edge cases
  • Manual test: click filter icon on an array field in Grafana log detail, verify results appear

Fixes #179

xrl added 4 commits April 24, 2026 23:30
Documents how the = operator wraps array values like ["paperclip"]
in quotes, producing phrase queries that don't match indexed array
elements. Tests cover all operator types and edge cases.

Refs quickwit-oss#179
When Grafana passes a stringified array like ["paperclip"] as a filter
value, detect it as JSON array and generate term queries on the
individual elements instead of a phrase query on the literal string.

Single element: attributes.tags:paperclip
Multiple elements: attributes.tags:paperclip OR attributes.tags:stapler
Empty array: no-op

Fixes quickwit-oss#179
Single-element arrays still produce a simple term query.
Multi-element arrays now produce field:IN ["a" "b"] which maps
to tantivy's TermSetQuery — cleaner than chaining OR clauses.

Refs quickwit-oss#179
Tantivy indexes array elements as individual terms with no way to
match on array structure. Document why IN (match any) is used for
multi-element arrays.
Comment thread src/modifyQuery.ts Outdated
Values like ["foo bar"] or ["foo:bar"] produced broken queries
(e.g. field:foo bar) because the single-element path emitted bare
terms. Now all array element values are quoted as phrase queries,
consistent with the multi-element IN path.
@xrl
Copy link
Copy Markdown
Contributor Author

xrl commented Apr 27, 2026

@Sh4d1 ready for another review

@Sh4d1 Sh4d1 merged commit a39e92f into quickwit-oss:main Apr 28, 2026
9 checks passed
@Sh4d1
Copy link
Copy Markdown
Collaborator

Sh4d1 commented Apr 28, 2026

Thanks @xrl !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter clicks on array-valued JSON fields produce incorrect queries

2 participants