ELK系列三:Elasticsearch的简单使用和配置文件简介
1、定义模板创建索引:
首先定义好一个模板的例子
{
"order":14,
"template":"ids-1",
"state":"open",
"settings":{
"number_of_shards":1
},
"mappings":{
"warnning":{
"properties":{
"name":{
"type":"keyword"
},
"createtime":{
"type":"date",
"format":"strict_date_optional_time||epoch_millis"
},
"category":{
"type":"keyword"
},
"srcip":{
"type":"keyword"
},
"dstip":{
"type":"keyword"
}
}
}
}
}
然后使用PUT方法,发送给Elasticsearch。可以使用下图插件:

然后查看一下,模板是否上传成功:

我博客前面的Elasticsearch中曾经有关于模板的介绍,这里因为Elasticsearch的升级改版,要对模板知识做一些修改
#1、新版本的elasticsearch中,模板的index只能有true何false两个选择,与是否分词无关;不分词请把类型(type)设置成keyword。
#2、新版本中不在保留string类型,取而代之的是text类型和keyword类型,text类型可分词,keyword类型不分词。
2、创建索引操作:


3、传入数据
restful api接口,见我写的前面的文章《ELK基础学习》

数据如下:
{
"name": "ms17-010",
"createtime": 1540362486002,
"category": "attack",
"srcip": "192.168.1.3",
"dstip": "192.168.1.4"
}
效果如图:

