我有像这样的弹性搜索文件
{
"_index" : "sokhop",
"_type" : "jobs",
"_id" : "14",
"_score" : 1.0,
"_source" : {
"job_salary" : "2000000 - 10",
"job_bonus" : "> 5909990",
"job_location" : [ {
"province_name" : "tay ho",
"district" : "",
"province_value" : "Tay Ho",
"street" : "",
"province_id" : 130,
"number" : "",
"job_id" : 14
} ],
"job_created_at" : "2016-10-14T10:01:45.000Z",
"job_exclude_condition" : [ ],
"job_expired_time" : "2000-01-01T00:00:00.000Z",
"job_skills" : "",
"job_owner_id" : 2,
"job_position" : {
"pos_value" : "LTV",
"pos_id" : 1,
"pos_name" : "ltv"
},
"job_time_type" : 2,
"job_isactive" : 1,
"job_description" : "",
"job_categories" : [ ],
"job_year_exps" : "1 Năm",
"salary" : {
"job_allowance" : {
"min" : 4000000,
"max" : -1
},
"job_bonus" : {
"min" : 5909990,
"max" : -1
},
"job_salary" : {
"min" : 2000000,
"max" : 10
}
},
"job_gender" : 1,
"job_status" : 2,
"job_languages" : [ {
"lang_name" : "english",
"lang_code" : "en",
"job_id" : 14,
"lang_id" : 1,
"lang_updated_at" : "2016-10-08T09:47:49.000Z",
"lang_created_at" : "2016-10-08T09:47:49.000Z"
} ],
"job_id" : 14,
"job_extra_desc" : "",
"job_allowance" : "> 4000000",
"job_require_condition" : [ ],
"job_work_location" : "[{\"district\":\"\",\"province\":130,\"number\":\"\",\"street\":\"\"}]",
"job_updated_at" : "2016-10-18T03:20:38.000Z",
"job_language_profile" : "en",
"job_title" : "Tin",
"job_position_id" : 1
}
},
我使用搜索的查询是
{
"query": {
"bool": {
"must": [
{
"match": {
"job_location.province_id": "130"
}
},
{
"match": {
"job_position.pos_id": "1"
}
}
],
"filter": [
{
"range": {
"salary.job_salary.min": {
"gte": 20000
}
}
},
{
"term": {
"salary.job_salary.max": 10
}
}
]
}
}
}
好吧它工作正常!但是当条件改变为
时
"gte": 50000
或300000,40000每个数字不以2弹性搜索开始立即返回空数组[]
更新
以下是我的弹性搜索的所有结果 ==> elasticsearch_result
我如何重新获得它?
答案 0 :(得分:1)
根据您的映射,问题是您的salary.job_salary.min
字段是类型字符串。
"job_salary":{"properties":{"max":{"type":"string"},"min":{"type":"string"}}
对字符串字段的range
查询不会按数字顺序对数值进行排序,而是按字典顺序排序,即" 50000"在" 2000000000"
解决此问题的唯一方法是删除索引并使用适当的数据类型创建正确的映射。
DELETE sokhop
PUT sokhop
{
"mappings": {
"jobs": {
"properties": {
"job_allowance": {
"type": "string"
},
"job_apply_number": {
"type": "long"
},
"job_apply_numbers": {
"type": "long"
},
"job_bonus": {
"type": "string"
},
"job_categories": {
"properties": {
"jca_created_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"jca_id": {
"type": "long"
},
"jca_name": {
"type": "string"
},
"jca_updated_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"jca_value": {
"type": "string"
},
"job_id": {
"type": "long"
}
}
},
"job_company_id": {
"type": "long"
},
"job_created_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"job_description": {
"type": "string"
},
"job_exclude_condition": {
"properties": {
"jexca_created_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"jexca_id": {
"type": "long"
},
"jexca_name": {
"type": "string"
},
"jexca_updated_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"jexcon_value": {
"type": "string"
},
"job_id": {
"type": "long"
}
}
},
"job_expired_time": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"job_extra_desc": {
"type": "string"
},
"job_gender": {
"type": "long"
},
"job_id": {
"type": "long"
},
"job_isactive": {
"type": "long"
},
"job_language_profile": {
"type": "string"
},
"job_languages": {
"properties": {
"job_id": {
"type": "long"
},
"lang_code": {
"type": "string"
},
"lang_created_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"lang_id": {
"type": "long"
},
"lang_name": {
"type": "string"
},
"lang_updated_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
},
"job_location": {
"properties": {
"district": {
"type": "string"
},
"job_id": {
"type": "long"
},
"number": {
"type": "string"
},
"province_id": {
"type": "long"
},
"province_name": {
"type": "string"
},
"province_value": {
"type": "string"
},
"street": {
"type": "string"
}
}
},
"job_owner_id": {
"type": "long"
},
"job_position": {
"properties": {
"pos_id": {
"type": "long"
},
"pos_name": {
"type": "string"
},
"pos_value": {
"type": "string"
}
}
},
"job_position_id": {
"type": "long"
},
"job_quantity": {
"type": "long"
},
"job_range_allowance_id": {
"type": "long"
},
"job_range_bonus_id": {
"type": "long"
},
"job_range_salary_id": {
"type": "long"
},
"job_require_condition": {
"properties": {
"jexca_created_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"jexca_id": {
"type": "long"
},
"jexca_name": {
"type": "string"
},
"jexca_updated_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"jexcon_value": {
"type": "string"
},
"job_id": {
"type": "long"
}
}
},
"job_salary": {
"type": "string"
},
"job_skills": {
"type": "string"
},
"job_status": {
"type": "long"
},
"job_time_type": {
"type": "long"
},
"job_title": {
"type": "string"
},
"job_updated_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"job_views_number": {
"type": "long"
},
"job_work_location": {
"type": "string"
},
"job_year_exps": {
"type": "string"
},
"salary": {
"properties": {
"job_allowance": {
"properties": {
"max": {
"type": "long"
},
"min": {
"type": "long"
}
}
},
"job_bonus": {
"properties": {
"max": {
"type": "long"
},
"min": {
"type": "long"
}
}
},
"job_salary": {
"properties": {
"max": {
"type": "long"
},
"min": {
"type": "long"
}
}
}
}
}
}
}
}
}
然后您需要重新索引数据,之后您的查询将按预期工作。