elasticsearch常用命令备注

时间:2022-10-05 08:21:26

1、检查集群健康状态

  curl 'localhost:9200/_cat/health?v'

elasticsearch常用命令备注

2、检查节点健康状态

  curl 'localhost:9200/_cat/nodes?v'

elasticsearch常用命令备注

3、新增一条索引

  curl -XPUT 'localhost:9200/fred_log?pretty'

4、查询当前索引

  curl 'localhost:9200/_cat/indices?v'

elasticsearch常用命令备注

5、在索引中添加文档,本例中添加如下:

备注:fred_log为索引名称、log为type

curl -XPUT 'localhost:9200/fred_log/log/1?pretty' -d '{"name": "Fredric"}'
curl -XPUT 'localhost:9200/fred_log/log/2?pretty' -d '{"name": "Sinny"}'
curl -XPUT 'localhost:9200/fred_log/log/3?pretty' -d '{"name": "故障企业日志"}'
curl -XPUT 'localhost:9200/fred_log/log/4?pretty' -d '{"name": "业务企业日志"}'
curl -XPUT 'localhost:9200/fred_log/log/5?pretty' -d '{"title": "企业日志", "type":"CRM模块", "content":"管理员添加客户"}'
curl -XPUT 'localhost:9200/fred_log/log/6?pretty' -d '{"title": "企业日志", "type":"CRM模块", "content":"管理员删除客户"}'

elasticsearch常用命令备注

6、查询文档:

  curl -XGET 'localhost:9200/fred_log/log/4?pretty'

  elasticsearch常用命令备注

  curl -XGET 'localhost:9200/fred_log/log/_search' -d '{ "query": { "match": {"name": "企业"}}}'

elasticsearch常用命令备注

  curl -XGET 'localhost:9200/fred_log/log/_search' -d '{"query": {"bool": {"must": [{ "match": { "type": "CRM" }},{ "match": { "content": "删除" }}]}}}'

elasticsearch常用命令备注

备注:若将must改变为should则条件不为必须满足,但可以通过minimum_should_match控制匹配经度