elasticsearch-sql icon indicating copy to clipboard operation
elasticsearch-sql copied to clipboard

日期范围查询sql怎么写

Open suixindong opened this issue 3 years ago • 3 comments

select alarmId,alarmTitle,eventTime t_alarm where eventTime>=to_date('2022-01-01 10:00:00','yyyy-MM-dd hh24:mi:ss')and eventTime <=to_date('2022-01-01 12:00:00','yyyy-MM-dd hh24:mi:ss')

想根据 eventTime 进行时间范围查询,如上sql 在 elasticsearch-sql中应该怎么写呢 ?查了查文档 wiki 没找到相关具体的说明 。。。

用的 elastic7.9.2

suixindong avatar Mar 01 '22 02:03 suixindong

select * from myindex where date_format(created,'yyyy-MM-dd HH:mm:ss','+08:00') >= '2019-02-28 17:00:00'

select * from myindex where created >= '2019-02-28' 

shi-yuan avatar Mar 06 '22 13:03 shi-yuan

不行啊 class org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper: class_cast_exception: Cannot apply [<] operation to types [java.lang.String] and [java.lang.String].

toudsf avatar Apr 17 '22 15:04 toudsf

select eventTime,collectTime,alarmTitle from alarm* where date_format(eventTime,'yyyy-MM-dd HH:mm:ss','+00:00') >= '2021-12-16 16:29:00' and date_format(eventTime,'yyyy-MM-dd HH:mm:ss','+00:00') <= '2021-12-16 00:00:00

使用这种写法,没问题啊

suixindong avatar Apr 18 '22 01:04 suixindong