kibana dev tools 操作 Elasticsearch

#查询es 集群健康信息
GET /_cluster/health

#查询集群健康信息
GET /_cat/health?v

#查询集群全部索引
GET /_cat/indices?v

#创建索引,使用默认分片数 5 
PUT /school?pretty

#查询文档结构
GET /school

#创建文档
PUT /school/doc/1?pretty
{
  "name":"jony"
}

#查询制定文档
GET /school/doc/1?pretty

#删除索引
DELETE /school?pretty

#创建文档,如果id 存在即覆盖
PUT /school/doc/1?pretty
{
  "name":"jony change",
  "age":25
}

#创建文档
PUT /school/doc/2?pretty
{
  "name":"jony new one",
  "age":26
}

GET /school/doc/2?pretty

#不指定id创建文档
POST /school/doc?pretty
{
  "name":"bob",
  "age":27
}

#查询索引下全部文档
GET /school/_search

#更新文档
POST /school/doc/1/_update?pretty
{
  "doc":{"name":"jone update"}
}

#简单脚本增加年龄+5
POST /school/doc/1/_update?pretty
{
  "script": "ctx._source.age +=5"
}

#删除文档
DELETE /school/doc/XV6B7XcB7WH2WRdVdQ-u?pretty

#带条件查询
GET /school/_search?q=*&sort=age:asc

#使用请求体查询
GET /school/_search
{
  "query": {
    "match_all": {}
  }
  , "sort": [
    {
      "age": "desc"
    }
  ]
}


#使用size ,默认为 10
GET /school/_search
{
  "query": {
    "match_all": {}
  }
  , "size": 1
}

#from size 与数据库 limit 类似
#from 下标从 0 开始闭区间
GET /school/_search
{
  "query": {"match_all": {}}
  , "from": 1
  , "size": 1
}

#https://www.elastic.co/guide/en/elasticsearch/reference/6.0/_executing_searches.html

#返回特定的字段
GET /school/_search
{
  "query": {"match_all": {}}
  , "_source": ["age","name"]
}


# query 返回符合条件的数据 age = 30
GET /school/_search
{
  "query": {
    "match": {
      "age": 30
    }
  }
}

#返回name 中包含 update 的数据
GET /school/_search
{
  "query": {
    "match": {
      "name": "new"
    }
  }
}


#使用 bool 查询 ,must 必须同时满足
GET /school/_search
{
  "query": {
    "bool": {
      "must": [
        {"match": {"name": "new"}},
        {"match": {"age": "26"}}
      ]
    }
  }
}

#bool 查询,任意满足一个
GET /school/_search
{
  "query": {
    "bool": {
       "should": [
         {"match": {"name": "new"}},
         {"match": {"age": "25"}}
       ]
    }
  }
}

#bool 不包含任意下列条件
GET /school/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "match": {
            "age": "26"
          }
        },
        {
          "match": {
            "name": "new"
          }
        }
      ]
    }
  }
}

#bool 组合复杂查询
GET /school/_search
{
  "query": {
    "bool": {
      "must": [
        {"match": {
          "age": 25
        }}
      ],
      "must_not": [
        {"match": {
          "name": "jony2"
        }}
      ]
    }
  }
}

#过滤查询
GET /school/_search
{
  "query": {
    "bool": {
      "must":  {"match_all": {}},
      "filter": {
        "range": {
          "age": {
            "gte": 10,
            "lte": 30
          }
        }
      }
    }
  }
}


#聚合查询
GET /school/_search
{
  "size": 0,
  "aggs": {
    "groub_by_name": {
      "terms": {
        "field": "name.keyword"
      }
    }
  }
}

#获取系统配置
GET _cluster/settings

#修改为自动创建索引
PUT _cluster/settings
{
  "persistent": {
    "action.auto_create_index":"true"
  }
}

#检测文档是否存在
HEAD school/doc/10
原文地址:https://www.cnblogs.com/bytecodebuffer/p/14465431.html