- Elasticsearch 教程
- Elasticsearch - 主页
- Elasticsearch - 基本概念
- Elasticsearch - 安装
- Elasticsearch - 填充
- 版本之间的迁移
- Elasticsearch - API 约定
- Elasticsearch - 文档 API
- Elasticsearch - 搜索 API
- Elasticsearch - 聚合
- Elasticsearch - 索引 API
- Elasticsearch - CAT API
- Elasticsearch - 集群 API
- Elasticsearch - 查询 DSL
- Elasticsearch - 映射
- Elasticsearch - 分析
- Elasticsearch - 模块
- Elasticsearch - 索引模块
- Elasticsearch - 摄取节点
- Elasticsearch - 管理索引生命周期
- Elasticsearch - SQL 访问
- Elasticsearch - 监控
- Elasticsearch - 汇总数据
- Elasticsearch - 冻结索引
- Elasticsearch - 测试
- Elasticsearch - Kibana 仪表板
- Elasticsearch - 按字段过滤
- Elasticsearch - 数据表
- Elasticsearch - 区域地图
- Elasticsearch - 饼图
- Elasticsearch - 面积图和条形图
- Elasticsearch - 时间序列
- Elasticsearch - 标签云
- Elasticsearch - 热图
- Elasticsearch - 画布
- Elasticsearch - 日志 UI
- Elasticsearch 有用资源
- Elasticsearch - 快速指南
- Elasticsearch - 有用的资源
- Elasticsearch - 讨论
Elasticsearch - 索引 API
这些 API 负责管理索引的所有方面,如设置、别名、映射、索引模板。
创建索引
该API可帮助您创建索引。当用户将 JSON 对象传递到任何索引时,可以自动创建索引,也可以在此之前创建索引。要创建索引,您只需发送带有设置、映射和别名的 PUT 请求,或者发送一个不带正文的简单请求。
PUT colleges
运行上面的代码,我们得到如下所示的输出 -
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "colleges"
}
我们还可以在上面的命令中添加一些设置 -
PUT colleges
{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
}
运行上面的代码,我们得到如下所示的输出 -
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "colleges"
}
删除索引
该API可帮助您删除任何索引。您只需传递带有该特定索引名称的删除请求。
DELETE /colleges
您可以仅使用 _all 或 * 删除所有索引。
获取索引
只需向一个或多个索引发送 get 请求即可调用此 API。这将返回有关索引的信息。
GET colleges
运行上面的代码,我们得到如下所示的输出 -
{
"colleges" : {
"aliases" : {
"alias_1" : { },
"alias_2" : {
"filter" : {
"term" : {
"user" : "pkay"
}
},
"index_routing" : "pkay",
"search_routing" : "pkay"
}
},
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1556245406616",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "3ExJbdl2R1qDLssIkwDAug",
"version" : {
"created" : "7000099"
},
"provided_name" : "colleges"
}
}
}
}
您可以使用_all或*来获取所有索引的信息。
索引存在
只需向该索引发送 get 请求即可确定该索引是否存在。如果HTTP响应是200,则存在;如果是404,则不存在。
HEAD colleges
运行上面的代码,我们得到如下所示的输出 -
200-OK
索引设置
您只需在 URL 末尾附加 _settings 关键字即可获取索引设置。
GET /colleges/_settings
运行上面的代码,我们得到如下所示的输出 -
{
"colleges" : {
"settings" : {
"index" : {
"creation_date" : "1556245406616",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "3ExJbdl2R1qDLssIkwDAug",
"version" : {
"created" : "7000099"
},
"provided_name" : "colleges"
}
}
}
}
指数统计
此 API 可帮助您提取有关特定索引的统计信息。您只需发送一个 get 请求,并在末尾添加索引 URL 和 _stats 关键字。
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
运行上面的代码,我们得到如下所示的输出 -
{
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}