标签:
在Elasticsearch,有时要通过索引日期来筛选某段时间的数据,这时就要用到ES提供的日期数学表达式
特别在日志数据中,只是查询一段时间内的日志数据,这时就可以使用日期数学表达式,这样可以限制检索的索引数量,减少集群的负载,提高系统性能。
几乎所有的API都支持日期索引中的数学参数值。
<static_name{date_math_expr{date_format|time_zone}}>
其中各个字段的含义是:
static_name:索引名字的静态部分
date_math_expr:动态的日期表达式
date_format:格式化,默认是YYYY.MM.dd
time_zone:时区,默认是UTC
需要注意的是,在使用时要把索引以及日期表达式的部分放在<>尖括号内。
比如现在的时间是2024年3月22日中午12点.utc
|
表达式 |
表达式的值 |
| <test-{now/d}> | |
curl -XPOST ‘192.168.204.32:9200/<test-\{now%2FM\}>/type/1?pretty‘ -d ‘{"name":"xing1",age:20}‘‘
{
"_index" : "test-2016.05.01",
"_type" : "type",
"_id" : "1",
"_version" : 1,
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"created" : true
}
# curl -XPOST ‘192.168.204.42:9200/<test-\{now%2FM\}>/_search?pretty‘ -d ‘{"query":{"match_all":{}}}‘
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test-2016.05.01",
"_type" : "type",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "xing1",
"age" : 20
}
} ]
}
}
Elasticsearch--Date math在索引中的使用
标签:
原文地址:http://www.cnblogs.com/miqi1992/p/5473699.html