ElasticSearch Java Boost on Date [英] ElasticSearch Java Boost on Date
问题描述
我目前正在加强网址,标题和描述,如下所示:
I am currently boosting on url, title, and description as follows:
QueryBuilder qb = QueryBuilders.multiMatchQuery(term,"title", "description","url").field("title", 1.75f).field("url", 1.55f).field("description", 1.35f);
我想进一步添加提升到最近创建的文档(我有一个postDate字段映射为日期)。
I would like to further add boosting to documents created more recently (I have a postDate field mapped as date).
我发现这个 SO Post 指向遗产ES文档,指的是高斯衰变。然而,我似乎在目前的Java Api doc 。
I found this SO Post pointing to a legacy ES Doc which refers to gaussian decay. However, I cannot seem to find this in the current Java Api doc.
如何在最近创建(postDate)文档的QueryBuilder中添加一个提升?
How would I add a boost to my QueryBuilder for more recently created (postDate) documents?
推荐答案
你应该看看功能分数查询:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function -score-query.html
You should have a look at the function score query: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html
以下代码提供了您可以使用的内容:
The following code gives a hint to what you could use:
QueryBuilder qb = QueryBuilders.multiMatchQuery(term,"title", "description","url").field("title", 1.75f).field("url", 1.55f).field("description", 1.35f);
FunctionScoreQueryBuilder builder = QueryBuilders.functionScoreQuery(qb);
builder.add(ScoreFunctionBuilders.exponentialDecayFunction("postDate","14d"));
这篇关于ElasticSearch Java Boost on Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!