【Graylog】索引模板mapping自定义

2023-11-28 10:38

本文主要是介绍【Graylog】索引模板mapping自定义,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

前言

一、Logstash输入到Elasticsearch

二、进入主题

1.根据拿到的template.json分析

2.新建文件

3.插入

4.验证

5. 遇到的错误

总结



前言

Graylog使用中,总会有千奇百怪的要求,比如有同事就想全盘挪移ELK那套东西到Graylog,目前迁移一个业务日志到平台中,要求使用Logstash输入到Elasticsearch,Graylog管控索引声明周期,负责查询功能。


一、Logstash输入到Elasticsearch

这一步很好实现,但是如果想要在Graylog中可以查看到,需要下一番功夫,我遇到的问题有以下两点。

  1. 时间戳问题,@timestamp转换为timestamp,还要对时间进行矫正,要不然会有八个小时的时差
  2. 补全字段,如果想要在Graylog可以搜索到,需要补全字段。

二、进入主题

1.根据拿到的template.json分析

  通过查看json文件,发现大部分都是keyword类型,所以根据可以不用加入到json中,最特殊的是其中一个使用ik分词器的(安装分词器,分词器的安装比较烂大街,就不在赘述了)所以使用Graylog默认的mapping肯定是行不通的。

        查看官方文档,很容易就找到了创建外挂mapping,我的理解是,新建索引集后,会根据默认的mapping+外挂的mapping共同生成一个索引mapping,参考文档:Graylog文档。

2.新建文件

        新建一个json文件,新增字段的mapping。

{"template": "cce_*","mappings": {"message": {"properties": {"cluster_name": {"type": "keyword"},"log_level": {"type": "keyword"},"type": {"type": "keyword"},"log_time": {"type": "keyword"},"namespace_name": {"type": "keyword"},"pod_name": {"type": "keyword"},"log_type": {"type": "keyword"},"cluster_uuid": {"type": "keyword"},"container_name": {"type": "keyword"},"log_data": {"search_analyzer": "ik_smart","analyzer": "ik_max_word","type": "text","fields": {"keyword": {"ignore_above": 256,"type": "keyword"}}},"workload_name": {"type": "keyword"},"collect_time": {"type": "date"}}}}
}

3.插入

curl -X PUT -d @'graylog-custom-mapping-7x.json' -H 'Content-Type: application/json' 'http://localhost:9200/_template/graylog-custom-mapping?pretty'

返回true即可。

4.验证

轮换索引集,查看mapping,成功。

{ - "cce_2": { - "mappings": { - "message": { - "dynamic_templates": [ - { - "internal_fields": { - "match": "gl2_*","match_mapping_type": "string","mapping": { - "type": "keyword"}}},{ - "store_generic": { - "match_mapping_type": "string","mapping": { - "type": "keyword"}}}],"properties": { - "_time": { - "type": "date"},"cluster_name": { - "type": "keyword"},"cluster_uuid": { - "type": "keyword"},"collect_time": { - "type": "date"},"container_name": { - "type": "keyword"},"full_message": { - "type": "text","analyzer": "ik_max_word"},"gl2_message_id": { - "type": "keyword"},"gl2_processing_timestamp": { - "type": "date","format": "yyyy-MM-dd HH:mm:ss.SSS"},"gl2_receive_timestamp": { - "type": "date","format": "yyyy-MM-dd HH:mm:ss.SSS"},"gl2_remote_ip": { - "type": "keyword"},"gl2_remote_port": { - "type": "long"},"gl2_source_input": { - "type": "keyword"},"gl2_source_node": { - "type": "keyword"},"log_data": { - "type": "text","fields": { - "keyword": { - "type": "keyword","ignore_above": 256}},"analyzer": "ik_max_word","search_analyzer": "ik_smart"},"log_level": { - "type": "keyword"},"log_time": { - "type": "keyword"},"log_type": { - "type": "keyword"},"message": { - "type": "text","analyzer": "ik_max_word"},"namespace_name": { - "type": "keyword"},"pod_name": { - "type": "keyword"},"source": { - "type": "text","analyzer": "analyzer_keyword","fielddata": true},"source_type": { - "type": "keyword"},"streams": { - "type": "keyword"},"time_day": { - "type": "date"},"time_hours": { - "type": "keyword"},"time_min": { - "type": "keyword"},"time_min_zero": { - "type": "keyword"},"time_month": { - "type": "date"},"time_nano": { - "type": "long"},"time_sec": { - "type": "keyword"},"timestamp": { - "type": "date","format": "yyyy-MM-dd HH:mm:ss.SSS"},"type": { - "type": "keyword"},"workload_name": { - "type": "keyword"}}}}}
}

