RESTful API with JSON over HTTP
創建索引
{
"setting":{
"number_of_shards":5,
"number_of_replicas":1
},
"mappings":{
"man":{
"properties":{
"name":{
"type":"text"
},
"country":{
"type":"keyword"
},
"age":{
"type":"integer"
},
"date":{
"type":"date",
"format":"yyyy-MM-dd HH:mm::ss||yyyy-MM-dd||epoch_millis"
}
}
}
}
}
創建結構
結構化創建 需要利用mappings 結構化關鍵詞。
{
"cs": {
"properties": {
"title": {
"type": "text"
}
}
}
}
插入數據
- 1.指定文檔ID插入
{
"name":"張仁杰",
"country":"China",
"age":30,
"date":"1987-06-01"
}
- 2.自動產生文檔ID插入
{
"name":"張惠",
"country":"China",
"age":28,
"date":"1990-11-01"
}
修改數據
- 1.直接修改
{
"doc":{
"name":"Jack",
"age":31
}
}
- 2.通過腳本方式修改
painless內置的腳本語言
ctx._source.age+=10
ctx上下文
source當前文檔
{
"script":{
"lang":"painless",
"inline":"ctx._source.age-=10"
}
}
{
"script":{
"lang":"painless",
"inline":"ctx._source.age=params.age",
"params":{
"age":"100"
}
}
}
刪除操作
-
1.刪除文檔
- 2.刪除索引
DELETE http://127.0.0.1:9200/people