elasticsearch
查看全部索引
GET /_cat/indices
索引文档
PUT /{index}/{type}/{id} { "field": "value", ... }
例如:
PUT /website/blog/123 { "title": "My first blog entry", "text": "Just trying this out...", "date": "2014/01/01" }
取回一个文档
GET /website/blog/123?pretty
返回文档一部分
GET /website/blog/123?_source=title,text
文档检查是否存在(用HEAD请求)
curl -i -XHEAD http://localhost:9200/website/blog/123
更新整个文档
在 Elasticsearch 中文档是 不可改变 的,不能修改它们。相反,如果想要更新现有的文档,需要 重建索引 或者进行替换
PUT /website/blog/123 { "title": "My first blog entry", "text": "I am starting to get the hang of this...", "date": "2014/01/02" }
创建文档
第一种 PUT /website/blog/123?op_type=create { ... } 第二种 PUT /website/blog/123/_create { ... }
删除文档
DELETE /website/blog/123
指定版本更新索引
PUT /website/blog/1?version=1 { "title": "My first blog entry", "text": "Starting to get the hang of this..." }
文档部分更新
POST /website/blog/1/_update { "doc" : { "tags" : [ "testing" ], "views": 0 } }
取回多个文档
GET /_mget { "docs" : [ { "_index" : "website", "_type" : "blog", "_id" : 2 }, { "_index" : "website", "_type" : "pageviews", "_id" : 1, "_source": "views" } ] }
批量操作
POST /my_store/products/_bulk { "index": { "_id": 1 }} { "price" : 10, "productID" : "XHDK-A-1293-#fJ3" } { "index": { "_id": 2 }} { "price" : 20, "productID" : "KDKE-B-9947-#kL5" } { "index": { "_id": 3 }} { "price" : 30, "productID" : "JODL-X-1937-#pV7" } { "index": { "_id": 4 }} { "price" : 30, "productID" : "QQPX-R-3956-#aD8" }
查看字段分词
GET /my_store/_analyze { "field": "productID", "text": "XHDK-A-1293-#fJ3" }
查看映射
通过 /_mapping
,我们可以查看 Elasticsearch 在一个或多个索引中的一个或多个类型的映射。在 开始章节 ,我们已经取得索引 gb
中类型 tweet
的映射:
GET /gb/_mapping/tweet
手动创建索引
PUT /my_index { "settings": { ... any settings ... }, "mappings": { "type_one": { ... any mappings ... }, "type_two": { ... any mappings ... }, ... } }
删除映射
DELETE /my_store
自定义映射
PUT /my_store
{
"mappings" : {
"products" : {
"properties" : {
"productID" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}
}
}
删除一个索引
DELETE /my_index
删除多个索引
DELETE /index_one,index_two
DELETE /index_*
删除所有索引
DELETE /_all DELETE /*