Elasticsearch Query Builder

From wiki.searchtechnologies.com
Revision as of 17:11, 3 March 2017 by Sdenny (talk | contribs) (Protected "Elasticsearch Query Builder" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
Jump to: navigation, search

For Information on Aspire 3.1 Click Here

Enterprise Add-On Feature

Note: This page is accurate and complete, with the exceptions detailed below.

This page documents the details of the elasticsearch Query Builder for QPL.

Legend:

  • Operator = The QPL operator
  • Implemented = Whether or not the QPL operator has been implemented in the builder
  • Fields = Are fielded queries supported?
  • Proximity = Are proximity windows supported?
    • This may be further qualified as to whether the window can be placed directly on the operator, or if the operator is allowed to occur inside an expression which contains a proximity window on an ancestor operator node
  • Boosting = Is boosting / weighted expressions supported?


Operator Implemented Fields Proximity Boosting Implementation Notes
term Yes Yes Yes Yes TermQueryBuilder() for standard terms. MatchAllQueryBuilder() when query is "*:*" or "*". SpanTermQueryBuilder() for terms inside proximity expressions.
match Yes Yes No Yes MatchQueryBuilder() with type=boolean and operator=AND for strings inside the match operator. Not currently allowed inside of proximity expressions (may change if we ever develop a new operator for this purpose).
matchPhrase Yes Yes No Yes MatchQueryBuilder() with type=phrase for strings inside the match operator. Not currently allowed inside of proximity expressions (may change if we ever develop a new operator for this purpose).
wildcard Yes Yes Yes Yes WildcardQueryBuilder() when query has wildcard character, MatchAllQuery() when query is "*:*" or "*". RegexpQueryBuilder() with SpanMultiTermQueryBuilder() when wildcard is inside a proximity expression. Note that only wildcards "*" (zero or more characters) and "?" (exactly one character) are supported. When used inside a proximity expression, these wildcards are automatically converted to Regexp wildcards to maintain consistency.
OpTrue Yes Yes No Yes MatchAllQueryBuilder()
and Yes Yes Yes Yes BoolQueryBuilder() for standard ANDs. SpanNearQueryBuilder() for standard proximity queries with a window. SpanAndQueryBuilder() for ANDs inside of between() (Search Technologies' custom operators).
or Yes Yes Yes Yes BoolQueryBuilder() with SHOULD clauses for standard ORs. SpanOrQueryBuilder() for ORs inside of proximity expressions.
orMin Yes Yes No Yes BoolQueryBuilder() with SHOULD clauses, and minimumNumberShouldMatch() set to the minimum clauses.
max Yes Yes No Yes DisMaxQueryBuilder() with tiebreakers = 0.0
phrase Yes Yes Yes Yes MatchQueryBuilder() with type=PHRASE for standard phrases. Nested phrases and nested terms are combined together (separated by spaces) and then passed to MatchQueryBuilder().

For proximity expressions, SpanNearQueryBuilder() with slop=0 is used.

Note that, unlike Solr, nested OR expressions are not currently allowed within phrase().

To do: Use spanning match operator when this becomes available (requires custom operator) for handling phrase() within spanning functions.

between Yes Yes Yes Yes BetweenQueryBuilder() Query (custom Search Technologies operator automatically installed with QPL)
before Yes Yes Yes Yes Implemented with a SpanNearQueryBuilder with inOrder = true.
near Yes Yes Yes Yes Implemented with a SpanNearQueryBuilder with inOrder = false.
constant Yes Yes No Yes ConstantScoreQueryBuilder() with a nested BooleanQuery() (with SHOULD clauses) if there are multiple operands.
boostPlus Yes Yes No Yes BoolQueryBuilder() where first operand is MUST and all other operands are SHOULD
boostMul Yes Yes No Yes BoostingQueryBuilder() with a nested BooleanQuery() (with SHOULD clauses) if there are more than 3 arguments.
range Yes Yes No Yes RangeQueryBuilder() with both upper and lower bounds are inclusive (uses the GTE and LTE methods).
not Yes Yes No n/a For and(not()...), the not is propagated up to the and()'s BooleanQuery as a MUST_NOT clause. This is (by far) the most efficient implementation.

not(not(x)) is optimized to simply 'x'.

All other versions of not are replaced with BooleanQuery() with two clauses: The first is a MatchAllDocsQuery() with MUST, and the second is the not operand with MUST_NOT. For example:

or(not('george'), 'washington') --> (+*:* -text:george) text:washington

WARNING: Using not() within or() expressions will likely be very slow! Use sparingly, if at all.


Meta-Operator Handling

The following methods are automatically converted by the QPL framework into the simpler operators found above.

  • boost() -> Fully Implemented
  • field() -> Fully Implemented
  • compositeOr() -> Fully Implemented
  • compositeMax() -> Fully Implemented