{
"cells": [
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"使用.NET专用客户端 Elastic.Client 库,管理单节点ES\n",
"==============================================="
]
},
"## 全局设置"
"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>"
"output_type": "display_data"
],
"//引入 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",
"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",
"public RestClient ClusterRestClient = new RestClient(option);"
"## 集群主页面"
"execution_count": 2,
"text/plain": [
" \"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"
"//集群主页\n",
" var request = new RestRequest(\"?pretty\", Method.Get);\n",
" var healthResponse = ClusterRestClient.Get(request);\n",
" var context = healthResponse.Content;\n",
" context.Display();\n",
"}"
"## 集群节点信息"
"execution_count": null,
"outputs": [],
"//获取集群节点信息\n",
" var request = new RestRequest(\"/_cat/nodes?v\", Method.Get);\n",
" Console.WriteLine(context);\n",
"## 集群健康状态"
" var request = new RestRequest(\"/_cat/health?v\", Method.Get);\n",
" //Console.WriteLine(context);\n",
"## 查询索引"
"//查询所有索引\n",
" var request = new RestRequest(\"/_cat/indices?v&pretty\", Method.Get);\n",
"kernelspec": {
"display_name": ".NET (C#)",
"language": "C#",
"name": ".net-csharp"
"language_info": {
"name": "polyglot-notebook"
"orig_nbformat": 4,
"kernelInfo": {
"defaultKernelName": "csharp",
"items": [
"aliases": [],
"name": "csharp"
"nbformat": 4,
"nbformat_minor": 2