获取有关弹性搜索的相关数据

Ram*_*ddy 5 search relevance elasticsearch elasticsearch-query

需要对候选人的技能和多年经验应用搜索条件

以下是条件

  1. 技能可以是强制性的或非强制性的
  2. 如果我们将技能作为强制性应用,那么搜索结果应包括具有技能并相应排序的记录
  3. 如果我们将技能应用为非强制性搜索结果应根据最匹配的技能进行排序
  4. 与技能一起,也可以应用经验年限,例如经验大于或小于某些年,如果应用经验年数,则搜索结果包括匹配技能名称和经验年数条件的记录,并与最匹配的记录排序

以下是有关应用的映射和查询的详细信息,这些信息不起作用

// 我的索引映射

{
                              "skills": {
                                "type": "nested",
                                "dynamic": "true",
                                "properties": {
                                  "id": {
                                    "type": "long"
                                  },
                                  "isHighlight": {
                                    "type": "boolean"
                                  },
                                  "skill": {
                                    "type": "text",
                                    "fields": {
                                      "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 32766,
                                        "normalizer": "lowerasciinormalizer"
                                      }
                                    }
                                  },
                                  "yearsOfExp": {
                                    "type": "float"
                                  }
                                }
                              }
                            }
Run Code Online (Sandbox Code Playgroud)

下面是我的索引数据

{
                              "_index": "tenant1_candidate",
                              "_type": "docs",
                              "_id": "953",
                              "_score": 0.0074906712,
                              "_source": {
                                "record": {
                                  "skills": [
                                    {
                                      "id": 0,
                                      "skill": "Jr.Software Developer",
                                      "yearsOfExp": 2,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "AJAX",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Angular Developer",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "AngularJS",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Apache Subversion",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "API",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Bachelors Degree",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Back End",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Bootstrap",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Cascading Style Sheets",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "CRUD",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "CSS3",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Design Patterns",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Excellent analytical and logical programming skills",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Front End",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Git",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "HTML",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "HTML5",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "JavaScript",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "jQuery",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Jr. UI Developer",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "JSON",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Microsoft Access",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Microsoft SQL Server",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Microsoft Visual Studio",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "MySQL",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Object Oriented Analysis/Design",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Responsive Web Design",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "REST API",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "RESTful",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Test-Driven Development",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "TypeScript",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Version Control",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "Web Services",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    },
                                    {
                                      "id": 0,
                                      "skill": "XML",
                                      "yearsOfExp": 1,
                                      "isHighlight": false
                                    }
                                  ]
                                },
                                "entityType": "Candidate",
                                "index": "tenant1_candidate",
                                "dbId": "953",
                                "id": "953"
                              }
                            }
Run Code Online (Sandbox Code Playgroud)

下面是我的搜索查询

 {
                              "from": "0",
                              "size": "30",
                              "track_scores": true,
                              "query": {
                                "bool": {
                                  "must": [
                                    {
                                      "term": {
                                        "entityType": "candidate"
                                      }
                                    },
                                    {
                                      "nested": {
                                        "path": "record.skills",
                                        "score_mode": "avg",
                                        "query": {
                                          "bool": {
                                            "should": [
                                              {
                                                "bool": {
                                                  "must": [
                                                    {
                                                      "match": {
                                                        "record.skills.skill.keyword": "XML"
                                                      }
                                                    },
                                                    {
                                                      "range": {
                                                        "record.skills.yearsOfExp": {
                                                          "gte": 0
                                                        }
                                                      }
                                                    }
                                                  ]
                                                }
                                              },
                                              {
                                                "bool": {
                                                  "must": [
                                                    {
                                                      "match": {
                                                        "record.skills.skill.keyword": "SQL"
                                                      }
                                                    },
                                                    {
                                                      "range": {
                                                        "record.skills.yearsOfExp": {
                                                          "gte": 0
                                                        }
                                                      }
                                                    }
                                                  ]
                                                }
                                              }
                                            ]
                                          }
                                        }
                                      }
                                    }
                                  ]
                                }
                              }
                            }
 

                      
Run Code Online (Sandbox Code Playgroud)

示例数据:

Candidate1 : name: x, Skills: [ { name: sk1, exp: 2 }, { name: sk2, exp: 5 }, { name: sk3, exp: 3 }]

Candidate2 : name: y, Skills: [ { name: sk1, exp: 1 }, { name: sk5, exp: 4 }, { name: sk3, exp: 1 }]

在搜索查询技能可以是强制性的或非强制性的

  1. 如果具有 2 年经验的 sk1 被作为强制性应用,那么只有候选人 1 应该出现在结果中
  2. 如果 sk1 具有 1 年的经验是强制性的,那么候选人 1 和候选人 2 应该出现在结果中,候选人 1 应该是第一个记录,因为它有更多年的经验
  3. 如果 sk1 有 2 年的经验,sk5 有 4 年的经验为非强制性,则Candidate1 和2 都应该出现在结果中,但是Candidate2 应该是结果中的第一条记录,因为它与更多技能相匹配