5. 遇到的错误

  • 注意json文件格式
  • 由于我使用版本,搭配的es为6,所以类型上一定不要错。

总结

熟能生巧,多看官方文档,特别是国外产品。

这篇关于【Graylog】索引模板mapping自定义的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/429553

相关文章

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

poj3468(线段树成段更新模板题)

题意:包括两个操作:1、将[a.b]上的数字加上v;2、查询区间[a,b]上的和 下面的介绍是下解题思路: 首先介绍  lazy-tag思想:用一个变量记录每一个线段树节点的变化值,当这部分线段的一致性被破坏我们就将这个变化值传递给子区间,大大增加了线段树的效率。 比如现在需要对[a,b]区间值进行加c操作,那么就从根节点[1,n]开始调用update函数进行操作,如果刚好执行到一个子节点,

C++11第三弹:lambda表达式 | 新的类功能 | 模板的可变参数

🌈个人主页: 南桥几晴秋 🌈C++专栏: 南桥谈C++ 🌈C语言专栏: C语言学习系列 🌈Linux学习专栏: 南桥谈Linux 🌈数据结构学习专栏: 数据结构杂谈 🌈数据库学习专栏: 南桥谈MySQL 🌈Qt学习专栏: 南桥谈Qt 🌈菜鸡代码练习: 练习随想记录 🌈git学习: 南桥谈Git 🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈�

poj 1258 Agri-Net(最小生成树模板代码)

感觉用这题来当模板更适合。 题意就是给你邻接矩阵求最小生成树啦。~ prim代码:效率很高。172k...0ms。 #include<stdio.h>#include<algorithm>using namespace std;const int MaxN = 101;const int INF = 0x3f3f3f3f;int g[MaxN][MaxN];int n

uva 1342 欧拉定理(计算几何模板)

题意: 给几个点,把这几个点用直线连起来,求这些直线把平面分成了几个。 解析: 欧拉定理: 顶点数 + 面数 - 边数= 2。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#inc

uva 11178 计算集合模板题

题意: 求三角形行三个角三等分点射线交出的内三角形坐标。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <

poj 2104 and hdu 2665 划分树模板入门题

题意: 给一个数组n(1e5)个数,给一个范围(fr, to, k),求这个范围中第k大的数。 解析: 划分树入门。 bing神的模板。 坑爹的地方是把-l 看成了-1........ 一直re。 代码: poj 2104: #include <iostream>#include <cstdio>#include <cstdlib>#include <al

最大流、 最小费用最大流终极版模板

最大流  const int inf = 1000000000 ;const int maxn = 20000 , maxm = 500000 ;struct Edge{int v , f ,next ;Edge(){}Edge(int _v , int _f , int _next):v(_v) ,f(_f),next(_next){}};int sourse , mee

自定义类型:结构体(续)

目录 一. 结构体的内存对齐 1.1 为什么存在内存对齐? 1.2 修改默认对齐数 二. 结构体传参 三. 结构体实现位段 一. 结构体的内存对齐 在前面的文章里我们已经讲过一部分的内存对齐的知识,并举出了两个例子,我们再举出两个例子继续说明: struct S3{double a;int b;char c;};int mian(){printf("%zd\n",s