建立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"
}'
$ curl -X GET http://192.168.122.161:9200/user/_search
$ 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 協議》,轉載必須註明作者和本文連結