Search code examples
elasticsearchelasticsearch-6

elasticsearch match only date of date field


Following is the mapping for date field in elasticsearch index

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

Now I want to search all the persons whose birthday is on 5th of any month.

Thanks in advance.


Solution

  • So, with above solutions help. I made the query this way

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

    The above query returns true/false value.