如何改造查询以实现基于日期范围的文档权重提升?
Boosting Documents by Date Instead of Filtering
Got it, let's adjust your query to prioritize documents from your target date range without filtering out other valid results. Here's how to refactor it:
Modified Query
{ "queryType":"full", "search": "bool(must:[(priority:High^50 OR priority:Normal^10), (type:one^1 OR type:two^10)], should:[publishedDate:2018-04-01^20])", "searchMode": "all" }
Key Changes Explained
- Removed the
filterclause: This ensures documents outside your target date are still included in results—they just won't get the extra date boost. - Added a
shouldclause with date boost: Theshouldpart applies a weight (here^20) to documents matchingpublishedDate:2018-04-01. Adjust this number to make the boost stronger (higher value) or weaker (lower value) based on how much priority you want these documents to have. - Kept mandatory filters as
mustclauses: The priority and type conditions are still required, so only documents matching those criteria are returned—date-matching ones just rank higher in results.
For Date Ranges Instead of Single Dates
If you need to boost a range (e.g., all of April 2018), use Lucene's range syntax:
{ "queryType":"full", "search": "bool(must:[(priority:High^50 OR priority:Normal^10), (type:one^1 OR type:two^10)], should:[publishedDate:[2018-04-01 TO 2018-04-30]^20])", "searchMode": "all" }
This way, your results include all valid documents (based on priority and type), but those within your target date range get a ranking boost to appear higher in the list.
内容的提问来源于stack exchange,提问作者nmishr
相关产品推荐
相关产品推荐

