1、模版获取

https://github.com/qkfm-97/nifi-example/blob/main/etl/mysql-to-es.xml

2、任务说明

将mysql的test_addition表数据先全量导入到elasticsearch中的land_aoi索引中,然后1小时增量同步一次

具体的字段对应和处理如下

源表(test_addition)目标索引(land_aoi)备注
idid索引中的id加上AOI_
namename
wktoutline轮廓
type_cntype_cn场所类型
locationlocation中心位置经纬度

3、流程截图

4、重点说明

   1)表结构和建索引语句

DROP TABLE IF EXISTS `test_addition`;
CREATE TABLE `test_addition`  (
  `id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `WKT` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '场所轮廓',
  `NAME` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '场所名称',
  `CITY` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '市',
  `PROVINCE` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '省',
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '对应的中心点经纬度',
  `type_cn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '场所类型',
  `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

 

#添加索引,number_of_shards数据量大的话 分片多建几个,我们一般是10~15个g一个分片
put   land_aoi
{
    "aliases": {

    },
    "mappings": {
      "properties": {
        "name": {
          "type": "keyword"
        },
        "id": {
          "type": "keyword"
        },
        "location": {
          "type": "geo_point"
        },
		 "outline": {
          "type": "keyword",
          "index": false
        },
        "type_cn": {
          "type": "keyword"
        }
      }
    },
    "settings": {
      "index": {
         
        "number_of_shards": "1",
        
        "number_of_replicas": "1" 
      }
    }
}

   2)有的数据没有中心点数据,这边使用了ExecuteScript 通过轮廓数据,计算出中心点获取location

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