# 查看全部节点 http://192.168.188.128:9200/_cat/nodes # 查看 es 健康情况 http://192.168.188.128:9200/_cat/health # 查看主节点 http://192.168.188.128:9200/_cat/master # 查看全部索引 http://192.168.188.128:9200/_cat/indices
PUT customer/external/1;在 customer 索引下的 external 类型下保存 1 号数据为node
# put 保存数据 http://192.168.188.128:9200/customer/external/1 { //元数据 "_index": "customer", //类型 "_type": "external", //id "_id": "1", //版本信息 "_version": 1, //create:新建的数据 updated:更新数据 "result": "updated", //分片 "_shards": { "total": 2, "successful": 1, "failed": 0 }, "_seq_no": 2, "_primary_term": 5 } # post保存数据 http://192.168.188.128:9200/customer/external/
POST 新增: 若是不指定 id,会自动生成 id。 指定 id 就会修改这个数据,并新增版本号 PUT 能够新增能够修改。 PUT 必须指定 id; 因为 PUT 须要指定id,咱们通常都用来作修改操做,不指定 id 会报错。
# 获取信息 http://192.168.188.128:9200/customer/external/1 { //索引 "_index": "customer", //类型 "_type": "external", //记录 id "_id": "1", //版本号 "_version": 2, //并发控制字段,每次更新就会+1,用来作乐观锁 "_seq_no": 2, //同上,主分片从新分配,如重启,就会变化 "_primary_term": 5, "found": true, //保存的信息 "_source": { "name": "Jack Deon" } }
# POST更新 //进行更新前,会比较新数据和老数据的区别;若无改变则不进行更新 version、_seq_no不发生改变 http://192.168.188.128:9200/customer/external/1/_update 请求的JSON信息: { "doc":{ "name": "John" } } # POST更新 //进行更新前,不会比较新、老数据。 //若想比较 则使用doc括起来 http://192.168.188.128:9200/customer/external/1 请求的JSON信息: { "name": "John Doe2" } # PUT更新 //PUT更新(不带_update) 都会直接更新数据 http://192.168.188.128:9200/customer/external/1 请求的JSON信息: { "name": "John Doe2" } # 更新同时增长属性 ## POST更新同时增长属性 http://192.168.188.128:9200/customer/external/1/_update 请求的JSON信息: { "doc": { "name": "Jane Doe", "age": 20 } } ## PUT更新同时增长属性 http://192.168.188.128:9200/customer/external/1 请求的JSON信息: { "name": "Jane Doe", "age": 20 } PUT 和 POST 不带_update 也能够
不一样:POST 操做会对比源文档数据,若是相同不会有什么操做,文档version不增长PUT操做总会将数据从新保存并增长 version 版本; 带_update 对比元数据若是同样就不进行任何操做。看场景; 对于大并发更新,不带 update; 对于大并发查询偶尔更新,带 update;对比更新,从新计算分配规则。
# 删除一条数据 http://192.168.188.128:9200/customer/external/1 # 删除索引 http://192.168.188.128:9200/customer
使用kibanagit
# kibana dev tools执行 POST customer/external/_bulk {"index":{"_id":"1"}} {"name":"John Doe"} {"index":{"_id":"2"}} {"name":"Jane Doe"} # kibana delete|create|update操做 POST /_bulk {"delete":{"_index":"website","_type":"blog","_id":"123"}} {"create":{"_index":"website","_type":"blog","_id":"123"}} {"title":"My first blog post"} {"index":{"_index":"website","_type":"blog"}} {"title":"My second blog post"} {"update":{"_index":"website","_type":"blog","_id":"123"}} {"doc":{"title":"My updated blog post"}} # 样本测试数据 https://github.com/elastic/elasticsearch/blob/master/docs/src/test/resources/accounts.json # POST请求 POST /bank/account/_bulk 请求的JSON信息: { 从上面网址获取JSON串 }