Compound queriesedit
Compound queries wrap other compound or leaf queries, either to combine their results and scores, to change their behaviour, or to switch from query to filter context.
The queries in this group are:
-
constant_scorequery -
A query which wraps another query, but executes it in filter context. All
matching documents are given the same “constant”
_score. -
boolquery -
The default query for combining multiple leaf or compound query clauses, as
must,should,must_not, orfilterclauses. Themustandshouldclauses have their scores combined — the more matching clauses, the better — while themust_notandfilterclauses are executed in filter context. -
dis_maxquery -
A query which accepts multiple queries, and returns any documents which match
any of the query clauses. While the
boolquery combines the scores from all matching queries, thedis_maxquery uses the score of the single best- matching query clause. -
function_scorequery - Modify the scores returned by the main query with functions to take into account factors like popularity, recency, distance, or custom algorithms implemented with scripting.
-
boostingquery -
Return documents which match a
positivequery, but reduce the score of documents which also match anegativequery. -
indicesquery - Execute one query for the specified indices, and another for other indices.
Constant Score Queryedit
Bool Queryedit
See Bool Query
Dis Max Queryedit
See Dis Max Query
Function Score Queryedit
See Function Score Query.
To use ScoreFunctionBuilders just import them in your class:
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.*;
FilterFunctionBuilder[] functions = {
new FunctionScoreQueryBuilder.FilterFunctionBuilder(
matchQuery("name", "kimchy"),
randomFunction("ABCDEF")),
new FunctionScoreQueryBuilder.FilterFunctionBuilder(
exponentialDecayFunction("age", 0L, 1L))
};
QueryBuilder qb = QueryBuilders.functionScoreQuery(functions);Boosting Queryedit
See Boosting Query
Indices Queryedit
Deprecated in 5.0.0.
Search on the _index field instead.
See Indices Query
// Using another query when no match for the main one
QueryBuilder qb = indicesQuery(
termQuery("tag", "wow"),
"index1", "index2"
).noMatchQuery(termQuery("tag", "kow")); 
query to be executed on selected indices | |
selected indices | |
query to be executed on non matching indices |