【ES】RestHighLevelClient自动创建按月索引如何实现(二)

这篇博客介绍了如何在Java应用中利用ES的RestHighLevelClient结合模板,实现按月自动创建索引。首先定义了一个名为gis-location的模板,设置了映射和设置,然后在代码中通过模板创建索引,根据ctime字段进行按月划分。文章还分享了相关注解定义、文档配置和基础DAO接口的实现,以便于管理和查询数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.本文基于 【ES】RestHighLevelClient连接阿里ElasticSearch7.10(一) 基础环境之上。记录对于es处于java中的相关业务需要做按月索引的实现

https://blog.csdn.net/ssdlleave/article/details/107846094?spm=1001.2014.3001.5501

方式:根据es模版自动创建索引。指定mapping类型

        按月创建 根据创建时间 cretetime字段按月划分。追加索引名称后自动创建索引实现按月索引

定义es gis-location模版kibana添加

POST _template/template-gis-location
{
    "template": "gis-location",
    "order": 2,
    "index_patterns": ["gis-location*"],
    "aliases": {
        "gis-location": {}
    },
    "settings": {
        "index": {
            "number_of_shards": "6",
            "number_of_replicas": "1"
        }
    },
    "mappings": {
            "dynamic_templates": [{
                "strings": {
                    "match_mapping_type": "string",
                    "mapping": {
                        "type": "keyword"
                    }
                }
            }],
            "properties": {
                "id": {
                    "type": "keyword"
                },
                "truckNumber": {
                    "type": "keyword"
                },
                "parkingTime": {
                    "type": "long"
                },
                "travelStatus": {
                    "type": "integer"
                },
                "sourceType": {
                    "type": "integer"
                },
                "accStatus": {
                    "type": "keyword"
                },
                  "mileage": {
                    "type": "keyword"
                },
                  "speed": {
                    "type": "keyword"
                },
                  "provinceCode": {
                    "type": "keyword"
                },
                  "cityCode": {
                    "type": "keyword"
                },
                  "areaCode": {
                    "type": "keyword"
                },
                  "provinceName": {
                    "type": "keyword"
                },
                  "cityName": {
                    "type": "keyword"
                },
                  "areaName": {
                    "type": "keyword"
                },
                  "locationDetails": {
                    "type": "keyword"
             &n

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值