当前位置:网站首页>数据清洗-使用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"
}
}
]
}
边栏推荐
- 反转链表-就地逆置法
- Go语学习笔记 - gorm使用 - gorm处理错误 Web框架Gin(十)
- 2021GDCPC广东省大学生程序设计竞赛 H.History
- d违反常了吗
- “蔚来杯“2022牛客暑期多校训练营4 L.Black Hole 垃圾计算几何
- 2022 Nioke Summer Multi-School Training Camp 1 J Serval and Essay
- "Code execution cannot continue because MSVCP140.dll was not found, reinstalling the program may resolve the problem, etc." Solutions
- "Wei cup" school more than 2022 cattle summer camp 4 L.B lack Hole, computational geometry
- Successfully resolved ModuleNotFoundError: No module named 'Image'
- “由于找不到MSVCP140.dll,无法继续执行代码,重新安装程序可能会解决此问题等”解决方案
猜你喜欢
随机推荐
“蔚来杯“2022牛客暑期多校训练营4 L.Black Hole 垃圾计算几何
Apache Doris series: In-depth understanding of real-time analytical database Apache Doris
通过社交媒体建立个人IP的 5 种行之有效的策略
Go的Gin框架学习
宁波中宁典当转让29.5%股权为283.38万元,2021年所有者权益为968.75万元
Chapter 8 Intermediate Shell Tools II
[SAM template question] P3975 [TJOI2015] string theory
力扣题(2)—— 两数相加
IDEA usage skills
MySQL进阶sql性能分析
Debezium error series 20: task failed to create new topic. Ensure that the task is authorized to create topics
Gxlcms audio novel system/novel listening system source code
DFS question list and template summary
# # yyds dry goods inventory interview will brush TOP101: to determine whether there is a part of the list
2sk2225代换3A/1500V中文资料【PDF数据手册】
Flex布局使用
二进制序列
Ningbo Zhongning Pawn will transfer 29.5% of the equity for 2.8338 million yuan, and the owner's equity in 2021 will be 9.6875 million yuan
Apache Doris series: detailed steps for installation and deployment
vscode上利用screen命令跑代码