ElasticSearch: How to query a date field using an hours-range filter

后端 未结 3 977
庸人自扰
庸人自扰 2020-12-10 12:04

Currently, I already know how to filter a days range from a (timestamp) date field. That\'s an easy one:

\"range\": {
    \"date\": {
        \"gte\": \"2015         


        
3条回答
  •  自闭症患者
    2020-12-10 12:46

    If I understood your question correctly then I think you have to add new field which indexes only time like

    PUT your_index
    {
      "mappings": {
        "your_type": {
          "properties": {
            "time": {
              "type":   "date",
              "format": "HH:mm:ss"
            }
          }
        }
      }
    }
    

    Then you can query like this

    {
      "query": {
        "bool": {
          "must": [
            {
              "range": {
                "date": {
                  "gte": "2015-11-01",
                  "lte": "2015-11-30"
                }
              }
            },
            {
              "range": {
                "time": {
                  "gte": "08:00:00",
                  "lte": "10:00:00"
                }
              }
            }
          ]
        }
      }
    }
    

    Does this help?

提交回复
热议问题