本片文章记录了elasticsearch概念、特点、集群、插件、API使用方法。

1.elasticsearch的概念及特点。
概念:elasticsearch是一个基于lucene的搜索服务器。lucene是全文搜索的一个框架。
特点:

  - 分布式,可扩展,高可用。
  - 能够实时搜索分析数据。
  - 复杂的RESTful API。
总结:是一个采用RESTful API标准,实现分布式、可扩展以及高可用的实时数据存储分析的全文搜索工具。

2.elasticsearch涉及的相关概念。(关系非关系对比)
相关概念:
  - Node: 装有一个elasticsearch服务器的节点。
  - Cluster: 有一个或多个Node组成的集群,共同工作。
  - Document: 一个可被搜素的基础信息单元。
  - Index: 拥有相似特征的文档的集合。
  - Type: 一个索引中可以定义一种或多种类型。
  - Filed: 是elasticsearch的最小单位,相当于数据的某一列。
  - Shards: 索引分成若干份,每一份就是一个shard。默认5份。
  - Replics: 是索引的一份或者多份拷贝。
关系型与非关系型对比:
    database ---->   Index
    table       ---->   Type
    row         ---->   Document
    column    ---->   Filed
内置字段和字段类型:
  - 内置字段:_uid,_id,_type,_source,_all,_analyzer,_boost,_parent,_routing,_index,_size,_timestamp,_ttl
  - 字段类型:string,integer/long,float/double,boolean,null,date

3.elasticsearch架构详解。

4.什么是倒排索引。
概念:倒排索引(英语:Inverted index),也常被称为反向索引、置入档案或反向档案。是一种索引方法,被用来存储在全文搜索下某个单词在一个文档或者一组文档中的存储位置的映射。它是文档检索系统中最常用的数据结构。

正向索引和倒排索引对比:
内容 --正向--> 关键字/词
内容 <--倒排-- 关键字/词

5.RESTful API以及curl。
概念:RESTful 表现层状态转化。
  - 表现层:图片,文字,视频等
  - 转化后:资源
API:应用程序接口。
RESTful API:一种资源操作的应用程序接口。
curl:一个利用URL语法在命令行下工作的文件传输工具,支持文件上传和下载。
curl常用参数:
  - I 获取头部信息
  - v 获取握手过程
  - o 保存文件
curl -o baidu.html www.baidu.com
curl -I -v www.baidu.com

6.elasticsearch单机/集群安装配置。
单机安装(node1上安装elasticsearch)
①.安装jdk1.8_65
[root@node1 ~]# rpm -ivh jdk-8u65-linux-x64.rpm
②.下载安装elasticsearch,并设置开启自启动。
[root@node1 ~]# wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.4/elasticsearch-2.3.4.rpm
[root@node1 ~]# rpm -ivh elasticsearch-2.3.4.rpm
[root@node1 ~]# chkconfig --add elasticsearch
③.修改配置文件,并启动服务。
[root@node1 ~]# grep -Ev "^#|^$" /etc/elasticsearch/elasticsearch.yml
network.host: 192.168.3.1
http.port: 9200
[root@node1 ~]# service elasticsearch start
④.浏览器访问IP:9200查看结果。
http://192.168.3.1:9200

集群安装(node1|node2安装elasticsearch)
①.node2上安装,安装同单机node1一样。
②.修改node1和node2配置文件。
node1:
[root@node1 ~]# grep -Ev "^#|^$" /etc/elasticsearch/elasticsearch.yml
cluster.name: elk-xkops
node.name: node-1
network.host: 192.168.3.1
http.port: 9200
node2:
[root@node2 ~]# grep -Ev "^#|^$" /etc/elasticsearch/elasticsearch.yml
cluster.name: elk-xkops
node.name: node-2
network.host: 192.168.3.2
discovery.zen.ping.unicast.hosts: ["192.168.3.1"]

*注释:关于单播和多播,为了防止节点的任意加入,官方建议集群关闭多播,使用单播集群。单播列表只要能保证与集群中任一节点能通信即可,不需要列出所有集群节点。

7.elasticsearch常用插件。(head,kopf,bigdesk)
在线安装:
①.安装head插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
②.安装bigdesk插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install hlstudio/bigdesk
③.安装kopf插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
离线安装:
①.安装head插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install file:/elk/soft/elasticsearch-head-master.zip
②.安装bigdesk插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install file:/elk/soft/bigdesk-master.zip
③.安装kopf插件。
[root@node1 ~]# /usr/share/elasticsearch/bin/plugin install file:/elk/soft/elasticsearch-kopf-master.zip
浏览器端访问插件:
http://192.168.3.1:9200/_plugin/head
http://192.168.3.1:9200/_plugin/bigdesk
http://192.168.3.1:9200/_plugin/kopf

8.使用RESTful API操作elasticsearch。
①.索引初始化配置:创建、获取、删除。
初始化配置school索引:

curl -XPUT 'http://192.168.3.1:9200/school/' -d '{
"settings":{
"index":{
"number_of_shards": ,
"number_of_replicas":
}
}
}'

