使用 shuf 来打乱一个文件中的行或是选择文件中一个随机的行。

时间字符串的聚合

Elasticsearch | 作者 liwenlin | 发布于2017年11月17日 | 阅读数:2210

这个date字段类型为text , 例如:  2001-12-01 12:01:01 这种格式properties": {"date": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
我想用这个字段聚合到 day , month ,或者year 。如何实现呢 ? mysql里有个 substr,但不知道es有什么?
 
已邀请:

napoay

赞同来自:

从一开始就错啦,日期类型的type就设为date啊:
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"date": {
"type": "date"
}
}
}
}
}

PUT my_index/my_type/1
{ "date": "2015-01-01" }

PUT my_index/my_type/2
{ "date": "2015-01-01T12:10:30Z" }

PUT my_index/my_type/3
{ "date": 1420070400001 }

GET my_index/_search
{
"sort": { "date": "asc"}

要回复问题请先登录注册