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的简单使用和配置文件简介的更多相关文章

  1. ELK系列(1) - Elasticsearch + Logstash + Kibana + Log4j2快速入门与搭建用例

    前言 最近公司分了个ELK相关的任务给我,在一边学习一边工作之余,总结下这些天来的学习历程和踩坑记录. 首先介绍下使用ELK的项目背景:在项目的数据库里有个表用来存储消息队列的消费日志,这些日志用于开 ...

  2. ElasticSearch实战系列三: ElasticSearch的JAVA API使用教程

    前言 在上一篇中介绍了ElasticSearch实战系列二: ElasticSearch的DSL语句使用教程---图文详解,本篇文章就来讲解下 ElasticSearch 6.x官方Java API的 ...

  3. 用Qt写软件系列三:一个简单的系统工具(上)

    导言 继上篇<用Qt写软件系列二:QIECookieViewer>之后,有一段时间没有更新博客了.这次要写的是一个简单的系统工具,需求来自一个内部项目.功能其实很简单,就是查看当前当前系统 ...

  4. 用Qt写软件系列三:一个简单的系统工具之界面美化

    前言 在上一篇中,我们基本上完成了主要功能的实现,剩下的一些导出.进程子模块信息等功能,留到后面再来慢慢实现.这一篇来讲述如何对主界面进行个性化的定制.Qt库提供的只是最基本的组件功能,使用这些组件开 ...

  5. ELK系列(4) - Elasticsearch cannot write xcontent for unknown value of type class java.math.BigDecimal

    问题与分析 在使用Elasticsearch进行index数据时,发现报错如下: java.lang.IllegalArgumentException: cannot write xcontent f ...

  6. ELK系列(3) - Elasticsearch修改jvm参数

    方法 Elasticsearch默认会配置1G的JVM堆的初始值和最大值,该jvm参数被配置在/config/jvm.options里: -Xms1g -Xmx1g 如果只是个人开发小项目,可以把参数 ...

  7. elk 系列:Elasticsearch 7.2 集群部署+TLS 加密+认证登陆

    背景 2019年5月21日,Elastic官方发布消息: Elastic Stack 新版本6.8.0 和7.1.0的核心安全功能现免费提供. 这意味着用户现在能够对网络流量进行加密.创建和管理用户. ...

  8. ElasticSearch实战系列四: ElasticSearch理论知识介绍

    前言 在前几篇关于ElasticSearch的文章中,简单的讲了下有关ElasticSearch的一些使用,这篇文章讲一下有关 ElasticSearch的一些理论知识以及自己的一些见解. 虽然本人是 ...

  9. ElasticSearch实战系列五: ElasticSearch的聚合查询基础使用教程之度量(Metric)聚合

    Title:ElasticSearch实战系列四: ElasticSearch的聚合查询基础使用教程之度量(Metric)聚合 前言 在上上一篇中介绍了ElasticSearch实战系列三: Elas ...

随机推荐

  1. windows reload()

    reload() 方法用于重新加载当前文档.如果该方法没有规定参数,或者参数是 false,它就会用 HTTP 头 If-Modified-Since 来检测服务器上的文档是否已改变.如果文档已改变, ...

  2. [转]仿91助手的PC与android手机通讯

    仿91助手的PC与android手机通讯 原文 知道91助手和豌豆莢吧? 说到这两个东西,最让人好奇的应该是就是和手机的交互了.我之前有研究过电脑和安卓的交互,基本功能已经走通了,在这里我想分享一下. ...

  3. 禁止页面内按F5键进行刷新(扩展知识:禁止复制信息内容)

    禁止页面内按F5键进行刷新: //禁止页面内按F5键进行刷新 function f_DisableF5Refresh(event) { var e = event || window.event; v ...

  4. idea中mybatis generator自动生成代码配置 数据库是sqlserver

    好长时间没有写博客了,最近公司要用java语言,开始学习java,属于初学者,今天主要记录一下mybatis generator自动生成代码,首先在如下图的目录中新建两个文件,如下图 generato ...

  5. 6. go数组与冒泡排序

    include 数组的概念 如何定义数组 数组常用的用法 数组如何指定下标设值 二维数组 冒泡排序 数组 定义数组的格式:var [n] , n>=0 数组长度也是类型的一部分,因此具有不同的长 ...

  6. oracle18c linux x86-64 install 杂记

    132 yum install libstdc++-devel 133 yum install compat-libstdc++-33 135 yum install compat-libcap1 1 ...

  7. Lua获取系统时间和时间格式化方法及格式化参数

    一.系统当前时间对应的时间戳 复制代码代码如下: local ntime = os.timeprint(ntime) 二.格式化时间显示,参考下表常用于设置header等 复制代码代码如下: ngx. ...

  8. php5.4转5.3被替换的函数

    今天服务器由于业务需求,需要换成php5.4版本,以前使用的5.3,有些函数过期,导致了许多问题 1.ereg() 使用 preg_match() 替代 int preg_match ( string ...

  9. Android开发学习笔记-SharedPreferences的用法

    SharedPreferences介绍:   做软件开发应该都知道,很多软件会有配置文件,里面存放这程序运行当中的各个属性值,由于其配置信息并不多,如果采用数据库来存放并不划算,因为数据库连接跟操作等 ...

  10. 未定义变量 "caffe" 或类 "caffe.reset_all"

    配置caffe后在matlab中测试报错. 未定义变量 "caffe" 或类 "caffe.reset_all". 我的原因是:caffe在matlab接口处没 ...