首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ElasticSearch :如何提高分数取决于字段值?

ElasticSearch :如何提高分数取决于字段值?
EN

Stack Overflow用户
提问于 2016-10-07 11:38:52
回答 3查看 6.1K关注 0票数 1

我试图通过提高基于字段值的_score来消除elasticsearch中的排序问题。下面是我的场景:

我的文档中有一个字段: applicationDate。这是自EPOC以来的一段时间。我希望有更高的applicationDate (最近的)记录有更高的分数。

如果两个文档的得分相同,我希望在另一个类型为String的字段上对它们进行排序。说“状态”是另一个有价值的字段(可用,正在进行中,已关闭)。因此,具有相同applicationDate的文档应该具有基于状态的_score。可用应该有更多的分数,在进度较少,关闭,最少。因此,通过这种方法,我将不必在得到结果后对文档进行排序。

请给我一些指点。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-10-07 14:53:15

您应该能够使用功能评分实现这一点。根据您的需求,它可以像下面的示例一样简单:

代码语言:javascript
运行
复制
  put test/test/1 
{
     "applicationDate" : "2015-12-02",
     "status" : "available"
}
put test/test/2
{
     "applicationDate" : "2015-12-02",
     "status" : "progress"
}

put test/test/3
{
     "applicationDate" : "2016-03-02",
     "status" : "progress"
}


post test/_search
{
   "query": {
      "function_score": {
         "functions": [
             {
               "field_value_factor" : {
                    "field" : "applicationDate",
                    "factor" : 0.001
               }
             },
            {
               "filter": {
                  "term": {
                     "status": "available"
                  }
               },
               "weight": 360
            },
            {
               "filter": {
                  "term": {
                     "status": "progress"
                  }
               },
               "weight": 180
            }
         ],
         "boost_mode": "multiply",
         "score_mode": "sum"
      }
   }
}
**Results:**

"hits": [
     {
        "_index": "test",
        "_type": "test",
        "_id": "3",
        "_score": 1456877060,
        "_source": {
           "applicationDate": "2016-03-02",
           "status": "progress"
        }
     },
     {
        "_index": "test",
        "_type": "test",
        "_id": "1",
        "_score": 1449014780,
        "_source": {
           "applicationDate": "2015-12-02",
           "status": "available"
        }
     },
     {
        "_index": "test",
        "_type": "test",
        "_id": "2",
        "_score": 1449014660,
        "_source": {
           "applicationDate": "2015-12-02",
           "status": "progress"
        }
     }
  ]
票数 9
EN

Stack Overflow用户

发布于 2016-10-07 14:38:53

你看过功能分数了吗?https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html

特别是在上面的文档中查看衰变函数。

票数 0
EN

Stack Overflow用户

发布于 2021-01-09 12:16:28

有一个名为rank_feature_field的新字段可用于此usecase:

https://www.elastic.co/guide/en/elasticsearch/reference/current/rank-feature.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39916339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档