elasticsearch REST api
========================================
命令模式:<REST Verb> /<Index>/<Type>/<ID>
插入索引
------------
PUT /customer?pretty
查詢索引列表
-------------
GET /_cat/indices?v
給索引插入文檔
-----------------------
PUT /customer/external/1?pretty
{
"name": "John Doe"
}
查詢文檔
---------------
GET /customer/external/1?pretty
刪除索引
------------
DELETE /customer?pretty
修改文檔
-------------
若是index/type/id 相同,就會替換文檔
PUT /customer/external/1?pretty
{
"name": "Jane Doe"
}
不指定ID插入文檔
----------------------
POST /customer/external?pretty
{
"name": "Jane Doe"
}
更新文檔
---------------
POST /customer/external/1/_update?pretty
{
"doc": { "name": "Jane Doe", "age": 20 }
}
POST /customer/external/1/_update?pretty
{
"script" : "ctx._source.age += 5"
}
批量操做
------------
POST /customer/external/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
POST /customer/external/_bulk?pretty
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
根據索引查詢
-----------------
GET /bank/_search
{
"query": { "match_all": {} },
"size": 1
}
GET /bank/_search
{
"query": { "match_all": {} },
"from": 10,
"size": 10
}
GET /bank/_search
{
"query": { "match_all": {} },
"sort": { "balance": { "order": "desc" } }
}
api
刪除舊的日誌elasticsearch
-----------------------日誌
POST /*/_delete_by_query
{
"query": {
"range": {
"@timestamp": {
"lt": "now-10d"
}
}
}
}索引