[學習ES系列]-3.ElasticSearch基礎交互
阿新 • • 發佈:2019-01-21
code lock keyword 結構 ams mil int 語言 last RESTful API with JSON over HTTP
創建索引
PUT http://127.0.0.1:9200/people
{ "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 結構化關鍵詞。
POST http://127.0.0.1:9200/book/cs/_mappings
{
"cs": {
"properties": {
"title": {
"type": "text"
}
}
}
}
插入數據
- 1.指定文檔ID插入
PUT http://127.0.0.1:9200/people/man/1
{
"name":"張仁傑",
"country":"China",
"age":30,
"date":"1987-06-01"
}
- 2.自動產生文檔ID插入
POST http://127.0.0.1:9200/people/man
{
"name":"張惠",
"country":"China",
"age":28,
"date":"1990-11-01"
}
修改數據
- 1.直接修改
POST http://127.0.0.1:9200/people/man/1/_update
{
"doc":{
"name":"Jack",
"age":31
}
}
- 2.通過腳本方式修改
painless內置的腳本語言
ctx._source.age+=10
ctx上下文
source當前文檔
POST http://127.0.0.1:9200/people/man/1/_update
{
"script":{
"lang":"painless",
"inline":"ctx._source.age-=10"
}
}
{
"script":{
"lang":"painless",
"inline":"ctx._source.age=params.age",
"params":{
"age":"100"
}
}
}
刪除操作
-
1.刪除文檔
DELETE http://127.0.0.1:9200/people/man/1
- 2.刪除索引
DELETE http://127.0.0.1:9200/people
[學習ES系列]-3.ElasticSearch基礎交互