elasticsearch -- 索引操作

简历

主要描述索引的增、删、改、查 和 持久化

原文链接:https://www.cainiaojc.com/elasticsearch/elasticsearch-index-apis.html

 

增/创建索引

只需要发送带有设置,映射和别名的PUT请求,或者仅发送不带正文的简单请求。

PUT colleges

返回:

{
   "acknowledged" : true,
   "shards_acknowledged" : true,
   "index" : "colleges"
}

示例:

http://101.132.42.187:9200/names

返回:

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "names"
}

 

第二种:带设置的

PUT colleges
{
  "settings" : {
      "index" : {
         "number_of_shards" : 3,
         "number_of_replicas" : 2
      }
   }
}

示例:

 

删除索引

只需要传递带有该特定索引名称的删除请求即可。

DELETE /colleges

您可以仅使用_all或*删除所有索引。

示例:(删除指定索引)

删除多个以逗号分隔。

 

获取索引

可以通过仅将get请求发送到一个或多个索引来调用此API。这将返回有关索引的信息。

GET colleges

示例:(获取多个)

 

获取索引设置

只需在网址末尾附加_settings关键字即可获取索引设置。

GET /colleges/_settings

示例:

 

索引统计

只需要在末尾发送带有索引URL和_stats关键字的get请求。

GET /_stats

返回:

………………………………………………
},
   "request_cache" : {
      "memory_size_in_bytes" : 849,
      "evictions" : 0,
      "hit_count" : 1171,
      "miss_count" : 4
   },
   "recovery" : {
      "current_as_source" : 0,
      "current_as_target" : 0,
      "throttle_time_in_millis" : 0
   }
} ………………………………………………

 

示例:

 

冲洗/持久化

索引的刷新过程可确保当前仅保留在事务日志中的所有数据也将永久保留在Lucene中。这减少了恢复时间,因为在打开Lucene索引之后,不需要从事务日志中重新索引数据。

POST colleges/_flush

示例:

 

posted @ 2022-07-20 15:47  萤huo虫  阅读(50)  评论(0编辑  收藏  举报