ElasticSearch head就是一款能连接ElasticSearch搜索引擎,并提供可视化的操作页面对ElasticSearch搜索引擎进行各种设置和数据检索功能的管理插件,如在head插件页面编写RESTful接口风格的请求,就可以对ElasticSearch中的数据进行增删改查、创建或者删除索引等操作。类似于使用navicat工具连接MySQL这种关系型数据库,对数据库做操作。
Elasticsearch Head插件
插件安装
安装链接:https://chrome.google.com/webstore/detail/multi-elasticsearch-head/cpmmilfkofbeimbmgiclohpodggeheim?hl=zh-CN
git地址:https://github.com/mobz/elasticsearch-head
打开head后效果
集群健康值。Elasticsearch 中其实有专门的衡量索引健康状况的标志,分为三个等级:
- green,绿色。这代表所有的主分片和副本分片都已分配。你的集群是 100% 可用的。
- yellow,黄色。所有的主分片已经分片了,但至少还有一个副本是缺失的。
- red,红色。至少一个主分片以及它的全部副本都在缺失中。
基本查询
检索关键字
must子句
文档必须匹配must所有子句查询
should子句
文档应该匹配should子句查询的至少一个
must_not子句
文档不能匹配该查询条件,相当于“!=”
3.2 检索条件
- match:分词匹配
- term:表示精确匹配
- wildcard:通配符匹配
- prefix:前缀匹配
- range:区间查询
- query_string:允许在单个查询字符串中指定AND
- text:文本
- missing: 无值(类似于sql中IS NULL)
复合查询
ES以RESTful接口风格的请求,使用json进行复杂的查询。请求格式:http://ip:port/索引/类型/文档Id
查询数据(GET)
{index}/{type}/{id}
查询官方文档:https://www.elastic.co/guide/cn/elasticsearch/guide/current/query-dsl-intro.html
插入数据(PUT、POST)
PUT方法需要指明id
POST方法自动生成id
更新数据(PUT)
删除数据(DELETE)
给索引添加字段
创建索引
创建mapping
{
"wechat_data": {
"dynamic": "false",
"properties": {
"wechat_id": {
"store": true,
"type": "keyword"
},
"creator": {
"store": true,
"type": "keyword"
},
"groupId": {
"store": true,
"type": "keyword"
},
"description": {
"analyzer": "standard",
"type": "text"
},
"insert_time": {
"format": "yyyy-MM-dd HH:mm:ss",
"store": true,
"type": "date"
},
"reading": {
"store": true,
"type": "integer"
},
"auto_id": {
"store": true,
"type": "long"
},
"createDate": {
"format": "yyyy-MM-dd HH:mm:ss",
"store": true,
"type": "date"
}
}
}
}
总结
Elasticsearch Head插件直接在chrome浏览器安装后就可以使用,非常方便,对于初学者大有益处,使用head插件可以快速实现ES索引数据的增删改查、创建或者删除索引等操作。