Elastic Search个人学习(2) 基本操作

Elastic Search基本概念

文档 -> document -> 类似于Mysql中的一条数据
索引-> index ->类似于Mysql中的一张表 (ES6过后索引类似于Mysql的一张表,原先类比于一个database)

对Elastic Search的操作是基于Restful标准, 增删改查对应的Method为POST DELETE PUT GET

查询API:
/GET /{indexName}/{typeName}/id

如 /GET /testindex/doc/1 返回的结构体格式为:

{
  "_index" : "testindex",
  "_type" : "doc",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "id" : "1",
    "name" : "shunhao"
  }
}

各字段含义为:

_index: 索引名
_type: 类型名
_version: 该文档版本,每次更新都会使版本+1
_id: 唯一id
_source: 初始的JSON数据
_all: 整个所有字段内容到该字段,默认禁用,占用磁盘空间较大,不推荐使用
found: 是否找到对应文档

新增API:
/POST /{indexName}/{typeName}
jsonData


/POST /testindex/doc
{
“id”:“1”,
“name”:“shunhao”
}

该请求返回的结构体为

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

es将会为你自动生成一个唯一id

此外也可以指定id来生成,语句与更新相同, 为
/PUT/{indexName}/{typeName}/{id}
jsonData

PUT /testindex/doc/1
{
“id”:“1”,
“name”:“shunhao”
}
该语句作用为更新 testindex这个索引下 id为1的数据,若该数据不存在,则新建

删除API:
DELETE /{indexName}/{typeName}/{id}


DELETE /testindex/doc/1
返回的结构体为

{
  "_index" : "testindex",
  "_type" : "doc",
  "_id" : "1",
  "_version" : 2,
  "result" : "deleted",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 2,
  "_primary_term" : 1
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值