1、索引管理
1.1、索引创建
创建索引主要设置主分片及副分片数量。索引创建后,主分片数不能更改,可以修改副本分片数。
请求格式:
PUT /{索引名}
{
"settings":{
"number_of_shards":{主分片数},
"number_of_replicas":{副本分片数}
}
}
示例:
PUT /city
{
"settings":{
"number_of_shards":1,
"number_of_replicas":1
}
}
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "city"
}
1.2、索引删除
请求格式:
DELETE /{索引名}
1.3、获取索引
请求格式:
GET /{索引名}
1.4、打开/关闭索引
关闭的索引只能显示索引元数据信息,不能进行读写操作。
请求格式:
POST /{索引名}/_close
POST /{索引名}/_open
1.5、修改索引配置
修改索引只可修改副本分片数。
请求格式:
PUT /{索引名}/_settings
{
"settings":{
"number_of_replicas":{副本分片数}
}
}
示例:
PUT /city/_settings
{
"settings":{
"number_of_replicas":0
}
}
1.6、获取配置
请求格式:
GET /{索引名}/_settings
示例:
GET /city/_settings
{
"city" : {
"settings" : {
"index" : {
"creation_date" : "1585405501997",
"number_of_shards" : "1",
"number_of_replicas" : "0",
"uuid" : "eOpl1nAIQfyXLdfXCFliKg",
"version" : {
"created" : "7060099"
},
"provided_name" : "city"
}
}
}
}
1.7、索引别名
Elasticsearch中可以对一个或多个索引指定别名,通过别名可以查询到一个或多个索引。Elasticsearch会自动将别名映射到对应的索引上。可以对别名编写过滤器或路由,集群中的别名不能重复,也不能和索引名重复。
命令格式:
POST /_aliases
{
"actions":
{
"{add或remove}":{"index":"{索引名}","alias":"{别名}"}
}
}
示例:
创建别名:
POST /_aliases
{
"actions":
{
"add":{"index":"city","alias":"mycity"}
}
}
删除别名:
POST /_aliases
{
"actions":
{
"remove":{"index":"city","alias":"mycity"}
}
}
关联多个索引:
POST /_aliases
{
"actions": [
{
"add": {
"index": "city",
"alias": "myindex"
}
},
{
"add":{
"index": "people",
"alias": "myindx"
}
}
]
}
关联多个索引:
POST /_aliases
{
"actions": [
{
"add": {
"indices": ["city","people"],
"alias": "myindex"
}
}
]
}
1.8、别名过滤器及路由
可以给别名创建一个过滤器或是设置路由,过滤器或路由规则适用于索引的搜索、计数、查询、删除等操作。创建过滤时需确保对应字段在映射中存在。
带过滤器别名:
POST /_aliases
{
"actions": [
{
"add": {
"index": "people",
"alias": "alias1",
"filter": {"term": {
"country": "中国"
}}
}
}
]
}
带路由别名:
POST /_aliases
{
"actions": [
{
"add": {
"index": "people",
"alias": "alias1",
"routing": 1
}
}
]
}
指定搜索路由和查询路由:
POST /_aliases
{
"actions": [
{
"add": {
"index": "people",
"alias": "alias1",
"search_routing": "1,2",
"index_routing": "1"
}
}
]
}
1.9、查询别名
查询格式:
GET /{索引名}/_alias/{别名}
示例:
查询索引别名:
GET /_alias/
查询索引的别名:
GET /people/_alias
GET /people/_alias/ali*
GET /people/_alias/*
查询别名对应的索引:
GET /_alias/alias1
1.10、测试分析器
分析器会将文本分析成单独的词,并对这些词建立倒排索引。
POST /_analyze
{
"analyzer": "ik_smart",
"text": "我是中国人!"
}
{
"detail" : {
"custom_analyzer" : false,
"analyzer" : {
"name" : "org.wltea.analyzer.lucene.IKAnalyzer",
"tokens" : [
{
"token" : "我",
"start_offset" : 0,
"end_offset" : 1,
"type" : "CN_CHAR",
"position" : 0,
"bytes" : "[e6 88 91]",
"positionLength" : 1,
"termFrequency" : 1
},
{
"token" : "是",
"start_offset" : 1,
"end_offset" : 2,
"type" : "CN_CHAR",
"position" : 1,
"bytes" : "[e6 98 af]",
"positionLength" : 1,
"termFrequency" : 1
},
{
"token" : "中国人",
"start_offset" : 2,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 2,
"bytes" : "[e4 b8 ad e5 9b bd e4 ba ba]",
"positionLength" : 1,
"termFrequency" : 1
}
]
}
}
}
1.11、索引模板
索引模板就是创建好一个索引参数配置(settings)和映射(mapping)的模板,在创建新索引的时候指定模板名称即可治愈模板定义好的参数设置和映射。
PUT /_template/logtemplate
{
"template": "log-*",
"order": 1,
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"aliases": {"myindex":{}}
}
2、索引监控
2.1、索引统计信息
索引统计信息提供索引中不同内容的统计数据。
命令格式:
GET /{索引名}/_stats
命令示例:
GET /_stats
GET /people/_stats
{
"_shards" : {
"total" : 6,
"successful" : 3,
"failed" : 0
},
"_all" : {
"primaries" : {
"docs" : {
"count" : 4,
"deleted" : 0
},
"store" : {
"size_in_bytes" : 16172
},
"indexing" : {
"index_total" : 0,
"index_time_in_millis" : 0,
"index_current" : 0,
"index_failed" : 0,
"delete_total" : 0,
"delete_time_in_millis" : 0,
"delete_current" : 0,
"noop_update_total" : 0,
"is_throttled" : false,
"throttle_time_in_millis" : 0
},
"get" : {
"total" : 1,
"time_in_millis" : 0,
"exists_total" : 1,
"exists_time_in_millis" : 0,
"missing_total" : 0,
"missing_time_in_millis" : 0,
"current" : 0
},
"search" : {
"open_contexts" : 0,
"query_total" : 0,
"query_time_in_millis" : 0,
"query_current" : 0,
"fetch_total" : 0,
"fetch_time_in_millis" : 0,
"fetch_current" : 0,
"scroll_total" : 0,
"scroll_time_in_millis" : 0,
"scroll_current" : 0,
"suggest_total" : 0,
"suggest_time_in_millis" : 0,
"suggest_current" : 0
},
"merges" : {
"current" : 0,
"current_docs" : 0,
"current_size_in_bytes" : 0,
"total" : 0,
"total_time_in_millis" : 0,
"total_docs" : 0,
"total_size_in_bytes" : 0,
"total_stopped_time_in_millis" : 0,
"total_throttled_time_in_millis" : 0,
"total_auto_throttle_in_bytes" : 62914560
},
"refresh" : {
"total" : 6,
"total_time_in_millis" : 0,
"external_total" : 6,
"external_total_time_in_millis" : 0,
"listeners" : 0
},
"flush" : {
"total" : 3,
"periodic" : 0,
"total_time_in_millis" : 0
},
"warmer" : {
"current" : 0,
"total" : 3,
"total_time_in_millis" : 0
},
"query_cache" : {
"memory_size_in_bytes" : 0,
"total_count" : 0,
"hit_count" : 0,
"miss_count" : 0,
"cache_size" : 0,
"cache_count" : 0,
"evictions" : 0
},
"fielddata" : {
"memory_size_in_bytes" : 0,
"evictions" : 0
},
"completion" : {
"size_in_bytes" : 0
},
"segments" : {
"count" : 4,
"memory_in_bytes" : 4884,
"terms_memory_in_bytes" : 3108,
"stored_fields_memory_in_bytes" : 1248,
"term_vectors_memory_in_bytes" : 0,
"norms_memory_in_bytes" : 256,
"points_memory_in_bytes" : 0,
"doc_values_memory_in_bytes" : 272,
"index_writer_memory_in_bytes" : 0,
"version_map_memory_in_bytes" : 0,
"fixed_bit_set_memory_in_bytes" : 0,
"max_unsafe_auto_id_timestamp" : -1,
"file_sizes" : { }
},
"translog" : {
"operations" : 0,
"size_in_bytes" : 935,
"uncommitted_operations" : 0,
"uncommitted_size_in_bytes" : 935,
"earliest_last_modified_age" : 0
},
"request_cache" : {
"memory_size_in_bytes" : 0,
"evictions" : 0,
"hit_count" : 0,
"miss_count" : 0
},
"recovery" : {
"current_as_source" : 0,
"current_as_target" : 0,
"throttle_time_in_millis" : 0
}
},
"total" : {
"docs" : {
"count" : 4,
"deleted" : 0
},
"store" : {
"size_in_bytes" : 16172
},
"indexing" : {
"index_total" : 0,
"index_time_in_millis" : 0,
"index_current" : 0,
"index_failed" : 0,
"delete_total" : 0,
"delete_time_in_millis" : 0,
"delete_current" : 0,
"noop_update_total" : 0,
"is_throttled" : false,
"throttle_time_in_millis" : 0
},
"get" : {
"total" : 1,
"time_in_millis" : 0,
"exists_total" : 1,
"exists_time_in_millis" : 0,
"missing_total" : 0,
"missing_time_in_millis" : 0,
"current" : 0
},
"search" : {
"open_contexts" : 0,
"query_total" : 0,
"query_time_in_millis" : 0,
"query_current" : 0,
"fetch_total" : 0,
"fetch_time_in_millis" : 0,
"fetch_current" : 0,
"scroll_total" : 0,
"scroll_time_in_millis" : 0,
"scroll_current" : 0,
"suggest_total" : 0,
"suggest_time_in_millis" : 0,
"suggest_current" : 0
},
"merges" : {
"current" : 0,
"current_docs" : 0,
"current_size_in_bytes" : 0,
"total" : 0,
"total_time_in_millis" : 0,
"total_docs" : 0,
"total_size_in_bytes" : 0,
"total_stopped_time_in_millis" : 0,
"total_throttled_time_in_millis" : 0,
"total_auto_throttle_in_bytes" : 62914560
},
"refresh" : {
"total" : 6,
"total_time_in_millis" : 0,
"external_total" : 6,
"external_total_time_in_millis" : 0,
"listeners" : 0
},
"flush" : {
"total" : 3,
"periodic" : 0,
"total_time_in_millis" : 0
},
"warmer" : {
"current" : 0,
"total" : 3,
"total_time_in_millis" : 0
},
"query_cache" : {
"memory_size_in_bytes" : 0,
"total_count" : 0,
"hit_count" : 0,
"miss_count" : 0,
"cache_size" : 0,
"cache_count" : 0,
"evictions" : 0
},
"fielddata" : {
"memory_size_in_bytes" : 0,
"evictions" : 0
},
"completion" : {
"size_in_bytes" : 0
},
"segments" : {
"count" : 4,
"memory_in_bytes" : 4884,
"terms_memory_in_bytes" : 3108,
"stored_fields_memory_in_bytes" : 1248,
"term_vectors_memory_in_bytes" : 0,
"norms_memory_in_bytes" : 256,
"points_memory_in_bytes" : 0,
"doc_values_memory_in_bytes" : 272,
"index_writer_memory_in_bytes" : 0,
"version_map_memory_in_bytes" : 0,
"fixed_bit_set_memory_in_bytes" : 0,
"max_unsafe_auto_id_timestamp" : -1,
"file_sizes" : { }
},
"translog" : {
"operations" : 0,
"size_in_bytes" : 935,
"uncommitted_operations" : 0,
"uncommitted_size_in_bytes" : 935,
"earliest_last_modified_age" : 0
},
"request_cache" : {
"memory_size_in_bytes" : 0,
"evictions" : 0,
"hit_count" : 0,
"miss_count" : 0
},
"recovery" : {
"current_as_source" : 0,
"current_as_target" : 0,
"throttle_time_in_millis" : 0
}
}
},
"indices" : {
"people" : {
"uuid" : "trYLrNhrRFqnhbPHhVNFMA",
"primaries" : {
"docs" : {
"count" : 4,
"deleted" : 0
},
"store" : {
"size_in_bytes" : 16172
},
"indexing" : {
"index_total" : 0,
"index_time_in_millis" : 0,
"index_current" : 0,
"index_failed" : 0,
"delete_total" : 0,
"delete_time_in_millis" : 0,
"delete_current" : 0,
"noop_update_total" : 0,
"is_throttled" : false,
"throttle_time_in_millis" : 0
},
"get" : {
"total" : 1,
"time_in_millis" : 0,
"exists_total" : 1,
"exists_time_in_millis" : 0,
"missing_total" : 0,
"missing_time_in_millis" : 0,
"current" : 0
},
"search" : {
"open_contexts" : 0,
"query_total" : 0,
"query_time_in_millis" : 0,
"query_current" : 0,
"fetch_total" : 0,
"fetch_time_in_millis" : 0,
"fetch_current" : 0,
"scroll_total" : 0,
"scroll_time_in_millis" : 0,
"scroll_current" : 0,
"suggest_total" : 0,
"suggest_time_in_millis" : 0,
"suggest_current" : 0
},
"merges" : {
"current" : 0,
"current_docs" : 0,
"current_size_in_bytes" : 0,
"total" : 0,
"total_time_in_millis" : 0,
"total_docs" : 0,
"total_size_in_bytes" : 0,
"total_stopped_time_in_millis" : 0,
"total_throttled_time_in_millis" : 0,
"total_auto_throttle_in_bytes" : 62914560
},
"refresh" : {
"total" : 6,
"total_time_in_millis" : 0,
"external_total" : 6,
"external_total_time_in_millis" : 0,
"listeners" : 0
},
"flush" : {
"total" : 3,
"periodic" : 0,
"total_time_in_millis" : 0
},
"warmer" : {
"current" : 0,
"total" : 3,
"total_time_in_millis" : 0
},
"query_cache" : {
"memory_size_in_bytes" : 0,
"total_count" : 0,
"hit_count" : 0,
"miss_count" : 0,
"cache_size" : 0,
"cache_count" : 0,
"evictions" : 0
},
"fielddata" : {
"memory_size_in_bytes" : 0,
"evictions" : 0
},
"completion" : {
"size_in_bytes" : 0
},
"segments" : {
"count" : 4,
"memory_in_bytes" : 4884,
"terms_memory_in_bytes" : 3108,
"stored_fields_memory_in_bytes" : 1248,
"term_vectors_memory_in_bytes" : 0,
"norms_memory_in_bytes" : 256,
"points_memory_in_bytes" : 0,
"doc_values_memory_in_bytes" : 272,
"index_writer_memory_in_bytes" : 0,
"version_map_memory_in_bytes" : 0,
"fixed_bit_set_memory_in_bytes" : 0,
"max_unsafe_auto_id_timestamp" : -1,
"file_sizes" : { }
},
"translog" : {
"operations" : 0,
"size_in_bytes" : 935,
"uncommitted_operations" : 0,
"uncommitted_size_in_bytes" : 935,
"earliest_last_modified_age" : 0
},
"request_cache" : {
"memory_size_in_bytes" : 0,
"evictions" : 0,
"hit_count" : 0,
"miss_count" : 0
},
"recovery" : {
"current_as_source" : 0,
"current_as_target" : 0,
"throttle_time_in_millis" : 0
}
},
"total" : {
"docs" : {
"count" : 4,
"deleted" : 0
},
"store" : {
"size_in_bytes" : 16172
},
"indexing" : {
"index_total" : 0,
"index_time_in_millis" : 0,
"index_current" : 0,
"index_failed" : 0,
"delete_total" : 0,
"delete_time_in_millis" : 0,
"delete_current" : 0,
"noop_update_total" : 0,
"is_throttled" : false,
"throttle_time_in_millis" : 0
},
"get" : {
"total" : 1,
"time_in_millis" : 0,
"exists_total" : 1,
"exists_time_in_millis" : 0,
"missing_total" : 0,
"missing_time_in_millis" : 0,
"current" : 0
},
"search" : {
"open_contexts" : 0,
"query_total" : 0,
"query_time_in_millis" : 0,
"query_current" : 0,
"fetch_total" : 0,
"fetch_time_in_millis" : 0,
"fetch_current" : 0,
"scroll_total" : 0,
"scroll_time_in_millis" : 0,
"scroll_current" : 0,
"suggest_total" : 0,
"suggest_time_in_millis" : 0,
"suggest_current" : 0
},
"merges" : {
"current" : 0,
"current_docs" : 0,
"current_size_in_bytes" : 0,
"total" : 0,
"total_time_in_millis" : 0,
"total_docs" : 0,
"total_size_in_bytes" : 0,
"total_stopped_time_in_millis" : 0,
"total_throttled_time_in_millis" : 0,
"total_auto_throttle_in_bytes" : 62914560
},
"refresh" : {
"total" : 6,
"total_time_in_millis" : 0,
"external_total" : 6,
"external_total_time_in_millis" : 0,
"listeners" : 0
},
"flush" : {
"total" : 3,
"periodic" : 0,
"total_time_in_millis" : 0
},
"warmer" : {
"current" : 0,
"total" : 3,
"total_time_in_millis" : 0
},
"query_cache" : {
"memory_size_in_bytes" : 0,
"total_count" : 0,
"hit_count" : 0,
"miss_count" : 0,
"cache_size" : 0,
"cache_count" : 0,
"evictions" : 0
},
"fielddata" : {
"memory_size_in_bytes" : 0,
"evictions" : 0
},
"completion" : {
"size_in_bytes" : 0
},
"segments" : {
"count" : 4,
"memory_in_bytes" : 4884,
"terms_memory_in_bytes" : 3108,
"stored_fields_memory_in_bytes" : 1248,
"term_vectors_memory_in_bytes" : 0,
"norms_memory_in_bytes" : 256,
"points_memory_in_bytes" : 0,
"doc_values_memory_in_bytes" : 272,
"index_writer_memory_in_bytes" : 0,
"version_map_memory_in_bytes" : 0,
"fixed_bit_set_memory_in_bytes" : 0,
"max_unsafe_auto_id_timestamp" : -1,
"file_sizes" : { }
},
"translog" : {
"operations" : 0,
"size_in_bytes" : 935,
"uncommitted_operations" : 0,
"uncommitted_size_in_bytes" : 935,
"earliest_last_modified_age" : 0
},
"request_cache" : {
"memory_size_in_bytes" : 0,
"evictions" : 0,
"hit_count" : 0,
"miss_count" : 0
},
"recovery" : {
"current_as_source" : 0,
"current_as_target" : 0,
"throttle_time_in_millis" : 0
}
}
}
}
}
统计数据说明:
- docs 文档及删除文档数量
- store 索引大小
- indexing 索引统计数据,可以结合用逗号分隔的类型来提供文档类型基本的统计数据
- get 获取统计数据,包含缺失统计
- search 搜索统计数据,可以添加额外的groups参数包含自定义分子的统计数据。groups接受逗号分隔的组名列表。使用_all返回所有分组的统计数据。
- completion 完成建议统计数据
- fielddata 字段数据统计数据
- flush 冲洗统计数据
- merge 混合统计数据
- request_cache 分片请求缓存统计数据
- refresh 刷新统计数据
- suggest 建议统计数据
- translog 事物日志统计数据
2.2、索引分段信息
索引分段信息包含分片lucene的段信息。
命令格式:
获取所有分段信息
GET /_segments
获取某些索引的分段信息
GET /{索引名}/_segments
示例:
GET /people/_segments
{
"_shards" : {
"total" : 6,
"successful" : 3,
"failed" : 0
},
"indices" : {
"people" : {
"shards" : {
"0" : [
{
"routing" : {
"state" : "STARTED",
"primary" : true,
"node" : "_tCUuwGSQ1CiF1vxKS42nA"
},
"num_committed_segments" : 0,
"num_search_segments" : 0,
"segments" : { }
}
],
"1" : [
{
"routing" : {
"state" : "STARTED",
"primary" : true,
"node" : "_tCUuwGSQ1CiF1vxKS42nA"
},
"num_committed_segments" : 3,
"num_search_segments" : 3,
"segments" : {
"_0" : {
"generation" : 0,
"num_docs" : 1,
"deleted_docs" : 0,
"size_in_bytes" : 3778,
"memory_in_bytes" : 1221,
"committed" : true,
"search" : true,
"version" : "8.4.0",
"compound" : true,
"attributes" : {
"Lucene50StoredFieldsFormat.mode" : "BEST_SPEED"
}
},
"_3" : {
"generation" : 3,
"num_docs" : 1,
"deleted_docs" : 0,
"size_in_bytes" : 3752,
"memory_in_bytes" : 1221,
"committed" : true,
"search" : true,
"version" : "8.4.0",
"compound" : true,
"attributes" : {
"Lucene50StoredFieldsFormat.mode" : "BEST_SPEED"
}
},
"_4" : {
"generation" : 4,
"num_docs" : 1,
"deleted_docs" : 0,
"size_in_bytes" : 3794,
"memory_in_bytes" : 1221,
"committed" : true,
"search" : true,
"version" : "8.4.0",
"compound" : true,
"attributes" : {
"Lucene50StoredFieldsFormat.mode" : "BEST_SPEED"
}
}
}
}
],
"2" : [
{
"routing" : {
"state" : "STARTED",
"primary" : true,
"node" : "_tCUuwGSQ1CiF1vxKS42nA"
},
"num_committed_segments" : 1,
"num_search_segments" : 1,
"segments" : {
"_3" : {
"generation" : 3,
"num_docs" : 1,
"deleted_docs" : 0,
"size_in_bytes" : 3737,
"memory_in_bytes" : 1221,
"committed" : true,
"search" : true,
"version" : "8.4.0",
"compound" : true,
"attributes" : {
"Lucene50StoredFieldsFormat.mode" : "BEST_SPEED"
}
}
}
}
]
}
}
}
}
参数说明:
- _0 JSON文档的键名,代表分片的名称。这个名称用来生成文档名:分片目录中所有以分片名开头的文档属于这个分片
- generation 需要写新的分片时生成的一个数字,基本上是递增的。分片名从这个生成的数字派生出来
- num_docs 存储在分片中没被删除的文档数量。
- deleted_docs 存储在分片中被删除的文档数量,如果这个数字大于0也没问题,磁盘空间会在段合并时被回收
- size_in_bytes 用字节表示分片使用的磁盘空间数量
- memory_in_byte 分片需要在内存中存储一些数据使搜索性能更加高效。这个数字表示用于这个目的的字节数量。如果返回值为-1,表示Elasticsearch无法计算这个值
- committed 表示分片在磁盘上是否同步。提交的分片会在硬重启中存活下来。如果值为false也无需担心,未提交的分片数据也会存储在事物日志中,当集群下次重启时可以重做修改
- search 分片是否可以进行搜索,如果为false,可能意味着分片已经被写入磁盘但没有经过刷新使之可以进行搜索。
- version 用来写这个分片的lucene版本
- compound 分片是否存储在压缩文件中,如果为true,表示lucene将分片中所有的文档融合为一个用来保存文档的描述符。
2.3、索引分片信息
所有分片信息报告分片副本存在的节点、分片副本版本、只是分片副本最近状态已经在开启分片索引时遭遇的任何异常。
命令格式:
GET /{索引名}/_shard_stores
示例:
GET /people/_shard_stores
{
"nodes" : {
"_tCUuwGSQ1CiF1vxKS42nA" : {
"name" : "test-node-1",
"ephemeral_id" : "hlwUZ4faQSeKq_zsM2g5rA",
"transport_address" : "127.0.0.1:9300",
"attributes" : {
"ml.machine_memory" : "8480055296",
"xpack.installed" : "true",
"ml.max_open_jobs" : "20"
}
}
},
"indices" : {
"people" : { }
},
"shards" : [
[
{
"state" : "STARTED",
"primary" : true,
"node" : "_tCUuwGSQ1CiF1vxKS42nA",
"relocating_node" : null,
"shard" : 0,
"index" : "people",
"allocation_id" : {
"id" : "KtD9HbdnQXmnuJaV1hvK3Q"
}
}
],
[
{
"state" : "STARTED",
"primary" : true,
"node" : "_tCUuwGSQ1CiF1vxKS42nA",
"relocating_node" : null,
"shard" : 1,
"index" : "people",
"allocation_id" : {
"id" : "0EkYrz_ZQsG6oAAqxX6j_A"
}
}
],
[
{
"state" : "STARTED",
"primary" : true,
"node" : "_tCUuwGSQ1CiF1vxKS42nA",
"relocating_node" : null,
"shard" : 2,
"index" : "people",
"allocation_id" : {
"id" : "B4DSNFVFQcaVT7l8ydq-7g"
}
}
]
]
}
2.3、搜索分片信息
搜索分片信息包含某个索引可以拥有搜索的分片信息。
命令格式:
GET /{索引名}/_search_shards
示例:
{
"nodes" : {
"_tCUuwGSQ1CiF1vxKS42nA" : {
"name" : "test-node-1",
"ephemeral_id" : "hlwUZ4faQSeKq_zsM2g5rA",
"transport_address" : "127.0.0.1:9300",
"attributes" : {
"ml.machine_memory" : "8480055296",
"xpack.installed" : "true",
"ml.max_open_jobs" : "20"
}
}
},
"indices" : {
"people" : { }
},
"shards" : [
[
{
"state" : "STARTED",
"primary" : true,
"node" : "_tCUuwGSQ1CiF1vxKS42nA",
"relocating_node" : null,
"shard" : 0,
"index" : "people",
"allocation_id" : {
"id" : "KtD9HbdnQXmnuJaV1hvK3Q"
}
}
],
[
{
"state" : "STARTED",
"primary" : true,
"node" : "_tCUuwGSQ1CiF1vxKS42nA",
"relocating_node" : null,
"shard" : 1,
"index" : "people",
"allocation_id" : {
"id" : "0EkYrz_ZQsG6oAAqxX6j_A"
}
}
],
[
{
"state" : "STARTED",
"primary" : true,
"node" : "_tCUuwGSQ1CiF1vxKS42nA",
"relocating_node" : null,
"shard" : 2,
"index" : "people",
"allocation_id" : {
"id" : "B4DSNFVFQcaVT7l8ydq-7g"
}
}
]
]
}
3、状态管理
3.1、索引刷新
索引刷新操作可以刷新一个或多个索引,使其前一次刷新后的所有操作被执行。近实时能力取决于使用的搜索引擎。
命令格式:
POST /{索引名}/_refresh
3.2、索引冲洗
可以冲洗一个或多个索引。索引主要通过执行冲洗将数据保存带索引存储并且清除内部事务日志,以此来释放索引的内存空间。Elasticsearch默认使用内存启发式算法来自动触发冲洗操作的请求类清理内存。
命令格式:
POST /{索引名}/_flush
3.3、索引合并
合并索引可以强制合并一个或多个索引,合并分片数量和每个分片保存的lucene索引。强制合并可以通过合并来减少分片数量。调用会被阻塞直到合并完成。如果http连接丢失,请求会在后台继续执行,任何新的请求都会被阻塞直到前一个强制合并完成。
命令格式:
POST /{索引名}/_forcemerge
{
"max_num_segments":1,
"only_expunge_deletes":false,
"flush":true
}
3.4、缓存清除
可以清除缓存或关联一个或更多索引的特定缓存。默认清除所有缓存,可以明确设置query、fielddata和request来清除特定缓存。
命令格式:
POST /people/_cache/clear
网友评论