Reference Entry
RegexpQuery for Term-Level Regular Expressions
Lexical Querying · advanced · order 80
Match indexed terms with JavaScript regular expressions when wildcard patterns are not expressive enough, using the JSON DSL first.
Relevant APIs
RegexpQuery for Term-Level Regular Expressions
regexp matches indexed terms with a JavaScript RegExp or regex pattern string.
Like WildcardQuery, this is term-level behavior. It does not run full-text analysis over the query text.
Basic example
{
"query": {
"regexp": {
"title": "^quer"
}
}
}
When to use it
- Power-user filters
- Pattern-heavy identifiers
- Cases where
WildcardQueryis too limited
Regexp vs Wildcard
wildcardis simpler and easier to reason aboutregexpis more expressive
Prefer wildcard if simple * and ? are enough.
Notes
- Matching is done against indexed terms.
- Querylight removes the
gflag from regex objects to avoid stateful repeated-search bugs. - Broad regexes can match many terms, so keep them deliberate.