Head 插件使用
创建index 索引
- 首先创建一个 index
$ curl -X PUT http://192.168.122.161:9200/user {
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
},
"mappings": {
"dynamic": "false",
"properties": {
"uname": {
"type": "keyword"
},
"passwd": {
"type":"keyword",
"index":false
},
"introduce": {
"type": "text"
},
"createtime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
}
}
}
}
- 插入数据
$ curl -X POST http://192.168.122.161:9200/user/_doc -d '{
"uname": "admin",
"passwd": "123456",
"introduce": "勇敢 坚强 正直",
"createtime": "2021-06-26 10:00:00"
}'
$ curl -X POST http://192.168.122.161:9200/user/_doc -d '{
"uname": "zhangsan",
"passwd": "111111",
"introduce": "勇敢 果断 正义",
"createtime": "2021-06-26 11:00:00"
}'
$ curl -X POST http://192.168.122.161:9200/user/_doc -d '{
"uname": "lisi",
"passwd": "111111",
"introduce": "聪明 坚强 善良",
"createtime": "2021-06-26 12:00:00"
}'
- 创建 type 和 插入数据(put)
- post 可以插入没有 id 的数据,每次都会当作新数据插入
- put 插入的时候必须指定 id,update or add
$ curl -X PUT http://192.168.122.161:9200/user/_doc/1 -d '{
"uname": "wangwu",
"passwd": "333333",
"introduce": "聪明 坚强 善良",
"createtime": "2021-06-26 12:30:00"
}'
- 查询数据信息
# 查询index
$ curl -X GET http://192.168.122.161:9200/user/_search
# 按照 id 查询文档
$ curl -X GET http://192.168.122.161:9200/user/_doc/1
# 查询指定的列
$ curl -X GET http://192.168.122.161:9200/user/_doc/1 -d {
"source": {
"includes": ["uname","introduce"],
"excludes":["passwd"]
}
}
- 修改数据
# 局部替换
$ curl -X PUT http://192.168.122.161:9200/user/_doc/1 -d {"uname":"test"}
$ curl -X POST http://192.168.122.161:9200/user/_doc/1/_update -d {"uname":"test"}
- 删除数据
$ curl -X DELETE http://192.168.122.161:9200/user/_doc/1
本作品采用《CC 协议》,转载必须注明作者和本文链接