elasticsearch 只匹配日期字段的日期
elasticsearch match only date of date field
以下是elasticsearch索引中日期字段的映射
persons:{
"dob":{
"type": "date",
"format": "yyyy-MM-dd"
}
}
现在我想搜索所有生日在任何一个月的 5 号的人。
提前致谢。
您可以在不重新索引的情况下做到这一点!通过在 text
字段中重新索引日期,您无法再使用 range query
对该字段进行搜索。最好的做法是使用无痛脚本 doc['dob'].date.dayOfMonth
看这里:https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-expression.html#_date_field_api
所以,有了上面的解决方案帮助。我是这样查询的
"script_fields": {
"isDOBMatch": {
"script": {
"lang":"painless",
"inline": "doc.dob.date.dayOfMonth==params.dob_match_vals",
"params": {
"dob_match_vals": [**pass the value which u want to match**]
}
}
}
}
以上查询returnstrue/false值。
以下是elasticsearch索引中日期字段的映射
persons:{
"dob":{
"type": "date",
"format": "yyyy-MM-dd"
}
}
现在我想搜索所有生日在任何一个月的 5 号的人。
提前致谢。
您可以在不重新索引的情况下做到这一点!通过在 text
字段中重新索引日期,您无法再使用 range query
对该字段进行搜索。最好的做法是使用无痛脚本 doc['dob'].date.dayOfMonth
看这里:https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-expression.html#_date_field_api
所以,有了上面的解决方案帮助。我是这样查询的
"script_fields": {
"isDOBMatch": {
"script": {
"lang":"painless",
"inline": "doc.dob.date.dayOfMonth==params.dob_match_vals",
"params": {
"dob_match_vals": [**pass the value which u want to match**]
}
}
}
}
以上查询returnstrue/false值。