索引API

  • 查看索引分布情况

      curl http://es:9200/_cat/shards?pretty
    
  • 查看所有索引

      curl -XGET http://es:9200/_cat/indices?pretty
    
  • 删除指定索引

      curl -XDELETE http://es:9200/IndexName
    
  • 索引配置信息

      curl -XGET http://es:9200/IndexName/_settings?pretty
    
  • 取消所有索引只读模式

      curl -XPUT -H "Content-type: application/json" http://es:9200/_settings -d '{
              "index.blocks.read_only_allow_delete":"false"
      }'
    
  • 索引重命名

      curl -XPOST -H "Content-type: application/json" http://es:9200/_reindex -d '{
              "source": {
                      "index": "OldName"
              },
              "dest": {
                      "index": "NewName"
              }        
      }'
    

集群API

  • 修改默认密码

      curl -XPUT -H "Content-type: application/json" -u elastic  'http://es:9200/_xpack/security/user/elastic/_password'  -d '{
              "password" : "NewPassword"
      }'
    
  • 查看集群健康状况

      curl -XGET http://es:9200/_cluster/health?pretty
    
  • 查询集群详细信息

      curl -XGET http://es:9200/_cluster/state?pretty
    
  • 查看集群的节点详细信息

      curl -XGET http://es:9200/_nodes/NodeName?pretty
    
  • 查看阻塞的任务

      curl -XGET http://es:9200/_cluster/pending_tasks?pretty
    

模板API

  • 查看所有模板

      curl -XGET http://es:9200/_template?pretty
    
  • 查看模板详细信息

      curl -XGET http://es:9200/_template/TemplateName?pretty
    
  • 修改模板。

    一般修改模板时,使用原来的模板创建新的,并修改优先值。先通过GET获取到模板,然后将所有内容复制出来,将修改的东西增加进去,修改新模板的order值,值越小,越优先。

      curl -XPUT -H "Content-type: application/json" http://es:9200/_template/TemplateName -d "{
              "order": 2,
              "template": "graylog_*",
              "settings": {
                // 指定由模板生成的索引在指定的节点上,如果没有该节点,则索引会创建失败      
                "index.routing.allocation.include._name": "FullNodeName",      
                "index": {
                   "max_result_window": "2000000",
                },
                ...
              }
    
      }"
    

关于该接口的其他说明:

  1. index.routing.allocation.exclude._name 表示不希望的节点

  2. 这些选项不是强制性的,假如一个节点只允许同一个索引的分片最多有3个,那么如果一个索引它有三个分片,那么这三个分片分按分配规则来分,如果多出的,那就有可能在其他节点上。

  3. 查看分配后的分布情况可以调用/_cat/shards查看验证

搜索 API

  • 检索信息

      curl -XGET http://es:9200/_search?pretty
    
  • 检索指定索引的信息

      curl -XGET http://es:9200/IndexName/_search?pretty
    
  • 检索指定索引指定Type的信息

      curl -XGET http://es:9200/IndexName/TypeName/_search?pretty
    
  • 获取指定ID的文档

      curl -XGET http://es:9200/IndexName/TypeName/ID