ELK搜索引擎三剑客(存储+检索+分析) ---elasticsearch

10 篇文章 0 订阅
7 篇文章 0 订阅

ELK搜索引擎三剑客(存储+检索+分析) —elasticsearch

elasticsearch:分布式搜索引擎,大规模数据的搜索

下载es设置软连接 环境变量
first: #编辑/etc/security/limits.conf,追加以下内容:
* - nofile 65536 #针对当前系统针对所有用户最大打开文件数为65536
second: #编辑/etc/sysctl.conf文件,追加以下内容:
vm.max_map_count=262144 #elasticsearch最低要求
下命令sysctl -p 使设置过的文件保存生效
third: #编辑/opt/es/config/elasticsearch.yml,修改以下内容:
network.host: 0.0.0.0 设备主机ip

启动命令:elasticsearch -d 后台启动

elasticsearch-head:安装

1.安装必要的编译包
yum install gcc gcc-c++
2.从源码下载Nodejs
wget https://npm.taobao.org/mirrors/node/v10.13.0/node-v10.13.0.tar.gz
3.解压nodejs 进入node文件夹 开始编译 时间很长
cd node-v10.13.0/
./configure
make
4.编译完安装nodejs
make install
5.查看版本
node -v
6.解压elasticsearch-head
npm镜像替换为淘宝镜像
npm config set registry http://registry.npm.taobao.org/
安装npm
npm install
7.设置es跨域访问
cd el config
vi elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: “*”
8.分别启动es 和head

ES数据模型
index 索引 database
type 类型 table
document 文档 row
field 字段 column

批量导入JSON文件
curl -XPUT ‘localhost:9200/_bulk’ -H ‘Content-Type:application/json’ --data-binary @文件名.json

带参创建索引
PUT demo.1234
{
“settings” : {
“index” : {
“number_of_shards” : 2, 分片数,默认为5
“number_of_replicas” : 2 副本数量,默认1
}
}
}
PUT demo.12345
{
“settings” : {
“number_of_shards” : 1
},
“mappings” : {
“_doc” : {
“properties” : {
“field1” : { “type” : “text” }
}
}
}
}

ES搜索方式
URI Search:简易模式
Query DSL:基于JSON的查询语言

Query DSL:

1.mach_all 返回所有文档

GET stu/_search
{
“query”: {
“match_all”: {}
}
}

2.布尔查询匹配 对查询字符串进行分词,根据分词结果构造布尔查询,如果有中文分词器会根据词来分

GET stu/_search
{
“query”: {
“match”: {
“name”:“John Kerry”
}
}
}

3.match_phrase:短语匹配查询 根据字符串进行分词,

GET stu/_search
{
“query”: {
“match_phrase”: {
“name”:“John Kerry”
}
}
}

4.match_phrase_prefix:短语前缀匹配查询 类似match_phrase,但最后一个分词作为前缀匹配

GET stu/_search
{
“query”: {
“match_phrase_prefix”: {
“name”:“John Ke”
}
}
}

5.multi_match:多字段匹配查询   给定一句话 给定该句话可能存在的多个字段,进行查询

GET stu/_search
{
“query”: {
“multi_match”: {
“query”: “John like cooking”,
“fields”: [“name”,“interest”]
}
}
}

6.term:词条查询  :根据具体的,确切的字词,对字段进行匹配

GET stu/_search
{
“query”: {
“term”:{
“name”:“john”
}
}
}

7.多词条查询 按照存储在倒排索引中的确切字词,对字段进行多词条匹配  一个字段中多条

GET stu/_search
{
“query”: {
“terms”:{
“name”:[“john”,“da”]
}
}
}

8.范围查询	  左闭右开

GET stu/_search
{
“query”: {
“range” : {
“yearOfBorn” : {
“gte” : 1995,
“lte” : 2000
}
}
}
}
9.bool:布尔查询 在匹配字段的情况 不匹配must not中的内容
GET stu/_search
{
“query”: {
“bool”: {
“must”: {
“match”: { “interest”: “cooking”} },
“must_not”: {
“range”: { “yearOfBorn”: { “gte”: 1995, “lte”: 2000 }}}
}
}
}
from+size 浅分页
GET stu/_search
{
“query”: {
“match_all”: {}
},
“size”: 5,
“from”: 0
}

scroll  深分页

GET stu/_search?scroll=5m
{
“from”: 0,
“size”: 5,
“query”: {“match_all”: {}}
}
GET _search/scroll
{
“scroll_id”: “DnF1ZXJ5VGhlbkZldGNoBQAAAAAAAANy……”,
“scroll”: “5m”
}

ES是ELK Stack的核心
ES的数据模型包括哪些?
ES分布式架构的核心是在多台主机中启动ES实例
ES为开发者提供了丰富的RESTful API

ES数据模型包括index type document field 等 分别对应关系型数据库的database table row column。(牢记)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值