获取索引配置信息:

curl -XGET 'http://192.168.3.1:9200/school/_settings/'
curl -XGET 'http://192.168.3.1:9200/school,index_name/_settings/'
curl -XGET 'http://192.168.3.1:9200/_all/_settings/'

删除索引配置信息:

curl -XDELETE 'http://192.168.3.1:9200/school/'
curl -XDELETE 'http://192.168.3.1:9200/school,index_name/'
curl -XDELETE 'http://192.168.3.1:9200/_all/'

②.创建、更新、删除索引文档。
创建索引文档:

curl -XPUT 'http://192.168.3.1:9200/school/students/1' -d '{
"title": "devops",
"name":{
"first": "guzhang",
"last": "wu"
},
"age":
}'
*注释:school为索引名称,students为文档类型,1为文档ID(可省略)。

获取索引文档(通过source指定字段获取信息):

curl -XGET 'http://192.168.3.1:9200/school/students/1'
curl -XGET 'http://192.168.3.1:9200/school/students/1?_source=name,age'

更新索引文档:

  - 覆盖 意即重新创建
  - _update 使用API更新

curl -XPOST 'http://192.168.3.1:9200/school/students/1/_update' -d '{
"doc":{
"age":
}
}'

删除索引文档:

curl -XDELETE 'http://192.168.3.1:9200/school/students/1'

使用bulk批量创建文档:
官方元数据:
https://www.elastic.co/guide/en/kibana/3.0/snippets/shakespeare.json
https://raw.githubusercontent.com/bly2k/files/master/accounts.zip
导入官方元数据:
[root@node1 ~]# curl -XPOST 'http://192.168.3.1:9200/shakesapear/act/_bulk?pretty' --data-binary @shakespeare.json
[root@node1 ~]# curl -XPOST 'http://192.168.3.1:9200' --data-binary @account.json

使用mget批量获取文档:
mget可以快速的同时检索多个文档。mget API参数是一个docs数组,数组的每个节点定义一个文档的——index、_type、_id元数据。

获取多个索引下文档信息:

curl -XGET 'http://192.168.3.1:9200/_mget' -d '{
"docs":[
{
"_index": "bank",
"_type:": "account",
"_id":
},
{
"_index": "bank",
"_type:": "account",
"_id":
},
{
"_index": "shakespeare",
"_type:": "act",
"_id":
}
]
}'

获取相同索引下多个文档信息,并指定字段获取(_source)。

curl -XGET 'http://192.168.3.1:9200/bank/account/_mget' -d '{
"docs":[
{
"_id": ,
"_source": "age"
},
{
"_id": ,
"_source": "firstname"
}
]
}'

mapping:
映射:创建索引的时候,可以预先定义字段的类型及相关属性。
作用:这样会让索引建立得更加的细致和完善。
分类:静态映射和动态映射。

动态映射:自动根据数据进行相应的映射。
静态映射:自定义字段映射数据类型。

*提示:可以修改如下文件,共用mapping。
/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-elasticsearch-2.7.1-java/lib/logstash/outputs/elasticsearch/elasticsearch-template.json

最新文章

  1. jQuery css3仿游戏网站右键环形菜单
  2. Spring各jar包的作用
  3. node平台截取图片模块——jimp
  4. I am back-电商网站开发&amp;jQuery
  5. 分析Linux内核中进程的调度(时间片轮转)-《Linux内核分析》Week2作业
  6. 搭建turnserver
  7. 漫游kafka实战篇之搭建Kafka开发环境
  8. centos 7 lNMP 安装之php 篇
  9. Java基础知识强化之IO流笔记12:递归之递归解决问题的思想(图解)
  10. OC——网络解析获取图片的应用
  11. nodejs实战:使用原生nodeJs模块实现静态文件及REST请求解析及响应(基于nodejs6.2.0版本,不使用express等webMVC框架 )
  12. js /Date(1550273700000)/ 格式转换
  13. 哆啦A梦欺骗了你!浏览器CSS3测试遭质疑
  14. 30个最常用的Linux系统命令行
  15. VSCode 拓展插件推荐
  16. mac OS X下Java项目环境搭建+IntelliJ IDEA Jrebel插件安装与破解+Office 2016破解版安装
  17. 易出错的bug避免
  18. 如果在 Windows 10 家庭版中使用「远程桌面」
  19. 阿里巴巴开源项目: canal
  20. Mysq性能分析 —— Genral log(普通日志)与 Slow log(慢速日式)

热门文章

  1. datanode启动不了
  2. [WP8.1UI控件编程]Windows Phone XAML页面的编译
  3. 《1Q84》--[日]村上春树
  4. Bootstrap做的HTML页面在本地IE打开正常,放到服务器上显示就不正常了
  5. iphone H5 input type=&quot;search&quot; 不显示搜索 解决办法
  6. FMS Camera对象设置说明
  7. 配置hooks使svn提交后自动同步客户端代码(客户端与服务端在同一台机器上)
  8. java script小结
  9. 3Sum
  10. [CareerCup] 16.5 Semphore 信号旗