1、constant_score query
A query which wraps another query, but executes it in filter context. All matching documents are given the same “constant” _score.
constantScoreQuery(termQuery("name","kimchy")).boost(2.0f);
2、bool query
The default query for combining multiple leaf or compound query clauses, as must, should, must_not, or filter clauses. The must and should clauses have their scores combined — the more matching clauses, the better — while the must_not and filter clauses are executed in filter context.
boolQuery()
.must(termQuery("content", "test1"))
.must(termQuery("content", "test4"))
.mustNot(termQuery("content", "test2"))
.should(termQuery("content", "test3"))
.filter(termQuery("content", "test5"));
3、dis_max query
A query which accepts multiple queries, and returns any documents which match any of the query clauses. While the bool query combines the scores from all matching queries, the dis_max query uses the score of the single best- matching query clause.
disMaxQuery()
.add(termQuery("name", "kimchy"))
.add(termQuery("name", "elasticsearch"))
.boost(1.2f)
.tieBreaker(0.7f);
4、function_score query
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.
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()),
new FunctionScoreQueryBuilder.FilterFunctionBuilder(
exponentialDecayFunction("age", 0L, 1L))
};
functionScoreQuery(functions);
5、boosting query
Return documents which match a positive query, but reduce the score of documents which also match a negative query.
boostingQuery(
termQuery("name","kimchy"),
termQuery("name","dadoonet"))
.negativeBoost(0.2f);
本文深入探讨了Elasticsearch中的多种查询类型,包括constant_score_query、bool_query、dis_max_query、function_score_query和boosting_query。这些查询允许用户通过不同的方式组合和修改搜索条件,以实现更精确和灵活的搜索结果。
958

被折叠的 条评论
为什么被折叠?



