英文:
Elastic Search RangeQuery
问题
ElasticSearch查询的JSON代码已经翻译如下:
{
"from": 0,
"size": 20,
"query": {
"bool": {
"must": [
{
"term": {
"companyId": 3211002
}
},
{
"terms": {
"status": [
"0"
]
}
},
{
"bool": {
"must": {
"range": {
"salaryBottom": {
"from": "12",
"to": null,
"include_lower": true,
"include_upper": false
}
}
}
}
},
{
"bool": {
"must": {
"range": {
"salaryTop": {
"from": null,
"to": "13",
"include_lower": false,
"include_upper": true
}
}
}
}
}
]
}
},
"sort": [
{
"createTime": {
"order": "desc"
}
}
]
}
查询结果也已翻译如下:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": null,
"hits": [
{
"_index": "recruitment",
"_type": "requirement",
"_id": "578",
"_score": null,
"_source": {
"id": 578,
"companyId": 3211002,
"hrId": 1004483,
"formId": 578,
"requirementId": "urge0001",
"degree": 7,
"positionTitle": "testJDL",
"positionProperties": 1,
"positionPriority": 1,
"requirementCount": 3,
"requirementType": 1,
"reportTo": 1004483,
"requirementTeam": 188384773,
"salaryTop": -1,
"salaryBottom": 33,
"requirementStatus": 0,
"manager": [
1004483
],
"startTime": "2023-06-03",
"endTime": "2023-06-03",
"description": "333",
"status": 0,
"createTime": 1685689854630,
"hasAttachment": true
},
"sort": [
1685689854630
]
},
{
"_index": "recruitment",
"_type": "requirement",
"_id": "563",
"_score": null,
"_source": {
"id": 563,
"companyId": 3211002,
"hrId": 1004483,
"formId": 563,
"requirementId": "testData",
"positionTitle": "afs",
"positionProperties": 2,
"requirementCount": 11,
"salaryTop": 13,
"salaryBottom": 12,
"requirementStatus": 0,
"description": "AbCdE的",
"status": 0,
"createTime": 1685606170594,
"hasAttachment": true
},
"sort": [
1685606170594
]
}
]
}
}
英文:
I have encountered another issue: how do I use rangeQuery to search for the lower limit of salary ('salaryBottom') and the upper limit of salary ('salaryTop')? like salary between 12 and 13.
I tried several methods, but none of them worked, and the result was to return the data with ID= 578.
ElasticSearch Query for ES
{
"from": 0,
"size": 20,
"query": {
"bool": {
"must": [
{
"term": {
"companyId": 3211002
}
},
{
"terms": {
"status": [
"0"
]
}
},
{
"bool": {
"must": {
"range": {
"salaryBottom": {
"from": "12",
"to": null,
"include_lower": true,
"include_upper": false
}
}
}
}
},
{
"bool": {
"must": {
"range": {
"salaryTop": {
"from": null,
"to": "13",
"include_lower": false,
"include_upper": true
}
}
}
}
}
]
}
},
"sort": [
{
"createTime": {
"order": "desc"
}
}
]
}
Result:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": null,
"hits": [
{
"_index": "recruitment",
"_type": "requirement",
"_id": "578",
"_score": null,
"_source": {
"id": 578,
"companyId": 3211002,
"hrId": 1004483,
"formId": 578,
"requirementId": "urge0001",
"degree": 7,
"positionTitle": "testJDL",
"positionProperties": 1,
"positionPriority": 1,
"requirementCount": 3,
"requirementType": 1,
"reportTo": 1004483,
"requirementTeam": 188384773,
"salaryTop": -1,
"salaryBottom": 33,
"requirementStatus": 0,
"manager": [
1004483
],
"startTime": "2023-06-03",
"endTime": "2023-06-03",
"description": "333",
"status": 0,
"createTime": 1685689854630,
"hasAttachment": true
},
"sort": [
1685689854630
]
},
{
"_index": "recruitment",
"_type": "requirement",
"_id": "563",
"_score": null,
"_source": {
"id": 563,
"companyId": 3211002,
"hrId": 1004483,
"formId": 563,
"requirementId": "testData",
"positionTitle": "afs",
"positionProperties": 2,
"requirementCount": 11,
"salaryTop": 13,
"salaryBottom": 12,
"requirementStatus": 0,
"description": "AbCdE的",
"status": 0,
"createTime": 1685606170594,
"hasAttachment": true
},
"sort": [
1685606170594
]
}
]
}
}
答案1
得分: 1
由于 salaryBottom
在逻辑上小于 salaryTop
,我会这样做(即 12 <= salaryBottom < salaryTop <= 13):
{
"bool": {
"must": {
"range": {
"salaryBottom": {
"from": "12",
"to": "13",
"include_lower": true,
"include_upper": false
}
}
}
}
},
{
"bool": {
"must": {
"range": {
"salaryTop": {
"from": "12",
"to": "13",
"include_lower": false,
"include_upper": true
}
}
}
}
}
}
英文:
Since salaryBottom
is logically smaller than salaryTop
, I would do it this way (i.e. 12 <= salaryBottom < salaryTop <= 13):
{
"bool": {
"must": {
"range": {
"salaryBottom": {
"from": "12",
"to": "13",
"include_lower": true,
"include_upper": false
}
}
}
}
},
{
"bool": {
"must": {
"range": {
"salaryTop": {
"from": "12",
"to": "13",
"include_lower": false,
"include_upper": true
}
}
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论