- 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 - Ingest 节点
- Elasticsearch - 索引生命周期管理
- Elasticsearch - SQL访问
- Elasticsearch - 监控
- Elasticsearch - 数据汇总
- Elasticsearch - 冻结索引
- Elasticsearch - 测试
- Elasticsearch - Kibana 仪表盘
- Elasticsearch - 按字段过滤
- Elasticsearch - 数据表
- Elasticsearch - 地区地图
- Elasticsearch - 饼图
- Elasticsearch - 面积图和条形图
- Elasticsearch - 时间序列
- Elasticsearch - 词云
- Elasticsearch - 热力图
- Elasticsearch - Canvas
- 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 或 * 删除所有索引。
获取索引
此API可以通过向一个或多个索引发送GET请求来调用。这将返回有关索引的信息。
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帮助您提取有关特定索引的统计信息。您只需要发送一个带有索引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
运行以上代码后,我们将得到如下所示的输出:
{
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}
广告