ES查询和监控
es安装
参考https://blog.csdn.net/okiwilldoit/article/details/137107087
再安装kibana,在它的控制台里写es查询语句。
es指南
es权威指南-中文版:
kibana用户手册-中文版:
es中文社区
es参考手册API
es客户端API
es查询语句
# 查询es版本 GET / # 查询集群下所有index GET /_cat/indices?v # 查询节点 GET _cat/nodes?format=json # 查询某个index的结构 GET /index_name/_mapping?pretty #查询doc_id=123的详细信息 GET /index_name/_doc/123 # 查询作者为"猫腻"的作品,取出4个字段 GET /index_name/_search { "query" : { "match" : { "authorname" : "猫腻" } }, "_source": ["ID","title","authorname","desc"] }
es bool查询
Bool查询则可以实现查询的组合,并支持多字段查询和精确匹配、模糊匹配、范围匹配等多种查询方式。下面我们来看一下Bool查询的基本语法:
{ "query": { "bool": { "must": [ { "match": { "title": "Search" }}, { "match": { "content": "Elasticsearch" }} ], "filter": [ { "term": { "status": "published" }}, { "range": { "publish_date": { "gte": "2019-01-01" }}} ], "should": [ { "match": { "author": "John" }}, { "match": { "author": "Doe" }} ], "must_not": [ { "match": { "category": "Marketing" }} ] } } }
must:表示必须匹配的条件,相当于AND。
filter:表示过滤条件,可以提高查询效率,相当于WHERE。
should:表示应该匹配的条件,可以有多个,相当于OR。
must_not:表示必须不匹配的条件,相当于NOT。
在这个查询中,必须同时匹配 title 和 content 字段,同时 status 字段必须为 published,publish_date 字段必须大于等于 2019-01-01,并且 author 字段必须匹配 John 或者 Doe 中的至少一个,同时 category 字段不能匹配 Marketing
ES SQL
6.3版本后支持SQL,但是不支持join等复杂操作。
https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-spec.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-search-api.html
POST _sql?format=txt { "query": "SELECT author, title FROM index_name WHERE MATCH(title, '猎鬼') ORDER BY updateTime DESC LIMIT 100" }
ES监控
通过kibana可以看到es的监控信息,包括每个索引的查询耗时等。