ElasticSearch Rest风格操作(一)索引操作
基本Rest命令说明
method | url地址 | 描述 |
---|---|---|
PUT | 127.0.0.1:9200/索引名称/类型名称/文档id | 创建文档(指定文档id) |
POST | 127.0.0.1:9200/索引名称/类型名称 | 创建文档(随机文档id) |
POST | 127.0.0.1:9200/索引名称/类型名称/文档id/_update | 修改文档 |
DELETE | 127.0.0.1:9200/索引名称/类型名称/文档id | 删除文档 |
GET | 127.0.0.1:9200/索引名称/类型名称/文档id | 查询文档通过文档id |
POST | 127.0.0.1:9200/索引名称/类型名称/_search | 查询所有数据 |
1、创建索引
PUT /test1/type1/1
{
"name":"洪七公",
"age":3
}
2、指定字段的类型
常见字段类型
字符串类型 text , keyword
数值类型 long , integer , short , byte , double , float , half float , scalet float
日期类型 date
布尔类型 boolean
二进制类型 binary
等等 …
举例:执行如下脚本
PUT /test2
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "long"
},
"birthday":{
"type": "date"
}
}
}
}
查看结果:
3、GET命令
GET test2
4、获取健康值
GET _cat/health
5、获取版本信息
GET _cat/indices?v
6、修改
6.1、修改方式1
POST /test1/type1/1
{
"name":"张三丰",
"age":33
}
执行:
查询:
6.2、修改方式2
POST /test1/type1/1/_update
{
"doc":{
"name":"六小龄童"
}
}
7、删除
DELETE test2
特别鸣谢:狂神说Java