0
点赞
收藏
分享

微信扫一扫

Rest风格---ElasticSearch


Rest风格

5.1 简介

RESTful是一种架构的规范与约束、原则,符合这种规范的架构就是RESTful架构。

操作

method

url地址

描述

PUT

localhost:9100/索引名称/类型名称/文档id

创建文档(指定id)

POST

localhost:9100/索引名称/类型名称

创建文档(随机id)

POST

localhost:9100/索引名称/文档类型/文档id/_update

修改文档

DELETE

localhost:9100/索引名称/文档类型/文档id

删除文档

GET

localhost:9100/索引名称/文档类型/文档id

查询文档通过文档id

POST

localhost:9100/索引名称/文档类型/_search

查询所有文档

5.2 测试


  • 1、创建一个索引​​PUT /索引名/类型名/id​
  • 默认是_doc

Rest风格---ElasticSearch_索引

数据类型

  1. 基本数据类型

  • 字符串 text, keyword
  • 数据类型 long, integer,short,byte,double,float,half_float,scaled_float
  • 日期 date
  • 布尔 boolean
  • 二进制 binary

  1. 制定数据类型

创建规则

PUT /test2
{
"mappings": {

"properties": {
"name": {
"type": "text"
},
"age": {
"type": "long"
},
"birthday": {
"type": "date"
}
}
}
}

输出:

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

如果不指定具体类型,es会默认配置类型

查看索引


GET test2


  • 查看es信息
    get _cat/

修改

1. 之前的办法:直接put
2. 现在的办法:
POST /test1/_doc/1/_update
{
"doc": {
"name": "庞世宗"
}
}

删除索引


DELETE test1




举报

相关推荐

0 条评论