需求: 接收一个时间得毫秒值,转换为date类型,并且需要这个毫秒值做long类型得范围方便查找。
方案:考虑重新建索引,修改mapping,time字段用multi_field,定义为两种类型,一种式date一种是long。
实践:在实践种创建索引时候,出错。
"time":{
"type": "multi_field",
"fields": {
"name": {"type": "date"},
"touche": {"type": "long"}
}
}
mapping中设置一个字段为multi_field类型,在创建index mapping得时候,报错No handler for type [multi_field] declared on field [time]。
尝试修改time字段得定义为
"time": {
"type": "epoch_millis",
"fields": {
"name": {"type": "date"},
"touche": {"type": "long"}
}
}
依然报错No handler for type [epoch_millis] declared on field [time];
通过查看elasticsearch文档,一直没有创建成功,在上面两个定义中,徘徊。
最后我把epoch_millis 改为了date类型,index创建成功。time既可以用做date也可以用作long类型,通过大小范围搜寻。
"time": {
"type": "date",
"fields": {
"my_long": {
"type": "long"
}
}
}