You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ElasticSearchStudy/Docs/使用RestSharp库管理ES集群.ipynb

235 lines
5.4 KiB
Plaintext

{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"使用.NET专用客户端 Elastic.Client 库管理单节点ES\n",
"==============================================="
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 全局设置"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div><div><strong>Restore sources</strong><ul><li><span>https://api.nuget.org/v3/index.json</span></li></ul></div><div></div><div><strong>Installed Packages</strong><ul><li><span>RestSharp, 110.2.0</span></li></ul></div></div>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"//引入 RestSharp 类库\n",
"#i \"nuget:https://api.nuget.org/v3/index.json\"\n",
"#r \"nuget:RestSharp,110.2.0\"\n",
"\n",
"using RestSharp;\n",
"using RestSharp.Extensions;\n",
"using RestSharp.Serializers;\n",
"using RestSharp.Authenticators;\n",
"\n",
"public RestClientOptions option = new RestClientOptions()\n",
"{\n",
" BaseUrl = new Uri(\"https://127.0.0.1:9201\"),\n",
" Authenticator = new HttpBasicAuthenticator(\"elastic\", \"es-461400\")\n",
"};\n",
"\n",
"//集群客户端\n",
"public RestClient ClusterRestClient = new RestClient(option);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 集群主页面"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [
{
"data": {
"text/plain": [
"{\n",
" \"name\" : \"study-es-cluster-master\",\n",
" \"cluster_name\" : \"study-es-cluster\",\n",
" \"cluster_uuid\" : \"x9tU46-NSLiRUQJb_aXCCQ\",\n",
" \"version\" : {\n",
" \"number\" : \"8.7.0\",\n",
" \"build_flavor\" : \"default\",\n",
" \"build_type\" : \"zip\",\n",
" \"build_hash\" : \"09520b59b6bc1057340b55750186466ea715e30e\",\n",
" \"build_date\" : \"2023-03-27T16:31:09.816451435Z\",\n",
" \"build_snapshot\" : false,\n",
" \"lucene_version\" : \"9.5.0\",\n",
" \"minimum_wire_compatibility_version\" : \"7.17.0\",\n",
" \"minimum_index_compatibility_version\" : \"7.0.0\"\n",
" },\n",
" \"tagline\" : \"You Know, for Search\"\n",
"}\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"//集群主页\n",
"{\n",
" var request = new RestRequest(\"?pretty\", Method.Get);\n",
" var healthResponse = ClusterRestClient.Get(request);\n",
" var context = healthResponse.Content;\n",
" context.Display();\n",
"}"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 集群节点信息"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [],
"source": [
"//获取集群节点信息\n",
"{\n",
" var request = new RestRequest(\"/_cat/nodes?v\", Method.Get);\n",
" var healthResponse = ClusterRestClient.Get(request);\n",
" var context = healthResponse.Content;\n",
" Console.WriteLine(context);\n",
"}"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 集群健康状态"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [],
"source": [
"{\n",
" var request = new RestRequest(\"/_cat/health?v\", Method.Get);\n",
" var healthResponse = ClusterRestClient.Get(request);\n",
" var context = healthResponse.Content;\n",
" //Console.WriteLine(context);\n",
" context.Display();\n",
"}"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 查询索引"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [],
"source": [
"//查询所有索引\n",
"{\n",
" var request = new RestRequest(\"/_cat/indices?v&pretty\", Method.Get);\n",
" var healthResponse = ClusterRestClient.Get(request);\n",
" var context = healthResponse.Content;\n",
" //Console.WriteLine(context);\n",
" context.Display();\n",
"}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (C#)",
"language": "C#",
"name": ".net-csharp"
},
"language_info": {
"name": "polyglot-notebook"
},
"orig_nbformat": 4,
"polyglot_notebook": {
"kernelInfo": {
"defaultKernelName": "csharp",
"items": [
{
"aliases": [],
"name": "csharp"
}
]
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}