ElasticSearch常用操作API

基础操作

以下均为[GET]操作

bash 复制代码
查看ElasticSearch全部索引	http://{ip}:9200/_cat/indices?v
查看ElasticSearch集群节点	http://{ip}:9200/_cat/nodes?v
查看ElasticSearch版本信息	http://{ip}:9200/
查看ElasticSearch集群状态	http://{ip}:9200/_cluster/health?pretty
查看ElasticSearch当前主节点	http://{ip}:9200/_cat/master?v
查看ElasticSearch集群指标	http://{ip}:9200/_cluster/stats?pretty
查看ElasticSearch别名信息	http://{ip}:9200/_cat/aliases?v
查看ElasticSearch模板信息	http://{ip}:9200/_cat/templates?v
查看ElasticSearch分配情况	http://{ip}:9200/_cat/allocation?v
查看ElasticSearch文档总数	http://{ip}:9200/_cat/count?v
查看ElasticSearch修复状态	http://{ip}:9200/_cat/recovery?v
查看ElasticSearch分片信息	http://{ip}:9200/_cat/shards?v
查看ElasticSearch挂起任务	http://{ip}:9200/_cluster/pending_tasks?pretty
查看ElasticSearch热线程	    http://{ip}:9200/_nodes/hot_threads?pretty

进阶操作

1.开启、关闭索引通配符删除

false表示可以通配符删除

true表示不可以通配符删除

bash 复制代码
[PUT] _cluster/settings
{
  "transient": {
    "action.destructive_requires_name": false
  }
}

2.调整集群最大分片数

用于配置生命周期后,自动分裂分片使用

bash 复制代码
[PUT] _cluster/settings
{
  "transient": {
    "cluster.max_shards_per_node": 100000
  }
}

3.设置Search返回结果最大条数(默认10000)

bash 复制代码
所有索引生效
[PUT] _all/_settings
{ 
  "index.max_result_window": 50000
}
单个索引生效
[PUT] {index}/_settings
{ 
  "index.max_result_window": 50000
}

4.批量设置索引别名、设置为写索引

同时设置多个在数组里增加即可

"is_write_index": true表示当多个索引共用同一个别名时,设置当前索引为写索引,读的话走别名,可以将所有索引数据都查到

bash 复制代码
[POST] _aliases
{
	"actions": [{
		"add": {
			"index": "m12_insertzone-000001",
			"alias": "m12_insertzone",
			"is_write_index": true
		}
	}]
}

5.设置索引生命周期模板名称及滚动更新索引别名

bash 复制代码
[POST] {index}/_settings
{
	"index.lifecycle.name": "iscas",
	"index.lifecycle.rollover_alias": "m12_insertzone"
}

6.创建索引含配置

bash 复制代码
[PUT] {index}
{
	"aliases": {
		"m12_insertzone": {
			"is_write_index": true
		}
	},
	"settings": {
		"index.number_of_shards": "6",
		"index.number_of_replicas": "1",
		"index.lifecycle.name": "iscas-ilm-policy",
		"index.lifecycle.rollover_alias": "m12_insertzone",
		"index": {
			"routing": {
				"allocation": {
					"require": {
						"hotwarm_type": "hot"
					}
				}
			},
			"translog": {
				"durability": "async",
				"sync_interval": "30s",
				"flush_threshold_size": "1024mb"
			}
		}
	},
	"mappings": {}
}

7. 创建模板含配置

[PUT] _template/{name}

bash 复制代码
{
	"index_patterns": ["m22_sample_30-*"],
	"order": 0,
	"settings": {
		"index": {
			"lifecycle": {
				"rollover_alias": "m22_sample_30",
				"name": "iscas-ilm-policy"
			},
			"routing": {
				"allocation": {
					"require": {
						"hotwarm_type": "hot"
					}
				}
			},
			"number_of_shards": "6",
			"number_of_replicas": "1",
			"translog": {
				"durability": "async",
				"sync_interval": "30s",
				"flush_threshold_size": "1024mb"
			}
		}
	},
	"mappings": {}
}
相关推荐
逸Y 仙X1 小时前
Git常见命令--助力开发
java·大数据·git·java-ee·github·idea
元气满满的热码式2 小时前
logstash中的input插件(http插件,graphite插件)
网络·网络协议·http·elasticsearch·云原生
caihuayuan42 小时前
PHP建立MySQL持久化连接(长连接)及mysql与mysqli扩展的区别
java·大数据·sql·spring
B站计算机毕业设计超人2 小时前
计算机毕业设计Hadoop+Spark+DeepSeek-R1大模型民宿推荐系统 hive民宿可视化 民宿爬虫 大数据毕业设计(源码+LW文档+PPT+讲解)
大数据·hadoop·爬虫·机器学习·课程设计·数据可视化·推荐算法
silianpan3 小时前
文档检索服务平台
elasticsearch·搜索引擎·开源
(; ̄ェ ̄)。3 小时前
在nodejs中使用ElasticSearch(二)核心概念,应用
大数据·elasticsearch·搜索引擎
boy快快长大4 小时前
【Elasticsearch】同一台服务器部署集群
服务器·elasticsearch·jenkins
一个儒雅随和的男子4 小时前
Elasticsearch除了用作查找以外,还能可以做什么?
大数据·elasticsearch·搜索引擎
Sui_Network4 小时前
Sui 如何支持各种类型的 Web3 游戏
大数据·数据库·人工智能·游戏·web3·区块链
ZKNOW甄知科技4 小时前
IT服务运营管理体系的常用方法论与实践指南(上)
大数据·数据库·人工智能