Elastic : function_score on nested that match my query

Elastic : function_score on nested that match my query

我有像这样在 Elastic 中编入索引的文档(它是简历):

{
    id: 1
    title: 'Full Stack Developper',
    updatedAt: '2016-01-01'
    experiences: [
        {
            title: 'Java Software Engineer',
            endedAt: '2016-01-01'
        },
        {
            title: 'PHP Software Engineer',
            endedAt: '2008-01-01'
        },
    ]
}

{
    id : 2
    title: 'Backend Developper',
    updatedAt: '2016-01-01'
    experiences: [
        {
            title: 'Senior PHP Software Engineer',
            endedAt: '2016-01-01'
        },
        {
            title: 'Ruby On Rails advocate',
            endedAt: '2008-01-01'
        },
    ]
}

我想提高 XP 在过去 5 年内结束的简历分数,例如包含 "PHP"。

这可以吗? (我看不出有什么办法,但 Elastic 有很多功能!)

谢谢

是的,您可以 boost 符合特定条件的特定简历的分数。您可以组合 nested query with function score。这是一个基本示例

{
  "query": {
    "function_score": {
      "query": {
        "nested": {
          "path": "experiences",
          "score_mode": "sum",
          "query": {
            "bool": {
              "must": [
                {
                  "match": {
                    "experiences.title": "php"
                  }
                },
                {
                  "range": {
                    "endedAt": {
                      "gte": "now-5y"
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "boost": 5
    }
  }
}

这会给你想要的结果,我正在使用 score_mode:sum 以便具有多个 php 经验的候选人获得更高的分数。

希望对您有所帮助!!

感谢@ChintanShah25 的回答,这对我很有帮助。这里是一个完整的请求,即到处搜索 "java" 并将在体验标题中增加带有术语 "java" 的文档,例如。 我使用 function_score 因为在我的真实情况下我有一些功能。

希望对您有所帮助(我不是 Elastic 专家,所以如果您发现语法错误,请随时添加评论;))

{
   "query": {
      "function_score": {
         "query": {
            "bool": {
               "must": {
                  "term": {
                     "_all": "java"
                  }
               },
               "should": [
                  {
                     "nested": {
                        "path": "experiences",
                        "score_mode": "sum",
                        "query": {
                           "bool": {
                              "should": [
                                 {
                                    "match": {
                                       "experiences.title": "java"
                                    }
                                 },
                                 {
                                    "range": {
                                       "experiences.start": {
                                          "gte": "now-5y"
                                       }
                                    }
                                 }
                              ]
                           }
                        }
                     }
                  }
               ]
            }
         }
      }
   }
}