【发布时间】:2020-09-15 11:15:30
【问题描述】:
要求如下。
我希望结果是这样一种方式,即记录匹配两个技能应该首先出现,然后任何具有至少一项技能的记录应该放在后面,其余的放在后面(不匹配)。如果有“n”个技能给定的查询,我应该得到'n'技能匹配的记录(如果存在)然后(n-1)等等直到0技能匹配
下面是我的索引映射
//***myindexmapping***
{
"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"
}
}
}
}
below is my index data
***//myindexdata***
{
"_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"
}
}
below is my search query
***//mysearchquery***
{
"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
}
}
}
]
}
}
]
}
}
}
}
]
}
}
}
-------------
please look into this .
【问题讨论】:
-
你有没有机会仔细阅读我的回答,期待得到你的反馈:)
标签: elasticsearch