4.3ElasticSearch API 和操作索引和数据的增删改查

1.ElasticSearch API 和操作索引

Rest风格的API,即http请求接口

1.1 基本概念

对比关系

索引集(indexs)–Databases数据库

类型(type)—Table数据库表

文档(Document)—Row行

字段(Field)—Columns列

一个索引库里面只有一种类型的文档,对应数据库中一种类型的数据

索引集(indexs):逻辑上的完整索引

分片(shard):数据拆分后的各个部分

副本(replica):每个分片的复制

1.2 创建索引

Elasticsearch采用Rest风格API,因此其API就是一次http请求,你可以用任何工具发起http请求

创建索引的请求格式

  • 请求方式:PUT
  • 请求路径:/索引名称
  • 请求参数:json格式

insomnia请求:

{
	"settings":{
		"number_of_shards":3,  //分片数量
		"number_of_replicas":2 //副本数量
	}
}

返回结果:

{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "heima"
}

表示创建索引成功
在这里插入图片描述

kibana请求:

PUT /heima2
{
  "settings": {
"number_of_shards": 1,
"number_of_replicas": 1
  }
}

返回结果:

{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "heima2"
}

在这里插入图片描述

使用kibana查询索引

请求:

GET heima

返回结果:

{
  "heima": {
"aliases": {},
"mappings": {},
"settings": {
  "index": {
    "creation_date": "1589011560927",
    "number_of_shards": "3",
    "number_of_replicas": "2",
    "uuid": "cuHizgA1Tiaq9sfgO_lYEw",
    "version": {
      "created": "6020499"
    },
    "provided_name": "heima"
      }
}
  }
}

删除hema2

请求:

DELETE heima2

返回结果:

{
  "acknowledged": true
}

在次查询heima2

请求:

GET heima2

返回结果:

{
  "error": {
"root_cause": [
  {
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_or_alias",
"resource.id": "heima2",
"index_uuid": "_na_",
"index": "heima2"
  }
],
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_or_alias",
"resource.id": "heima2",
"index_uuid": "_na_",
"index": "heima2"
  },
  "status": 404
}

1.3.创建映射字段

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值