Span queries are low-level positional queries which provide expert control
over the order and proximity of the specified terms. These are typically used
to implement very specific queries on legal documents or patents.
Span queries cannot be mixed with non-span queries (with the exception of the
The queries in this group are:
The equivalent of the
term query but for use with
other span queries.
Accepts another span query whose matches must appear within the first N
positions of the field.
Accepts multiple span queries whose matches must be within the specified distance of each other, and possibly in the same order.
Combines multiple span queries — returns documents which match any of the
Wraps another span query, and excludes any documents which match that query.
Accepts a list of span queries, but only returns those spans which also match a second span query.
The result from a single span query is returned as long is its span falls
within the spans returned by a list of other span queries.
See Span Term Query
QueryBuilder qb = spanTermQuery(
Span Multi Term Queryedit
See Span Multi Term Query
QueryBuilder qb = spanMultiTermQueryBuilder(
Can be any builder extending the
MultiTermQueryBuilder class. For example:
See Span First Query
QueryBuilder qb = spanFirstQuery(
max end position
See Span Near Query
QueryBuilder qb = spanNearQuery(
span term queries
slop factor: the maximum number of intervening unmatched positions
whether matches are required to be in-order
See Span Not Query
QueryBuilder qb = spanNotQuery(
span query whose matches are filtered
span query whose matches must not overlap those returned
Span Containing Queryedit
See Span Containing Query
QueryBuilder qb = spanContainingQuery(
See Span Within Query
QueryBuilder qb = spanWithinQuery(
spanNearQuery(spanTermQuery("field1", "bar"), 5)