Skip to content

Lucene suffix wildcard field queries should compile to prefix predicates in ClickHouse #2296

Closed

Description

@qcrin

Description

Lucene suffix wildcard field queries semantically represent a prefix match. For example:

app:frontend.*

This should behave like values where app starts with frontend..

When HyperDX renders this kind of Lucene query to ClickHouse SQL, it appears to compile to a contains-style predicate instead of a prefix predicate, e.g.:

app ILIKE '%frontend.%'

For ClickHouse-backed log tables, this is much slower than preserving prefix semantics with something like:

startsWith(app, 'frontend.')
-- or
app LIKE 'frontend.%'

Why this matters

On large ClickHouse log tables ordered by a low-cardinality service/application field plus timestamp, prefix predicates can significantly reduce the scan range. Compiling a suffix-only Lucene wildcard into a contains predicate prevents effective primary key / ordering pruning and can make common saved searches much slower.

Example

Lucene query:

app:frontend.* AND environment:prod

Expected ClickHouse rendering:

startsWith(app, 'frontend.') AND environment = 'prod'

or:

app LIKE 'frontend.%' AND environment = 'prod'

Actual behavior appears to be closer to:

app ILIKE '%frontend.%' AND environment = 'prod'

Suggested behavior

When a Lucene field term has only a trailing wildcard, e.g. field:value*, render it as a ClickHouse prefix predicate instead of a contains predicate.

Leading wildcard queries such as field:*value or contains wildcard queries such as field:*value* can continue to use contains-style predicates.

Notes

This is not about implicit full-text search. It is specifically about explicit field queries with a suffix-only wildcard.

Activity

  1. pulpdrew commented on May 18, 2026

    @pulpdrew
    Contributor

    Hi @qcrin, you can achieve prefix search on fields with app:(frontend.*)

  2. qcrin commented on May 24, 2026

    @qcrin
    Author

    Hi @qcrin, you can achieve prefix search on fields with app:(frontend.*)

    Thanks @pulpdrew, that works for our use case. We'll update our saved searches to use app:(frontend.*)
    It may be useful to document this syntax.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions