ELasticSearch 文档学习

2020-10-22  本文已影响0人  仓鼠猪儿虫

官网文档学习

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

检查集群运行情况

GET /_cat/health?v
localhost:9200/_cat/health?v

1603273180 09:39:40 docker-cluster green 1 1 0 0 0 0 0 0 - 100.0%
得到集群中的节点列表

GET /_cat/nodes?v
localhost:9200/_cat/nodes?v

  ip         heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
  马赛克           51          95   1    0.10    0.09     0.08 dim       *      a64eb5333b79
查看索引

GET /_cat/indices?v
localhost:9200/_cat/indices?v

  health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
创建索引

PUT /customer?pretty
GET /_cat/indices?v
localhost:9200/customer?pretty
localhost:9200/_cat/indices?v

 health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
 yellow open   customer -0DkB5HuSRyIfXnwIpOb4w   1   1          0            0       230b           230b
添加document到索引中

PUT /customer/doc/1?pretty
localhost:9200/customer/extest/1?pretty
在postman 中 请求方式设置为put
body设置为raw 类型选择json

  {
          "_index": "customer",
          "_type": "extest",
          "_id": "1",
          "_version": 1,
          "result": "created",
          "_shards": {
                             "total": 2,
                              "successful": 1,
                              "failed": 0
                      },
          "_seq_no": 0,
          "_primary_term": 1
}
根据获取docment

GET /customer/doc/1?pretty
localhost:9200/customer/extest/1?pretty

 {
    "_index": "customer",
    "_type": "extest",
    "_id": "1",
    "_version": 1,
    "_seq_no": 0,
    "_primary_term": 1,
    "found": true,
    "_source":
          {
            "name": "John Doe"
          }
  }
删除索引

DELETE /customer?pretty
GET /_cat/indices?v

{
"_index": "customer",
"_type": "extest",
"_id": "1",
"_version": 2,
"result": "deleted",
"_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
     },
"_seq_no": 1,
"_primary_term": 1
}

模式总结如下

<REST Verb> /<Index>/<Type>/<ID>
总结下来 就是 动词 + 索引 + doc + id + pretty(规范输入)
< REST动词> / <索引> / <类型> / < ID >

修改数据

覆盖数据

在已有数据索引上直接覆盖修改
使用上面的添加docment 数据对已有数据的docment 进行更改

更新数据

POST /customer/doc/1/_update?pretty

  {
      "doc": { "name": "Jane Doe", "age": 20 }
  }

更新script 脚本修改

   {
      "script" : "ctx._source.age += 5"
    }

结果

   {
      "_index": "customer",
      "_type": "doc",
      "_id": "2",
      "_version": 3,
      "_seq_no": 4,
      "_primary_term": 1,
      "found": true,
      "_source": {
          "name": "Jane Doe",
          "age": 25
      }
}

使用脚本对 _source 里的age 属性自增5
ctx._source指的是将要更新的当前源文档。

批量处理

参见原文档
https://www.elastic.co/guide/en/elasticsearch/reference/6.0/_batch_processing.html

上一篇下一篇

猜你喜欢

热点阅读