美文网首页
ES操作(基本操作)

ES操作(基本操作)

作者: 我是嘻哈大哥 | 来源:发表于2018-09-23 18:27 被阅读374次

1.创建索引

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

返回值:

health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   customer 95SQ4TSUT7mWBT7VNHH67A   5   1          0            0       260b           260b

2.插入一条数据

PUT /customer/_doc/1?pretty
{
  "name": "John Doe"
}

返回值:

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

3.删除索引

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

返回值:

health status index uuid pri rep docs.count docs.deleted store.size pri.store.size

4.修改数据,直接输入依据id覆盖

PUT /customer/_doc/1?pretty
{
  "name": "John Doe"
}

5.更新文档
(1)修改name字段为“Jane Doe”

POST /customer/_doc/1/_update?pretty
{
  "doc": { "name": "Jane Doe" }
}

(2)通过将name字段更改为“Jane Doe”并同时向其添加一个age字段,更新我们以前的文档(ID为1)

POST /customer/_doc/1/_update?pretty
{
  "doc": { "name": "Jane Doe", "age": 20 }
}

(3)还可以使用简单的脚本执行更新。这个例子使用一个脚本将年龄增加5

POST /customer/_doc/1/_update?pretty
{
  "script" : "ctx._source.age += 5"
}

6.删除文档
删除我们之前的文档,ID为2

DELETE /customer/_doc/2?pretty

7.批量处理
(1)在一个批量操作中调用索引两个文档(ID 1 - John Doe和ID 2 - Jane Doe)

POST /customer/_doc/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }

(2)更新第一个文档(ID为1),然后在一次批量操作中删除第二个文档(ID为2)

POST /customer/_doc/_bulk?pretty
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}

8、postman批量导入json文件


导入json

相关文章

  • ES操作(基本操作)

    1.创建索引 返回值: 2.插入一条数据 返回值: 3.删除索引 返回值: 4.修改数据,直接输入依据id覆盖 5...

  • ES文档基本操作

    本文主要介绍了ES文档的基本操作 插入 es可以指定id存储,也可以不指定id自动生成。自动生成的id是 URL-...

  • Day102-ELK-ES集群

    1.ElasticSearch基本使用2.ES单机安装:3.ES索引基本操作4.ES集群环境搭建5.cerebro...

  • elasticsearch的概念与基本操作

    一、es索引的基本操作 1、文档 es官方文档[https://www.elastic.co/guide/cn/e...

  • ES7.9基本操作

    /** 索引操作 @throws IOException */ /*** *文档操作 */ //添加文档 //获取...

  • ES文档的基本操作

    1.CRUD基本操作 1.1 CREATE(创建) 支持自动生成文档ID和指定文档ID两种方式。post /ind...

  • ES 索引的基本操作

    1 介绍 主要介绍索引请求的基础API操作,使用postman进行请求,接口请求的前缀地址统一为elasticse...

  • ES 文档的基本操作

    1 介绍 主要介绍索引请求的基础API操作,使用postman进行请求,接口请求的前缀地址统一为elasticse...

  • ES _bulk 批量操作用法

    es版本:7.6 es 的 bulk 操作,是用来批量发送请求,或者理解为批量操作的。 支持4种操作 bulk 支...

  • ES操作

    查询有哪些索引 创建索引 关闭和打开索引在处理elasticsearch的时候,通常需要不断地调整索引的配置,以期...

网友评论

      本文标题:ES操作(基本操作)

      本文链接:https://www.haomeiwen.com/subject/ptdhgftx.html