4、Elasticsearch的配置文件简介
这里介绍的是elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application #集群名
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1 #节点名
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data #数据文件路径
#
# Path to log files:
#
#path.logs: /path/to/logs #日志文件路径
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1 #绑定的IP地址
#
# Set a custom port for HTTP:
#
#http.port: 9200 #服务端口
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"] # 允许访问的地址列表
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
# 以下是为了避免X-PACK插件与head冲突导致elasticsearch-head无法正常连接elasticsearch而配置的。
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
5、Elasticsearch批量插入数据
python 有 Elasticsearch 库,可以使用python Elasticsearch库中的helpers中的bulk来解决批量导入的问题,对于数据量大的时候的插入效率会好的多。但缺点也有,批量插入不会获取每一条插入具体成功与否的信息。Python伪代码如下:
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
es = Elasticsearch()
_list = []
_object_json = {
#...
}
for x in x:
_list.append(_object_json)
if len(_list) >= 5000:
bulk(es, _list)
if len(_list) > 0:
bulk(es, _list)
ELK系列三:Elasticsearch的简单使用和配置文件简介的更多相关文章
- ELK系列(1) - Elasticsearch + Logstash + Kibana + Log4j2快速入门与搭建用例
前言 最近公司分了个ELK相关的任务给我,在一边学习一边工作之余,总结下这些天来的学习历程和踩坑记录. 首先介绍下使用ELK的项目背景:在项目的数据库里有个表用来存储消息队列的消费日志,这些日志用于开 ...
- ElasticSearch实战系列三: ElasticSearch的JAVA API使用教程
前言 在上一篇中介绍了ElasticSearch实战系列二: ElasticSearch的DSL语句使用教程---图文详解,本篇文章就来讲解下 ElasticSearch 6.x官方Java API的 ...
- 用Qt写软件系列三:一个简单的系统工具(上)
导言 继上篇<用Qt写软件系列二:QIECookieViewer>之后,有一段时间没有更新博客了.这次要写的是一个简单的系统工具,需求来自一个内部项目.功能其实很简单,就是查看当前当前系统 ...
- 用Qt写软件系列三:一个简单的系统工具之界面美化
前言 在上一篇中,我们基本上完成了主要功能的实现,剩下的一些导出.进程子模块信息等功能,留到后面再来慢慢实现.这一篇来讲述如何对主界面进行个性化的定制.Qt库提供的只是最基本的组件功能,使用这些组件开 ...
- ELK系列(4) - Elasticsearch cannot write xcontent for unknown value of type class java.math.BigDecimal
问题与分析 在使用Elasticsearch进行index数据时,发现报错如下: java.lang.IllegalArgumentException: cannot write xcontent f ...
- ELK系列(3) - Elasticsearch修改jvm参数
方法 Elasticsearch默认会配置1G的JVM堆的初始值和最大值,该jvm参数被配置在/config/jvm.options里: -Xms1g -Xmx1g 如果只是个人开发小项目,可以把参数 ...
- elk 系列:Elasticsearch 7.2 集群部署+TLS 加密+认证登陆
背景 2019年5月21日,Elastic官方发布消息: Elastic Stack 新版本6.8.0 和7.1.0的核心安全功能现免费提供. 这意味着用户现在能够对网络流量进行加密.创建和管理用户. ...
- ElasticSearch实战系列四: ElasticSearch理论知识介绍
前言 在前几篇关于ElasticSearch的文章中,简单的讲了下有关ElasticSearch的一些使用,这篇文章讲一下有关 ElasticSearch的一些理论知识以及自己的一些见解. 虽然本人是 ...
- ElasticSearch实战系列五: ElasticSearch的聚合查询基础使用教程之度量(Metric)聚合
Title:ElasticSearch实战系列四: ElasticSearch的聚合查询基础使用教程之度量(Metric)聚合 前言 在上上一篇中介绍了ElasticSearch实战系列三: Elas ...
随机推荐
- 腾讯爱玩某处csrf导致骚扰用户(QQ弹窗+QQ会话+微博)
点击提醒,然后抓包: POST /dyid_proc.php HTTP/1.1 Host: tx.qq.com User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW ...
- 安卓开发笔记——Fragment+FragmentTabHost组件(实现新浪微博底部菜单)
记得之前写过2篇关于底部菜单的实现,由于使用的是过时的TabHost类,虽然一样可以实现我们想要的效果,但作为学习,还是需要来了解下这个新引入类FragmentTabHost 之前2篇文章的链接: 安 ...
- js 去掉重复数组
js去掉重复数组 重点一:字符串转数组 strArr.join(',') 重点二:做循环数组删除的时候,每次循环就把color[i] 去对比i之前所有数组color组合起来的字符串 比如 : i=1 ...
- java程序员如何编写更好的单元测试的7个技巧
详解 cppunit进行单元测试 单元测试(模块测试)是开发者编写的一小段代码,用于检验被测代码的一个很小的.很明确的功能是否正确.通常而言,一个单元测试是用于判断某个特定条件(或者场景)下某个特定函 ...
- linux下使用yum安装 mencached
1. 安装 yum -y install memcached 2. 启动memcached ./usr/bin/memcached -d -m 256 -u root -p 11211 -c 1024 ...
- [CNN] What is Convolutional Neural Network
Ref: 从LeNet-5看卷积神经网络CNNs 关于这篇论文的一些博文的QAC: 1. 基本原理 MLP(Multilayer Perceptron,多层感知器)是一种前向神经网络(如下图所示),相 ...
- logback -- 配置详解 -- 四 -- <filter>
附: logback.xml实例 logback -- 配置详解 -- 一 -- <configuration>及子节点 logback -- 配置详解 -- 二 -- <appen ...
- http 返回码 405 解决方案之一
今天做网络请求数据的时候遇到返回码405,当时就傻了~~ 故事是这样的-- 我用post请求访问一个url,服务端数据是一个json的txt文件,理论上直接访问,返回json,然后解析就没事了,可是今 ...
- 【Python】Linux Acanoda PySpark Spark
1.安装 Acanoda 2.安装 Spark和Scala 3.安装 PySpark 4.将Spark的Python目录拷贝至 Acanoda目录下 5.安装py4j,切换anaconda中bin目 ...
- 数据库iops的理解
想购买阿里云的RDS mysql,想请教下最大连接数是请求数吗?如下图,600最大可支持连接数,那一个页面查询30次,20个人同时请求,数据库不就超载了么?(内存2400MB,专用数据服务器,只能支持 ...