我想卡 business_time 字段查询 180 天内的数据,并且卡 subject_type=BIGCUSTOMER 这部分的数据
用 sql 语言是:select * from XX where business_time>=sysdate(-180) and subject_type='BIGCUSTOMER'
es 语法如下这么写为什么跑出来是 0 啊 ?
{"query":{"range":{"business_time":{"gte":"${fmt(add(NTIME(),-180,'day'),'yyyy-MM-dd')}"}},"term":{"subject_type":"BIGCUSTOMER"}}}
感谢!
![]() | 1 DonaldY 2020-03-06 14:36:27 +08:00 |
![]() | 2 nonea OP @DonaldY {"query":{"range":{"business_time":{"gte":"${fmt(add(NTIME(),-180,'day'),'yyyy-MM-dd')}"}},"match":{"subject_type":"BIGCUSTOMER"}}} term 改 match? es 完全小白,临时有一个需求点卡在这了 ,麻烦告知一下 |
![]() | 3 hackerwin7 2020-03-06 14:52:38 +08:00 via iPhone mapping |
![]() | 4 nonea OP @hackerwin7 啥意思啊 es 大佬说话都这么含糊吗 |
![]() | 5 DonaldY 2020-03-06 15:15:59 +08:00 `term`放在`query`下,试试 |
![]() | 6 stiekel 2020-03-06 15:21:42 +08:00 ```js { "query": { "bool": { "must": [ { "range": { "business_time": { "gte": "now-180d" } } }, { "term": { "subject_type": { "value": "newCalling" } } } ] } } } ``` |
![]() | 7 stiekel 2020-03-06 15:22:30 +08:00 多个条件,需要使用 bool / must 组织。 180 天内,可以使用 gte: now-180d。 |
8 ben1024 2020-03-06 15:23:27 +08:00 语法上 要把 bool must 层级聚合处理 或可以尝试 query string query_string:"business_time>date AND subject_type: BIGCUSTOMER" |
![]() | 9 francis59 2020-03-06 15:26:00 +08:00 |
![]() | 10 stiekel 2020-03-06 15:39:20 +08:00 评论不支持 markdown,重新整理一下。 { "query": { "bool": { "must": [ { "range": { "business_time": { "gte": "now-180d" } } }, { "term": { "subject_type": { "value": "BIGCUSTOMER" } } } ] } } } |
11 xz633 2020-03-06 15:39:30 +08:00 自带的 sql 了解一下 GET _xpack/sql { "query":"select count(1) from label_active where site_id in ('iosshus','andshus')" } 加上 translate 可以看对应的 dsl 语法 GET _xpack/sql/translate { "query":"select count(1) from label_active where site_id in ('iosshus','andshus')" } |
12 zxc12300123 2020-03-06 16:14:03 +08:00 via iPhone 先看看你的 mapping,business_time 是不是时间类型。 |
13 rykinia 2020-03-06 17:04:17 +08:00 你把 term 里面的 subject_type 改成 subject_type.keyword 试试,term 查字符串并不是=的效果 |