当前位置:网站首页>数据清洗-使用es的ingest
数据清洗-使用es的ingest
2022-07-30 23:10:00 【talen_hx296】
通常es产品里面,数据清洗的logstash,这里使用另外的ingest做简单的数据处理
这里是根据逗号分隔数据,变成数组
PUT spring_blogs/_doc/1
{
"title":"Introducing spring framework......",
"tags":"spring,spring boot,spring cloud",
"content":"You konw, for spring framework"
}
POST _ingest/pipeline/_simulate
{
"pipeline": {
"description": "to split blog tags",
"processors": [
{
"split": {
"field": "tags",
"separator": ","
}
}
]
},
"docs": [
{
"_index": "index",
"_id": "id",
"_source": {
"title": "Introducing spring framework......",
"tags": "spring,spring boot,spring cloud",
"content": "You konw, for spring framework"
}
},
{
"_index": "index",
"_id": "idxx",
"_source": {
"title": "Introducing cloud computering",
"tags": "docker,k8s,ingrest",
"content": "You konw, for cloud"
}
}
]
}# 为ES添加一个 Pipeline
PUT _ingest/pipeline/spring_blog_pipeline
{
"description": "a spring blog pipeline",
"processors": [
{
"split": {
"field": "tags",
"separator": ","
}
},
{
"set":{
"field": "views",
"value": 0
}
}
]
}
#查看Pipleline
GET _ingest/pipeline/spring_blog_pipeline
#测试pipeline
POST _ingest/pipeline/spring_blog_pipeline/_simulate
{
"docs": [
{
"_source": {
"title": "Introducing cloud computering",
"tags": "docker,k8s,ingrest",
"content": "You konw, for cloud"
}
}
]
}
DELETE spring_blogs
PUT spring_blogs/_doc/1
{
"title":"Introducing spring framework......",
"tags":"spring,spring boot,spring cloud",
"content":"You konw, for spring framework"
}
#使用pipeline更新数据
PUT spring_blogs/_doc/2?pipeline=spring_blog_pipeline
{
"title": "Introducing cloud computering",
"tags": "docker,k8s,ingrest",
"content": "You konw, for cloud"
}
POST spring_blogs/_search
#增加update_by_query的条件
POST spring_blogs/_update_by_query?pipeline=spring_blog_pipeline
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "views"
}
}
}
}
}最终处理后的数据
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "spring_blogs",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"title" : "Introducing cloud computering",
"content" : "You konw, for cloud",
"views" : 0,
"tags" : [
"docker",
"k8s",
"ingrest"
]
}
},
{
"_index" : "spring_blogs",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"title" : "Introducing spring framework......",
"content" : "You konw, for spring framework",
"views" : 0,
"tags" : [
"spring",
"spring boot",
"spring cloud"
]
}
}
]
}
}还可以使用Script Prcessor,这种自由度更大,可以处理稍微复杂点数据
POST _ingest/pipeline/_simulate
{
"pipeline": {
"description": "to split spring blog tags",
"processors": [
{
"split": {
"field": "tags",
"separator": ","
}
},
{
"script": {
"source": """
if(ctx.containsKey("title")){
ctx.content_length = ctx.title.length();
}else{
ctx.content_length=0;
}
"""
}
},
{
"set": {
"field": "views",
"value": 0
}
}
]
},
"docs": [
{
"_index": "index",
"_id": "id",
"_source": {
"title": "Introducing spring framework......",
"tags": "spring,spring boot,spring cloud",
"content": "You konw, for spring framework"
}
},
{
"_index": "index",
"_id": "idxx",
"_source": {
"title": "Introducing cloud computering",
"tags": "docker,k8s,ingrest",
"content": "You konw, for cloud"
}
}
]
}边栏推荐
猜你喜欢

宁波中宁典当转让29.5%股权为283.38万元,2021年所有者权益为968.75万元

#yyds干货盘点# 面试必刷TOP101:判断链表中是否有环

StoneDB 为何敢称业界唯一开源的 MySQL 原生 HTAP 数据库?

ThinkPHP high imitation blue play cloud network disk system source code / docking easy payment system program

Introducing the visualization tool Netron

抽象类和接口(学习笔记)

ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序

# Dasctf 7月赋能赛 WP

Alibaba Cloud video on demand + project combat

Go1.18升级功能 - 泛型 从零开始Go语言
随机推荐
可视化工具Netron介绍
2022 Nioke Summer Multi-School Training Camp 1 J Serval and Essay
The problem of sticky packets in tcp protocol transmission
Successfully solved ImportError: always import the name '_validate_lengths'
【无标题】
微软商店出现【0x800706D9】解决方法
Apache Doris系列之:安装与部署详细步骤
2022.7.30
2sk2225 Substitute 3A/1500V Chinese Documentation【PDF Data Book】
A detailed explanation: SRv6 Policy model, calculation and drainage
QT 在父类中添加子类的流程,object tree,
IDEA使用技巧
基于 Docker Compose 的 Nacos(MySQL 持久化)的搭建
“由于找不到MSVCP140.dll,无法继续执行代码,重新安装程序可能会解决此问题等”解决方案
[MySQL] Mysql transaction and authority management
PyTorch模型导出到ONNX文件示例(LeNet-5)
EasyExcel comprehensive course combat
通过社交媒体建立个人IP的 5 种行之有效的策略
测试人面试 常被问到的计算机网络题,高薪回答模板来了
Day016 Classes and Objects