ElasticSearch置顶方案

最近系统有个需求,希望工作流的审批人被催办后就要置顶在最前面,

工作流列表我是用es的,一开始想用pinned实现,但用pinned的话,每页都会置顶在前面,我的需求只是想让他优先排在前面,翻页后正常显示

后面找到这个,通过把匹配到数据的分数提高,然后用sort进行排序,就能实现我的需求了

GET wf_workflow-latest/_search
{
  
  "query": {
    "bool": {
      "must": [
        {
          "boosting": {
      //这是数据过滤条件,影响数据结果
"positive": { "match_all": {} },
        //这是相关性数据的过滤条件,不会影响数据结果,对得分有影响
"negative": { "bool": { "must": [ { "nested": { "path": "current_task.reminders", "query": { "term": { "current_task.reminders.reminder_user_id": { "value": 1 } } } } } ] } },
        //将匹配到的相关性数据的得分乘以这个系数
"negative_boost": 10 } } ] } }, "sort": [ "_score", { "last_modification_time": { "order": "asc" } } ], "from": 0, "size": 20 }

 

posted on 2023-08-15 17:19  菜工  阅读(226)  评论(0编辑  收藏  举报

导航