Elasticsearch日期查询.在某个月出生的人 [英] Elasticsearch date query. People who were born in a certain month

查看:73
本文介绍了Elasticsearch日期查询.在某个月出生的人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下映射的字段:

I have a field with the following mapping:

birthdate: { type: :date, format: :dateOptionalTime }

  1. 我需要找到每个在5月(包括所有年份)出生的人
  2. 另一个查询是查找所有出生于"8月25日"(包括所有年份)的人

查询的内容是什么?

推荐答案

您可以通过

You can achieve this with a script filter

任何一年的5月出生的所有人:

All people born in May of any year:

{
  "query": {
    "filtered": {
      "filter": {
        "script": {
          "script": "doc.birthdate.date.monthOfYear == 5"
        }
      }
    }
  }
}

所有8月25日(每年)出生的人

All people born on August 25th (any year)

{
  "query": {
    "filtered": {
      "filter": {
        "script": {
          "script": "doc.birthdate.date.monthOfYear == 8 && doc.birthdate.date.dayOfMonth == 25"
        }
      }
    }
  }
}

这篇关于Elasticsearch日期查询.在某个月出生的人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