Marvel插件
Marvel也是Elasticsearch的一个管理监控工具,集head合bigdesk优点于一身。但是Marvel插件不是免费的。
官网介绍: Monitoring: Monitor and Manage Elasticsearch | Elastic
安装:sudo elasticsearch/bin/plugin -install elasticsearch/marvel/latest
访问:http://localhost:9200/_plugin/marvel/
索引初始化
索引初始化操作
创建索引之前可以对索引做初始化操作,比如指定shards数量以及replicas的数量。
#命令行下的索引初始化设置
curl -XPUT 'http://192.168.1.10:9200/library/' -d '{
"settings":{
"index":{
"number_of_shards":5,
"number_of_replicas":1
}
}
}'
#获取索引信息
curl -XGET 'http://192.168.1.10:9200/library/_settings'
curl -XGET 'http://192.168.1.10:9200/library,library2/_settings'
curl -XGET 'http://192.168.1.10:9200/_all/_settings'
#单模式下索引的创建,更新以及删除操作
#初始化索引
#创建索引之前可以对索引做初始化操作
#比如指定shards数量以及replicas的数量
PUT http://192.168.1.10:9200/library/
{
"settings":{
"index":{
"number_of_shards":5,
"number_of_replicas":1
}
}
}
# 上面的number_of_replicas还可以换成:
# blocks.read_only:设为true,则当前索引只允许读,不允许写或更新
#blocks.read:设为true,则禁止读操作
#blocks.write:设为true,则禁止写操作
#blocks.metadata:设为true,则禁止metadata操作(?metadata指的是什么?)
note:以上操作可以在kibana的Dev tools中执行。
#可以通过GET带上参数_settings获得该索引详细的配置信息
GET /library/_settings
#同时获取两个索引的信息
GET /library,library2/_settings
#获取所有索引的信息
GET /_all/_settings
索引文档API CURD(CREATE,UPDATE,RETRIEVE,DELETE)
如何用API创建索引
例:curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{"user":"kimchv","post_date":"2009-11-15T14:12:12","message":"trying out Elasticsearch"}'
#创建一个文档
# |---索引名称
# | |---Type名称
# | | |---文档ID
PUT /library/books/1
{
“title”: "Elasticsearch: The Definitive Guide",
"name":{
"first" : “Zachary”,
“last” : "Tong"
},
"publish_date": "2015-02-06",
"price": "49.99"
}
#ID可以选择不设置,如下
POST /library/books/
{
"title":"Elasticsearch Blueprints",
"name": {
"first":"Vineeth",
"last": "Mohan"
},
"publish_date": "2015-06-06",
"price": "35.99"
}
#通过ID获取文档信息
GET /library/books/1
GET /library/books/2
GET /library/books/{uuid}
#通过_source 获取指定的字段
GET /library/books/1?_source=title
GET /library/books/1?_source=title,price
GET /library/books/1?_source
如何用API更新索引
例:curl -XPOST 'http://localhost:9200/test/type1/1/_update' -d '{"script":"ctr.source.counter+=count","params":{"count":4}}'
#我们更新同一个ID下的文档,可以通过覆盖的方式更新(不推荐)
PUT /library/books/1
{
"title": "Elasticsearch: The Definitive Guide",
"name": {
"first":"Zachary",
"last":"Tong"
},
"publish_date": "2015-02-06",
"price": "59.99"
}
GET /library/books/1
# 或者通过 _update API的方式单独更新你想要更新的
POST /library/books/1/_update
{
"doc": {
"price": 10
}
}
POST /library/books/1/_update{ "doc": { "title": "fly" }}
GET /library/books/1
如何用API删除索引
例:curl -XDELETE 'http://localhost:9200/twitter/tweet/1'
#删除一个文档的方法
DELETE /library/books/1
#删除type
DELETE /library/books
#删除索引
DELETE /library
GET /library/books/1
网友评论