-1

以下是弹性搜索索引中日期字段的映射

persons:{
    "dob":{
    "type": "date",
    "format": "yyyy-MM-dd"
  }
}

现在我想搜索所有生日在任何一个月的 5 日的人。

提前致谢。

4

2 回答 2

1

you can do that without reindexing! With a reindex of a date in text field, you can't search with range query against that field anymore. The best practice is to use a painless script doc['dob'].date.dayOfMonth Take a look here: https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-expression.html#_date_field_api

于 2018-05-03T08:50:07.333 回答
0

因此,有了上述解决方案的帮助。我是这样查询的

"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**]
       }
     }
   }
 }

上面的查询返回真/假值。

于 2018-05-07T07:38:26.950 回答