elasticsearch--(一)
1. 启动运行
解压elasticsearch-1.7.2.tar.gz 后进入bin目录
启动 ./elasticsearch -d 后台启动
访问:http://10.10.10.73:9200/
vim elasticsearch.yml
(1) cluster.name 集群名称
(2) node.name 节点名称
(3) network.host 本机ip
(4) 添加脑裂配置
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping_timeout: 120s
client.transport.ping_timeout: 60s
discovery.zen.ping.unicast.hosts: ["192.168.57.4","192.168.57.5", "192.168.57.6"]
(5)启动
-
这是出于系统安全考虑设置的条件。由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑,
建议创建一个单独的用户用来运行ElasticSearch -
创建elsearch用户组及elsearch用户
groupadd elsearch useradd elsearch -g elsearch -p elasticsearch
-
更改elasticsearch文件夹及内部文件的所属用户及组为elsearch:elsearch
cd /opt chown -R elsearch:elsearch elasticsearch
-
切换到elsearch用户再启动
su elsearch cd elasticsearch/bin ./elasticsearch
2. 安装kibana 插件
解压kibana-4.4.1-linux-x64 进入/home/insbook/kibana-4.4.1-linux-x64/config
vim kibana.xml
elasticsearch.url: "http://10.10.10.75:9200" 指向集群中的任意节点即可
(1) bin/kibana plugin --install elasticsearch/marvel/latest
3. elasticsearch-2.2.0 插件安装
(1) bin/plugin install license
(2) bin/plugin install marvel-agent
4. 2、3步骤后重启es 和kibana
2. 安装head 插件
(1)bin目录下命令安装 ./plugin -install mobz/elasticsearch-head
(2)手动安装
3. Bigdesk
bin目录下命令安装 ./plugin -install lukas-vlcek/bigdesk/2.5.0
访问:http://10.10.10.73:9200/_plugin/bigdesk/#nodes
4. Mavel 插件
一个管理监控工具,集head和bigdesk优点为一身 收费
bin目录下命令安装 ./plugin -install elasticsearch/marvel/latest
访问:http://10.10.10.73:9200/_plugin/bigdesk/#nodes
5. 索引维护
GET _search { "query": { "match_all": {} } } #初始化索引 PUT http://10.10.10.73:9200/y2 { "settings": { "index":{ "number_of_shars":5, "mumber_of_replicas":1 } } } GET /y2/_settings GET /y2,y1/_settings GET /_all/_settings PUT /library/books/2 { "title":"t2", "name":{ "first":"f2", "last":"l2" }, "publist_data":"2017-15-78", "price":"50" } PUT /library/books { "title":"t5", "name":{ "first":"f5", "last":"l5" }, "publist_data":"2017-15-78", "price":"50" } GET /library/books/1 GET /library/books/1?_source=title GET /library/books/1?_source=title,price GET /library/books/1?_source=name POST /library/books/1/_update { "doc":{ "first":"f11" } } DELETE /library/books/1
批量获取
GET /_mget { "docs" : [ { "_index":"library", "_type":"books", "_id":2 }, { "_index":"library", "_type":"books", "_id":3 } ] } GET /_mget { "docs" : [ { "_index":"library", "_type":"books", "_id":2, "_source":"title" }, { "_index":"library", "_type":"books", "_id":3, "_source":"price" } ] } GET /_mget { "docs" : [ { "_index":"library", "_type":"books", "_id":2, "_source":"title" }, { "_index":"library", "_type":"books", "_id":3, "_source":["price","title"] } ] } #获取相同index相同type下不同id的文档 GET /library/books/_mget { "docs":[ {"_id":2}, {"_id":3} ] } #也可以简写 GET /library/books/_mget { "ids":["2","5"] }
批量操作
POST /library/books/_bulk {"index":{"_id":10}} {"title":"yuwen","price":10} {"index":{"_id":11}} {"title":"shuxue","price":11} {"index":{"_id":12}} {"title":"yingyu","price":12} {"index":{"_id":13}} {"title":"wuli","price":13} GET /library/books/_mget { "ids":["10","11","12","13"] }
POST /library/books/_bulk {"delete":{"_index":"library","_type":"books","_id":"10"}} {"create":{"_index":"music","_type":"classical","_id":"14"}} {"title":"love you"} {"index":{"_index":"music","_type":"classical","_id":"15"}} {"title":"love me"} {"update":{"_index":"library","_type":"books","_id":"11"}} {"doc":{"price":"100"}}
映射的属性和方法
# 建立映射 POST /library { "settings": { "number_of_shards": 5, "number_of_replicas": 1 }, "mappings": { "books": { "properties": { "title": { "type": "string"}, "name": { "type": "string", "index": "not_analyzed"}, "publish_date": {"type": "date", "index": "not_analyzed"}, "price": {"type": "double"}, "number": {"type": "integer"} } } } } # 动态映射 PUT /library { "mappings": { "books": { "dynamic": "strict", "properties": { "title": { "type": "string" }, "name": { "type": "string", "index": "not_analyzed"}, "publish_date": {"type": "date", "index": "not_analyzed"}, "price": {"type": "double"}, "number": { "type": "object", "dynamic": true } } } } } GET /library/ # 获取某个索引的映射信息 GET /library/_mapping GET /bank/_mapping/ # 获取某个索引下某个type的映射信息 GET /library/_mapping/books # 获取这个集群内所有的映射信息 GET /_all/_mapping # 获取这个集群内某两个或多个type的映射信息 GET /_all/_mapping/books,bank_account # 更新修改Mapping映射 # 很遗憾,mapping一旦建立,就不能修改现有的字段映射 # 如果要推倒现有的映射,你得重新建立一个索引,然后重新定义映射 # 然后把之前索引里的数据导入到新建立的索引里 # ---------具体的方法---------- # 1. 给现有的索引定义一个别名,并且把现有的索引指向这个别名,运行步骤2 # 2. 运行 : PUT /现有索引/_alias/别名A # 3. 新创建一个索引,定义好最新的映射 # 4. 将别名指向新的索引,并且取消之前索引的指向,运行步骤5 # 5. 运行: POST /_aliases # { # "actions": [ # { "remove": { "index": "现有索引名", "alias": "别名A" }}, # { "add": { "index": "新建索引名", "alias": "别名A" }} # ] # } # # 注:通过这几个步骤就实现了索引的平滑过度,并且是零停机的 # #删除映射 DELETE /library/books DELETE /library/books/_mapping DELETE /library/_mapping/books,bank