{"id":10007094,"date":"2023-01-17T23:49:37","date_gmt":"2023-01-17T15:49:37","guid":{"rendered":"https:\/\/ityet.com\/?p=10007094"},"modified":"2023-01-17T23:49:37","modified_gmt":"2023-01-17T15:49:37","slug":"elasticsearch-%e5%bf%85%e7%9f%a5%e5%bf%85%e4%bc%9a-%e8%bf%9b%e9%98%b6%e7%af%87","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10007094","title":{"rendered":"ElasticSearch \u5fc5\u77e5\u5fc5\u4f1a &#8211; \u8fdb\u9636\u7bc7"},"content":{"rendered":"<p><strong>\u4eac\u4e1c\u7269\u6d41\uff1a\u5eb7\u777f \u59da\u518d\u6bc5 \u674e\u632f \u5218\u658c \u738b\u5317\u6c38<\/strong><\/p>\n<p>\u8bf4\u660e\uff1a\u4ee5\u4e0b\u5168\u90e8\u5747\u57fa\u4e8e ElasticSearch 8.1 \u7248\u672c<\/p>\n<h2>\u4e00.\u8de8\u96c6\u7fa4\u68c0\u7d22 &#8211; ccr<\/h2>\n<blockquote><p>\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=xRTjSFzCkjRd%2BNMMWEvyhw%3D%3D.wB8wAAEp9V46S1o5QSQmQR4GhVrEYw%2F5TtdFeiqzJNswahSsAbE2xIJXvw6%2Fr7FEDDxk8YX35sB3bdTYn1CaGTFmaxfPei6UEkKVbSeOQHKaKqfC%2Ftjl6nYKp1Bie0u7\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/modules-cross-cluster-search.html<\/a><\/p><\/blockquote>\n<h3>\u8de8\u96c6\u7fa4\u68c0\u7d22\u7684\u80cc\u666f\u548c\u610f\u4e49<\/h3>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342002\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u8de8\u96c6\u7fa4\u68c0\u7d22\u5b9a\u4e49<\/h3>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342003\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u8de8\u96c6\u7fa4\u68c0\u7d22\u73af\u5883\u642d\u5efa<\/h3>\n<p>\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=5%2F%2B2mcBdQKBhldUd17A8TQ%3D%3D.0O%2FyGTFs6rPR0o%2BvLVDayMTJ51OIMzQLoqARf41w0ySlXUXF2o9fMRCMWC6A0XVCDiXiU1dFsy3z8eU%2BpdS4OicGEky22wssXdV37AnJR04P2BLdbd84MO2%2BA0lokqUk\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/modules-cross-cluster-search.html<\/a><\/p>\n<p>\u6b65\u9aa41\uff1a\u642d\u5efa\u4e24\u4e2a\u672c\u5730\u5355\u8282\u70b9\u96c6\u7fa4\uff0c\u672c\u5730\u7ec3\u4e60\u53ef\u53d6\u6d88\u5b89\u5168\u914d\u7f6e<\/p>\n<p>\u6b65\u9aa42\uff1a\u6bcf\u4e2a\u96c6\u7fa4\u90fd\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4<\/p>\n<p>PUT \/_cluster\/settings { &#8220;persistent&#8221;: { &#8220;cluster&#8221;: { &#8220;remote&#8221;: { &#8220;cluster\/_one&#8221;: { &#8220;seeds&#8221;: [ &#8220;172.21.0.14:9301&#8243; ] },&#8221;cluster_two&#8221;: { &#8220;seeds&#8221;: [ &#8220;172.21.0.14:9302&#8221; ] } } } } }<\/p>\n<p>\u6b65\u9aa43\uff1a\u9a8c\u8bc1\u96c6\u7fa4\u4e4b\u95f4\u662f\u5426\u4e92\u901a<\/p>\n<p>\u65b9\u68481\uff1aKibana \u53ef\u89c6\u5316\u67e5\u770b\uff1astack Management -&gt; Remote Clusters -&gt; status \u5e94\u8be5\u662f connected\uff01 \u4e14\u5fc5\u987b\u6253\u4e0a\u7eff\u8272\u7684\u5bf9\u53f7\u3002<\/p>\n<p>\u200b \u65b9\u68482\uff1aGET _remote\/info<\/p>\n<h3>\u8de8\u96c6\u7fa4\u67e5\u8be2\u6f14\u7ec3<\/h3>\n<pre><code># \u6b65\u9aa41 \u5728\u96c6\u7fa4 1 \u4e2d\u6dfb\u52a0\u6570\u636e\u5982\u4e0b\nPUT test01\/_bulk\n{&quot;index&quot;:{&quot;_id&quot;:1}}\n{&quot;title&quot;:&quot;this is from cluster01...&quot;}\n\n# \u6b65\u9aa42 \u5728\u96c6\u7fa4 2 \u4e2d\u6dfb\u52a0\u6570\u636e\u5982\u4e0b\uff1a\nPUT test01\/_bulk\n{&quot;index&quot;:{&quot;_id&quot;:1}}\n{&quot;title&quot;:&quot;this is from cluster02...&quot;}\n\n# \u6b65\u9aa4 3\uff1a\u6267\u884c\u8de8\u96c6\u7fa4\u68c0\u7d22\u5982\u4e0b: \u8bed\u6cd5\uff1aPOST \u96c6\u7fa4\u540d\u79f01:\u7d22\u5f15\u540d\u79f0,\u96c6\u7fa4\u540d\u79f02:\u7d22\u5f15\u540d\u79f0\/_search\nPOST cluster_one:test01,cluster_two:test01\/_search\n{\n  &quot;took&quot; : 7,\n  &quot;timed_out&quot; : false,\n  &quot;num_reduce_phases&quot; : 3,\n  &quot;_shards&quot; : {\n    &quot;total&quot; : 2,\n    &quot;successful&quot; : 2,\n    &quot;skipped&quot; : 0,\n    &quot;failed&quot; : 0\n  },\n  &quot;_clusters&quot; : {\n    &quot;total&quot; : 2,\n    &quot;successful&quot; : 2,\n    &quot;skipped&quot; : 0\n  },\n  &quot;hits&quot; : {\n    &quot;total&quot; : {\n      &quot;value&quot; : 2,\n      &quot;relation&quot; : &quot;eq&quot;\n    },\n    &quot;max_score&quot; : 1.0,\n    &quot;hits&quot; : [\n      {\n        &quot;_index&quot; : &quot;cluster_two:test01&quot;,\n        &quot;_id&quot; : &quot;1&quot;,\n        &quot;_score&quot; : 1.0,\n        &quot;_source&quot; : {\n          &quot;title&quot; : &quot;this is from cluster02...&quot;\n        }\n      },\n      {\n        &quot;_index&quot; : &quot;cluster_one:test01&quot;,\n        &quot;_id&quot; : &quot;1&quot;,\n        &quot;_score&quot; : 1.0,\n        &quot;_source&quot; : {\n          &quot;title&quot; : &quot;this is from cluster01...&quot;\n        }\n      }\n    ]\n  }\n}\n\n\n<\/code><\/pre>\n<h2>\u4e8c.\u8de8\u96c6\u7fa4\u590d\u5236 &#8211; ccs &#8211; \u8be5\u529f\u80fd\u9700\u4ed8\u8d39<\/h2>\n<blockquote><p>\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=EVOv3lXEGsOrYHxFm4ASYg%3D%3D.E%2FfTyW8wVmYiFWpgUuaowdphNKr7S%2BDS9cjYUlg%2FXs0HelpsXn97m7wgp7z%2F2LyG3K%2F%2Bgic5E4C16jtmtmp0oSV8iDEKbNZnMc11mOokRag%3D\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/xpack-ccr.html<\/a><\/p><\/blockquote>\n<h3>\u5982\u4f55\u4fdd\u969c\u96c6\u7fa4\u7684\u9ad8\u53ef\u7528<\/h3>\n<ol>\n<li>\u526f\u672c\u673a\u5236<\/li>\n<li>\u5feb\u7167\u548c\u6062\u590d<\/li>\n<li>\u8de8\u96c6\u7fa4\u590d\u5236\uff08\u7c7b\u4f3cmysql \u4e3b\u4ece\u540c\u6b65\uff09<\/li>\n<\/ol>\n<h3>\u8de8\u96c6\u7fa4\u590d\u5236\u6982\u8ff0<\/h3>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342004\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u8de8\u96c6\u7fa4\u590d\u5236\u914d\u7f6e<\/h3>\n<ol>\n<li>\u51c6\u5907\u4e24\u4e2a\u96c6\u7fa4\uff0c\u7f51\u7edc\u4e92\u901a<\/li>\n<li>\u5f00\u542f license \u4f7f\u7528\uff0c\u53ef\u8bd5\u752830\u5929<\/li>\n<\/ol>\n<ul>\n<li>\u5f00\u542f\u4f4d\u7f6e\uff1aStack Management -&gt; License mangement.<\/li>\n<\/ul>\n<p>3.\u5b9a\u4e49\u597d\u8c01\u662fLeads\u96c6\u7fa4\uff0c\u8c01\u662ffollower\u96c6\u7fa4<\/p>\n<p>4.\u5728follower\u96c6\u7fa4\u914d\u7f6eLeader\u96c6\u7fa4<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342005\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>5.\u5728follower\u96c6\u7fa4\u914d\u7f6eLeader\u96c6\u7fa4\u7684\u7d22\u5f15\u540c\u6b65\u89c4\u5219\uff08kibana\u9875\u9762\u914d\u7f6e\uff09<\/p>\n<p>a.stack Management -&gt; Cross Cluster Replication -&gt; create a follower index.<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342006\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>6.\u542f\u7528\u6b65\u9aa45\u7684\u914d\u7f6e<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342007\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<hr>\n<h2>\u4e09\u7d22\u5f15\u6a21\u677f<\/h2>\n<blockquote><p>\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=7Dwg8PSfj6XVSAKJhhisow%3D%3D.28iqhZOCa07kTl2iPVvALH3E6YV7pMyacqnoAaVRxK9mW8gVX71iLZ1JZTmK%2BdH1wAcNZkJAZzRpISjWPVgvRTk8TLsar7SP%2BnIwKOxjdQN4uBh8y2Q0QlYvrqcnCGBz\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/index-templates.html<\/a><\/p><\/blockquote>\n<h3>8.X\u4e4b\u7ec4\u4ef6\u6a21\u677f<\/h3>\n<p>1.\u521b\u5efa\u7ec4\u4ef6\u6a21\u677f-\u7d22\u5f15setting\u76f8\u5173<\/p>\n<pre><code># \u7ec4\u4ef6\u6a21\u677f - \u7d22\u5f15setting\u76f8\u5173\nPUT _component_template\/template_sttting_part\n{\n  &quot;template&quot;: {\n    &quot;settings&quot;: {\n      &quot;number_of_shards&quot;: 3,\n      &quot;number_of_replicas&quot;: 0\n    }\n  }\n}\n\n<\/code><\/pre>\n<p>2.\u521b\u5efa\u7ec4\u4ef6\u6a21\u677f-\u7d22\u5f15mapping\u76f8\u5173<\/p>\n<pre><code># \u7ec4\u4ef6\u6a21\u677f - \u7d22\u5f15mapping\u76f8\u5173\nPUT _component_template\/template_mapping_part\n{\n  &quot;template&quot;: {\n    &quot;mappings&quot;: {\n      &quot;properties&quot;: {\n        &quot;hosr_name&quot;:{\n          &quot;type&quot;: &quot;keyword&quot;\n        },\n        &quot;cratet_at&quot;:{\n          &quot;type&quot;: &quot;date&quot;,\n          &quot;format&quot;: &quot;EEE MMM dd HH:mm:ss Z yyyy&quot;\n        }\n      }\n    }\n  }\n}\n\n<\/code><\/pre>\n<p>3.\u521b\u5efa\u7ec4\u4ef6\u6a21\u677f-\u914d\u7f6e\u6a21\u677f\u548c\u7d22\u5f15\u4e4b\u95f4\u7684\u5173\u8054<\/p>\n<pre><code>\/\/ **\u6ce8\u610f\uff1acomposed_of \u5982\u679c\u591a\u4e2a\u7ec4\u4ef6\u6a21\u677f\u4e2d\u7684\u914d\u7f6e\u9879\u6709\u91cd\u590d\uff0c\u540e\u9762\u7684\u4f1a\u8986\u76d6\u524d\u9762\u7684\uff0c\u548c\u914d\u7f6e\u7684\u987a\u5e8f\u6709\u5173**\n# \u57fa\u4e8e\u7ec4\u4ef6\u6a21\u677f\uff0c\u914d\u7f6e\u6a21\u677f\u548c\u7d22\u5f15\u4e4b\u95f4\u7684\u5173\u8054\n# \u4e5f\u5c31\u662f\u6240\u6709 tem_* \u8be5\u8868\u8fbe\u5f0f\u76f8\u5173\u7684\u7d22\u5f15\u521b\u5efa\u65f6\uff0c\u90fd\u4f1a\u4f7f\u7528\u5230\u4ee5\u4e0b\u89c4\u5219\nPUT _index_template\/template_1\n{\n  &quot;index_patterns&quot;: [\n    &quot;tem_*&quot;\n  ],\n  &quot;composed_of&quot;: [\n    &quot;template_sttting_part&quot;,\n    &quot;template_mapping_part&quot;\n  ]\n}\n\n<\/code><\/pre>\n<p>4.\u6d4b\u8bd5<\/p>\n<pre><code># \u521b\u5efa\u6d4b\u8bd5\nPUT tem_001\n\n<\/code><\/pre>\n<h3>\u7d22\u5f15\u6a21\u677f\u57fa\u672c\u64cd\u4f5c<\/h3>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342008\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u5b9e\u6218\u6f14\u7ec3<\/h3>\n<p>\u9700\u6c421\uff1a\u9ed8\u8ba4\u5982\u679c\u4e0d\u663e\u5f0f\u6307\u5b9aMapping,\u6570\u503c\u7c7b\u578b\u4f1a\u88ab\u52a8\u6001\u6620\u5c04\u4e3along\u7c7b\u578b\uff0c\u4f46\u5b9e\u9645\u4e0a\u4e1a\u52a1\u6570\u503c\u90fd\u6bd4\u8f83\u5c0f\uff0c\u4f1a\u5b58\u5728\u5b58\u50a8\u6d6a\u8d39\u3002\u9700\u8981\u5c06\u9ed8\u8ba4\u503c\u6307\u5b9a\u4e3aInteger<\/p>\n<blockquote>\n<p>\u7d22\u5f15\u6a21\u677f\uff0c\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=covoCr24lJeLV5a8MWyoTw%3D%3D.ZioYu58xCMR188C3WH%2BSdoo0TKLM9WKRuR5sxbA4AjU7rLuAxJ2pm8EhVU0pzNgzzaVzzNq7fDgFFhsAH9mXX18k%2FBX9dFujlEmuJKzFpmFnjdDtknGknKx0HnmUNJSq\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/index-templates.html<\/a><\/p>\n<p>mapping-\u52a8\u6001\u6a21\u677f,\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=xadfhJUOs6qWESrFrKtipw%3D%3D.he3ZtbsFRMG8m155%2FSSuSImoJvqNJyHQKJgz%2BmFgfg8G9gyWCvQeL5Flhde1wBTVTHDLvbAJ3O3U6nwVlVz5tw%2FgtTn4QFb7dV1X0bFlvq0fUEvTna49bAx70WlfKb%2Bl\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/dynamic-templates.html<\/a><\/p>\n<\/blockquote>\n<pre><code># \u7ed3\u5408mapping \u52a8\u6001\u6a21\u677f \u548c \u7d22\u5f15\u6a21\u677f\n# 1.\u521b\u5efa\u7ec4\u4ef6\u6a21\u677f\u4e4b - mapping\u6a21\u677f\nPUT _component_template\/template_mapping_part_01\n{\n  &quot;template&quot;: {\n    &quot;mappings&quot;: {\n      &quot;dynamic_templates&quot;: [\n        {\n          &quot;integers&quot;: {\n            &quot;match_mapping_type&quot;: &quot;long&quot;,\n            &quot;mapping&quot;: {\n              &quot;type&quot;: &quot;integer&quot;\n            }\n          }\n        }\n      ]\n    }\n  }\n}\n\n# 2. \u521b\u5efa\u7ec4\u4ef6\u6a21\u677f\u4e0e\u7d22\u5f15\u5173\u8054\u914d\u7f6e\nPUT _index_template\/template_2\n{\n  &quot;index_patterns&quot;: [&quot;tem1_*&quot;],\n  &quot;composed_of&quot;: [&quot;template_mapping_part_01&quot;]\n}\n\n# 3.\u521b\u5efa\u6d4b\u8bd5\u6570\u636e\nPOST tem1_001\/_doc\/1\n{\n  &quot;age&quot;:18\n}\n\n# 4.\u67e5\u770bmapping\u7ed3\u6784\u9a8c\u8bc1\nget tem1_001\/_mapping\n\n\n<\/code><\/pre>\n<p>\u9700\u6c422\uff1adate_*\u5f00\u5934\u7684\u5b57\u6bb5\uff0c\u7edf\u4e00\u5339\u914d\u4e3adate\u65e5\u671f\u7c7b\u578b\u3002<\/p>\n<blockquote>\n<p>\u7d22\u5f15\u6a21\u677f\uff0c\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=IMMf%2BDAqUep5ZXNTlTcyEA%3D%3D.RIB%2F37zyJNwZmi6p%2FcXEXuU4k%2BwE%2FPieeZr06dCvI0iXDMErEb7EW1kYC6tQVZ6KTyTZqtY6PDkZQHVkrWkMcwehAK5%2BC5OOtfNMaXpSf%2BOFcpPy72pDDe2OvGmMkkVT\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/index-templates.html<\/a><\/p>\n<p>mapping-\u52a8\u6001\u6a21\u677f,\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=4%2BPOpK1nMEXHzpiaXR4%2BGQ%3D%3D.saYOSB0SomrMgwgoi6H4ekjzqTzAqPdPlZxfL7FyO7zE74qEw0mkrQvXGreBLBa7Th7JuP9fCriW%2B%2BtfsKAT9K9Nr2T4VxubmOL1mv7HOEQZ3ZijM%2FAMeZkxgyyApE8t\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/dynamic-templates.html<\/a><\/p>\n<\/blockquote>\n<pre><code># \u7ed3\u5408mapping \u52a8\u6001\u6a21\u677f \u548c \u7d22\u5f15\u6a21\u677f\n# 1.\u521b\u5efa\u7ec4\u4ef6\u6a21\u677f\u4e4b - mapping\u6a21\u677f\nPUT _component_template\/template_mapping_part_01\n{\n  &quot;template&quot;: {\n    &quot;mappings&quot;: {\n      &quot;dynamic_templates&quot;: [\n        {\n          &quot;integers&quot;: {\n            &quot;match_mapping_type&quot;: &quot;long&quot;,\n            &quot;mapping&quot;: {\n              &quot;type&quot;: &quot;integer&quot;\n            }\n          }\n        },\n        {\n        &quot;date_type_process&quot;: {\n          &quot;match&quot;: &quot;date_*&quot;,\n          &quot;mapping&quot;: {\n            &quot;type&quot;: &quot;date&quot;,\n            &quot;format&quot;:&quot;yyyy-MM-dd HH:mm:ss&quot;\n          }\n        }\n      }\n      ]\n    }\n  }\n}\n\n# 2. \u521b\u5efa\u7ec4\u4ef6\u6a21\u677f\u4e0e\u7d22\u5f15\u5173\u8054\u914d\u7f6e\nPUT _index_template\/template_2\n{\n  &quot;index_patterns&quot;: [&quot;tem1_*&quot;],\n  &quot;composed_of&quot;: [&quot;template_mapping_part_01&quot;]\n}\n\n\n# 3.\u521b\u5efa\u6d4b\u8bd5\u6570\u636e\nPOST tem1_001\/_doc\/2\n{\n  &quot;age&quot;:19,\n  &quot;date_aoe&quot;:&quot;2022-01-01 18:18:00&quot;\n}\n\n# 4.\u67e5\u770bmapping\u7ed3\u6784\u9a8c\u8bc1\nget tem1_001\/_mapping\n\n<\/code><\/pre>\n<h2>\u56db.LIM \u7d22\u5f15\u751f\u547d\u5468\u671f\u7ba1\u7406<\/h2>\n<blockquote><p>\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=VRoRI9t9fj6ZUahZHl%2BbQQ%3D%3D.UtKBQBjhF%2F8aTrOVCHS9zQ0AxIMvc8u%2BIlXX58fry53AJn5ZVL4OhbYxReGaGmkPxMfKV8PTBHVg5ewjowI6YBGS8rnKFNd9XFjtrHNOvCGF8HiBMX1vucThHE1bgj%2Bd\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/index-lifecycle-management.html<\/a><\/p><\/blockquote>\n<h3>\u4ec0\u4e48\u662f\u7d22\u5f15\u751f\u547d\u5468\u671f<\/h3>\n<p>\u7d22\u5f15\u7684 \u751f-&gt; \u8001 -&gt; \u75c5 -\/&gt; \u6b7b<\/p>\n<p>\u662f\u5426\u6709\u8fc7\u8003\u8651\uff0c\u5982\u679c\u4e00\u4e2a\u7d22\u5f15\uff0c\u521b\u5efa\u4e4b\u540e\uff0c\u5c31\u4e0d\u518d\u53bb\u7ba1\u7406\u4e86\uff1f\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f<\/p>\n<h3>\u4ec0\u4e48\u662f\u7d22\u5f15\u751f\u547d\u5468\u671f\u7ba1\u7406<\/h3>\n<p><strong>\u7d22\u5f15\u592a\u5927\u4e86\u4f1a\u5982\u4f55?<\/strong><\/p>\n<blockquote><p>\u5927\u7d22\u5f15\u7684\u6062\u590d\u65f6\u95f4\uff0c\u8981\u8fdc\u6bd4\u5c0f\u7d22\u5f15\u6062\u590d\u6162\u7684\u591a\u7684\u591a\u7d22\u5f15\u5927\u4e86\u4ee5\u540e\uff0c\u68c0\u7d22\u4f1a\u5f88\u6162\uff0c\u5199\u5165\u548c\u66f4\u65b0\u4e5f\u4f1a\u53d7\u5230\u4e0d\u540c\u7a0b\u5ea6\u7684\u5f71\u54cd\u7d22\u5f15\u5927\u5230\u4e00\u5b9a\u7a0b\u5ea6\uff0c\u5f53\u7d22\u5f15\u51fa\u73b0\u5065\u5eb7\u95ee\u9898\uff0c\u4f1a\u5bfc\u81f4\u6574\u4e2a\u96c6\u7fa4\u6838\u5fc3\u4e1a\u52a1\u4e0d\u53ef\u7528<\/p><\/blockquote>\n<p><strong>\u6700\u4f73\u5b9e\u8df5<\/strong><\/p>\n<blockquote><p>\u96c6\u7fa4\u7684\u5355\u4e2a\u5206\u7247\u6700\u5927\u6587\u6863\u6570\u4e0a\u9650\uff1a2\u768432\u6b21\u5e42\u51cf1\uff0c\u537320\u4ebf\u5de6\u53f3\u5b98\u65b9\u5efa\u8bae\uff1a\u5206\u7247\u5927\u5c0f\u63a7\u5236\u572830GB-50GB\uff0c\u82e5\u7d22\u5f15\u6570\u636e\u91cf\u65e0\u9650\u589e\u5927\uff0c\u80af\u5b9a\u4f1a\u8d85\u8fc7\u8fd9\u4e2a\u503c<\/p><\/blockquote>\n<p><strong>\u7528\u6237\u4e0d\u5173\u6ce8\u5168\u91cf<\/strong><\/p>\n<blockquote><p>\u67d0\u4e9b\u4e1a\u52a1\u573a\u666f\uff0c\u4e1a\u52a1\u66f4\u5173\u6ce8\u8fd1\u671f\u7684\u6570\u636e\uff0c\u5982\u8fd13\u5929\u3001\u8fd17\u5929\u5927\u7d22\u5f15\u4f1a\u5c06\u5168\u90e8\u5386\u53f2\u6570\u636e\u6c47\u96c6\u5728\u4e00\u8d77\uff0c\u4e0d\u5229\u4e8e\u8fd9\u79cd\u573a\u666f\u7684\u67e5\u8be2<\/p><\/blockquote>\n<h3>\u7d22\u5f15\u751f\u547d\u5468\u671f\u7ba1\u7406\u7684\u5386\u53f2\u6f14\u53d8<\/h3>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342009\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>LIM\u524d\u594f &#8211; rollover \u6eda\u52a8\u7d22\u5f15<\/h3>\n<blockquote><p>\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=J6uY9jWY09gOP6iZOOKoWQ%3D%3D.38BRD5FLcNcDJAtCwWc0rYSBofs38oLDlM23xypewtDQRSArW6hcvHVwXPJRLvu8Tno%2Fr9Yt8LNXvrB%2FCPGPHQe9Snt5GegWxTaNEgaR3vc%3D\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/index-rollover.html<\/a><\/p><\/blockquote>\n<pre><code># 0.\u81ea\u6d4b\u524d\u63d0\uff0clim\u751f\u547d\u5468\u671frollover\u9891\u7387\u3002\u9ed8\u8ba410\u5206\u949f\nPUT _cluster\/settings\n{\n  &quot;persistent&quot;: {\n    &quot;indices.lifecycle.poll_interval&quot;: &quot;1s&quot;\n  }\n}\n\n# 1. \u521b\u5efa\u7d22\u5f15\uff0c\u5e76\u6307\u5b9a\u522b\u540d\nPUT test_index-0001\n{\n  &quot;aliases&quot;: {\n    &quot;my-test-index-alias&quot;: {\n      &quot;is_write_index&quot;: true\n    }\n  }\n}\n\n# 2.\u6279\u91cf\u5bfc\u5165\u6570\u636e\nPUT my-test-index-alias\/_bulk\n{&quot;index&quot;:{&quot;_id&quot;:1}}\n{&quot;title&quot;:&quot;testing 01&quot;}\n{&quot;index&quot;:{&quot;_id&quot;:2}}\n{&quot;title&quot;:&quot;testing 02&quot;}\n{&quot;index&quot;:{&quot;_id&quot;:3}}\n{&quot;title&quot;:&quot;testing 03&quot;}\n{&quot;index&quot;:{&quot;_id&quot;:4}}\n{&quot;title&quot;:&quot;testing 04&quot;}\n{&quot;index&quot;:{&quot;_id&quot;:5}}\n{&quot;title&quot;:&quot;testing 05&quot;}\n\n# 3.rollover \u6eda\u52a8\u89c4\u5219\u914d\u7f6e\nPOST my-test-index-alias\/_rollover\n{\n  &quot;conditions&quot;: {\n    &quot;max_age&quot;: &quot;7d&quot;,\n    &quot;max_docs&quot;: 5,\n    &quot;max_primary_shard_size&quot;: &quot;50gb&quot;\n  }\n}\n\n# 4.\u5728\u6ee1\u8db3\u6761\u4ef6\u7684\u524d\u63d0\u4e0b\u521b\u5efa\u6eda\u52a8\u7d22\u5f15\nPUT my-test-index-alias\/_bulk\n{&quot;index&quot;:{&quot;_id&quot;:7}}\n{&quot;title&quot;:&quot;testing 07&quot;}\n\n# 5.\u67e5\u8be2\u9a8c\u8bc1\u6eda\u52a8\u662f\u5426\u6210\u529f\nPOST my-test-index-alias\/_search\n\n<\/code><\/pre>\n<h3>LIM\u524d\u594f &#8211; shrink \u7d22\u5f15\u538b\u7f29<\/h3>\n<blockquote>\n<p>\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=rUyrG4RZbo5C3bAeRzSVCw%3D%3D.KHZGvEFoVwGNjLEHOPhQbx06owTeaY66CJP1o%2FTUtXJUZEvYBx8cZLccje3mleLV7OnS22UG8YAGMlyAKOmv0H24TV53ELjr3%2F%2FodDkZjGQ%3D\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/ilm-shrink.html<\/a><\/p>\n<p>\u6838\u5fc3\u6b65\u9aa4\uff1a<\/p>\n<p>1. \u5c06\u6570\u636e\u5168\u90e8\u8fc1\u79fb\u81f3\u4e00\u4e2a\u72ec\u7acb\u7684\u8282\u70b9<\/p>\n<p>2. \u7d22\u5f15\u7981\u6b62\u5199\u5165<\/p>\n<p>3. \u65b9\u53ef\u8fdb\u884c\u538b\u7f29<\/p>\n<\/blockquote>\n<pre><code># 1.\u51c6\u5907\u6d4b\u8bd5\u6570\u636e\nDELETE kibana_sample_data_logs_ext\nPUT kibana_sample_data_logs_ext\n{\n  &quot;settings&quot;: {\n    &quot;number_of_shards&quot;: 5,\n    &quot;number_of_replicas&quot;: 0\n  }\n}\nPOST _reindex\n{\n  &quot;source&quot;: {\n    &quot;index&quot;: &quot;kibana_sample_data_logs&quot;\n  },\n  &quot;dest&quot;: {\n    &quot;index&quot;: &quot;kibana_sample_data_logs_ext&quot;\n  }\n}\n\n\n# 2.\u538b\u7f29\u524d\u5fc5\u8981\u7684\u6761\u4ef6\u8bbe\u7f6e\n# number_of_replicas :\u538b\u7f29\u540e\u526f\u672c\u4e3a0\n# index.routing.allocation.include._tier_preference \u6570\u636e\u5206\u7247\u5168\u90e8\u8def\u7531\u5230hot\u8282\u70b9\n# &quot;index.blocks.write \u538b\u7f29\u540e\u7d22\u5f15\u4e0d\u518d\u5141\u8bb8\u6570\u636e\u5199\u5165\nPUT kibana_sample_data_logs_ext\/_settings\n{\n  &quot;settings&quot;: {\n    &quot;index.number_of_replicas&quot;: 0,\n    &quot;index.routing.allocation.include._tier_preference&quot;: &quot;data_hot&quot;,\n    &quot;index.blocks.write&quot;: true\n  }\n}\n\n# 3.\u5b9e\u65bd\u538b\u7f29\nPOST kibana_sample_data_logs_ext\/_shrink\/kibana_sample_data_logs_ext_shrink\n{\n  &quot;settings&quot;:{\n    &quot;index.number_of_replicas&quot;: 0,\n    &quot;index.number_of_shards&quot;: 1,\n    &quot;index.codec&quot;:&quot;best_compression&quot;\n  },\n  &quot;aliases&quot;:{\n    &quot;kibana_sample_data_logs_alias&quot;:{}\n  }\n}\n\n<\/code><\/pre>\n<h3>LIM\u5b9e\u6218<\/h3>\n<h4>\u5168\u5c40\u8ba4\u77e5\u5efa\u7acb &#8211; \u56db\u5927\u9636\u6bb5<\/h4>\n<p>\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=6ntgLcut9sx%2BwV3VjaqXSA%3D%3D.4ewypF0CoTCJ1%2B337dc%2F8tV7LPU0esLMFwQvyTfX7v8kFXwSJBuKZYwxZk09Sh9uBk2bdOgGvvxYxEGr4G%2BOAWcehljgp8O7jGzfYEuBGx85U%2BhSekKVTJp9lWMID1IRboCip2BGf6DG0GXBkAktyQ%3D%3D\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/overview-index-lifecycle-management.html<\/a><\/p>\n<p>\u751f\u547d\u5468\u671f\u7ba1\u7406\u9636\u6bb5\uff08Policy\uff09\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=wcfwURiHIF4jQ5folWthnA%3D%3D.%2BVfSdEqUYT%2BV7i3QWFSRmB8JEkSNoQd6iqDAilO0W5NaK2Yj4%2F8hvKgmTMI4n%2BC76j58KKhjardGuPdf2VvyTKSOVcXri8fO39CIwJwz9zrAiGsJEcBT0egO5GOIesGg\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/ilm-index-lifecycle.html<\/a><\/p>\n<p><strong>Hot\u9636\u6bb5<\/strong>(\u751f)<\/p>\n<blockquote>\n<p>Set priority<\/p>\n<p>Unfollow<\/p>\n<p>Rollover<\/p>\n<p>Read-only<\/p>\n<p>Shrink<\/p>\n<p>Force Merge<\/p>\n<p>Search snapshot<\/p>\n<\/blockquote>\n<p><strong>Warm\u9636\u6bb5<\/strong>\uff08\u8001\uff09<\/p>\n<blockquote>\n<p>Set priority<\/p>\n<p>Unfollow<\/p>\n<p>Read-only<\/p>\n<p>Allocate<\/p>\n<p>migrate<\/p>\n<p>Shirink<\/p>\n<p>Force Merge<\/p>\n<\/blockquote>\n<p><strong>Cold\u9636\u6bb5<\/strong>\uff08\u75c5\uff09<\/p>\n<blockquote><p>Search snapshot<\/p><\/blockquote>\n<p><strong>Delete\u9636\u6bb5<\/strong>\uff08\u6b7b\uff09<\/p>\n<blockquote><p>delete<\/p><\/blockquote>\n<h4>\u6f14\u7ec3<\/h4>\n<h5>1.\u521b\u5efapolicy<\/h5>\n<ul>\n<li><strong>Hot<\/strong>\u9636\u6bb5\u8bbe\u7f6e\uff0crollover: max\/_age:3d\uff0cmax\/_docs:5, max_size:50gb, \u4f18\u5148\u7ea7\uff1a100<\/li>\n<li>Warm\u9636\u6bb5\u8bbe\u7f6e\uff1amin_age:15s , forcemerage\u6bb5\u5408\u5e76\uff0c\u70ed\u8282\u70b9\u8fc1\u79fb\u5230warm\u8282\u70b9\uff0c\u526f\u672c\u6570\u8bbe\u7f6e0\uff0c\u4f18\u5148\u7ea7\uff1a50<\/li>\n<li>Cold\u9636\u6bb5\u8bbe\u7f6e: min_age 30s, warm\u8fc1\u79fb\u5230cold\u9636\u6bb5<\/li>\n<li>Delete\u9636\u6bb5\u8bbe\u7f6e\uff1amin_age 45s\uff0c\u6267\u884c\u5220\u9664\u64cd\u4f5c<\/li>\n<\/ul>\n<pre><code>PUT _ilm\/policy\/kr_20221114_policy\n{\n  &quot;policy&quot;: {\n    &quot;phases&quot;: {\n      &quot;hot&quot;: {\n        &quot;min_age&quot;: &quot;0ms&quot;,\n        &quot;actions&quot;: {\n          &quot;set_priority&quot;: {\n            &quot;priority&quot;: 100\n          },\n          &quot;rollover&quot;: {\n            &quot;max_size&quot;: &quot;50gb&quot;,\n            &quot;max_primary_shard_size&quot;: &quot;50gb&quot;,\n            &quot;max_age&quot;: &quot;3d&quot;,\n            &quot;max_docs&quot;: 5\n          }\n        }\n      },\n      &quot;warm&quot;: {\n        &quot;min_age&quot;: &quot;15s&quot;,\n        &quot;actions&quot;: {\n          &quot;forcemerge&quot;: {\n            &quot;max_num_segments&quot;: 1\n          },\n          &quot;set_priority&quot;: {\n            &quot;priority&quot;: 50\n          },\n          &quot;allocate&quot;: {\n            &quot;number_of_replicas&quot;: 0\n          }\n        }\n      },\n      &quot;cold&quot;: {\n        &quot;min_age&quot;: &quot;30s&quot;,\n        &quot;actions&quot;: {\n          &quot;set_priority&quot;: {\n            &quot;priority&quot;: 0\n          }\n        }\n      },\n      &quot;delete&quot;: {\n        &quot;min_age&quot;: &quot;45s&quot;,\n        &quot;actions&quot;: {\n          &quot;delete&quot;: {\n            &quot;delete_searchable_snapshot&quot;: true\n          }\n        }\n      }\n    }\n  }\n}\n\n<\/code><\/pre>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342010\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h5>2.\u521b\u5efaindex template<\/h5>\n<pre><code>PUT _index_template\/kr_20221114_template\n{\n  &quot;index_patterns&quot;: [&quot;kr_index-**&quot;],\n  &quot;template&quot;: {\n    &quot;settings&quot;: {\n      &quot;index&quot;: {\n        &quot;lifecycle&quot;: {\n          &quot;name&quot;: &quot;kr_20221114_policy&quot;,\n          &quot;rollover_alias&quot;: &quot;kr-index-alias&quot;\n        },\n        &quot;routing&quot;: {\n          &quot;allocation&quot;: {\n            &quot;include&quot;: {\n              &quot;_tier_preference&quot;: &quot;data-hot&quot;\n            }\n          }\n        },\n        &quot;number_of_shards&quot;: &quot;3&quot;,\n        &quot;number_of_replicas&quot;: &quot;1&quot;\n      }\n    },\n    &quot;aliases&quot;: {},\n    &quot;mappings&quot;: {}\n  }\n}\n\n\n<\/code><\/pre>\n<h5>3.\u6d4b\u8bd5\u9700\u8981\u4fee\u6539lim rollover\u5237\u65b0\u9891\u7387<\/h5>\n<pre><code>PUT _cluster\/settings\n{\n  &quot;persistent&quot;: {\n    &quot;indices.lifecycle.poll_interval&quot;: &quot;1s&quot;\n  }\n}\n\n<\/code><\/pre>\n<h5>4.\u8fdb\u884c\u6d4b\u8bd5<\/h5>\n<pre><code># \u521b\u5efa\u7d22\u5f15\uff0c\u5e76\u5236\u5b9a\u53ef\u5199\u522b\u540d\nPUT kr_index-0001\n{\n  &quot;aliases&quot;: {\n    &quot;kr-index-alias&quot;: {\n      &quot;is_write_index&quot;: true\n    }\n  }\n}\n# \u901a\u8fc7\u522b\u540d\u65b0\u589e\u6570\u636e\nPUT kr-index-alias\/_bulk\n{&quot;index&quot;:{&quot;_id&quot;:1}}\n{&quot;title&quot;:&quot;testing 01&quot;}\n{&quot;index&quot;:{&quot;_id&quot;:2}}\n{&quot;title&quot;:&quot;testing 02&quot;}\n{&quot;index&quot;:{&quot;_id&quot;:3}}\n{&quot;title&quot;:&quot;testing 03&quot;}\n{&quot;index&quot;:{&quot;_id&quot;:4}}\n{&quot;title&quot;:&quot;testing 04&quot;}\n{&quot;index&quot;:{&quot;_id&quot;:5}}\n{&quot;title&quot;:&quot;testing 05&quot;}\n# \u901a\u8fc7\u522b\u540d\u65b0\u589e\u6570\u636e\uff0c\u89e6\u53d1rollover\nPUT kr-index-alias\/_bulk\n{&quot;index&quot;:{&quot;_id&quot;:6}}\n{&quot;title&quot;:&quot;testing 06&quot;}\n# \u67e5\u770b\u7d22\u5f15\u60c5\u51b5\nGET kr_index-0001\n\nget _cat\/indices?v\n\n<\/code><\/pre>\n<h5>\u8fc7\u7a0b\u603b\u7ed3<\/h5>\n<p>\u7b2c\u4e00\u6b65\uff1a\u914d\u7f6e lim pollicy<\/p>\n<ul>\n<li>\u6a2a\u5411\uff1aPhrase \u9636\u6bb5(Hot\u3001Warm\u3001Cold\u3001Delete) \u751f\u8001\u75c5\u6b7b<\/li>\n<li>\u7eb5\u5411\uff1aAction \u64cd\u4f5c\uff08rollover\u3001forcemerge\u3001readlyonly\u3001delete\uff09<\/li>\n<\/ul>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u521b\u5efa\u6a21\u677f \u7ed1\u5b9apolicy,\u6307\u5b9a\u522b\u540d<\/p>\n<p>\u7b2c\u4e09\u6b65\uff1a\u521b\u5efa\u8d77\u59cb\u7d22\u5f15<\/p>\n<p>\u7b2c\u56db\u6b65\uff1a\u7d22\u5f15\u57fa\u4e8e\u7b2c\u4e00\u6b65\u6307\u5b9a\u7684policy\u8fdb\u884c\u6eda\u52a8<\/p>\n<hr>\n<h2>\u4e94.Data Stream<\/h2>\n<blockquote><p>\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=WQnOgO15%2B0aZSHx9h2qnqA%3D%3D.wB%2FY04rkT1XVV5rqyvFHcnaYeoWhHLnXSwwFLWi8yYJCVSCiL6jhk1xW%2BrWG6nSg5jlgqfdg%2BW5jEsktCbAK80kjHfRH597dl8LsT6myoPg%3D\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/ilm-actions.html<\/a><\/p><\/blockquote>\n<h3>\u7279\u6027\u89e3\u6790<\/h3>\n<p>Data Stream\u8ba9\u6211\u4eec\u8de8\u591a\u4e2a\u7d22\u5f15\u5b58\u50a8\u65f6\u5e8f\u6570\u636e\uff0c\u540c\u65f6\u7ed9\u4e86\u552f\u4e00\u7684\u5bf9\u5916\u63a5\u53e3\uff08data stream\u540d\u79f0\uff09<\/p>\n<ul>\n<li>\u5199\u5165\u548c\u68c0\u7d22\u8bf7\u6c42\u53d1\u7ed9data stream<\/li>\n<li>data stream\u5c06\u8fd9\u4e9b\u8bf7\u6c42\u8def\u7531\u81f3 backing index\uff08\u540e\u53f0\u7d22\u5f15\uff09<\/li>\n<\/ul>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342011\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>Backing indices<\/h3>\n<p>\u6bcf\u4e2adata stream\u7531\u591a\u4e2a\u9690\u85cf\u7684\u540e\u53f0\u7d22\u5f15\u6784\u6210<\/p>\n<ul>\n<li>\u81ea\u52a8\u521b\u5efa<\/li>\n<li>\u8981\u6c42\u6a21\u677f\u7d22\u5f15<\/li>\n<\/ul>\n<p>rollover \u6eda\u52a8\u7d22\u5f15\u673a\u5236\u7528\u4e8e\u81ea\u52a8\u751f\u6210\u540e\u53f0\u7d22\u5f15<\/p>\n<ul>\n<li>\u5c06\u6210\u4e3adata stream \u65b0\u7684\u5199\u5165\u7d22\u5f15<\/li>\n<\/ul>\n<h3>\u5e94\u7528\u573a\u666f<\/h3>\n<ol>\n<li>\u65e5\u5fd7\u3001\u4e8b\u4ef6\u3001\u6307\u6807\u7b49\u5176\u4ed6\u6301\u7eed\u521b\u5efa\uff08\u5c11\u66f4\u65b0\uff09\u7684\u4e1a\u52a1\u6570\u636e<\/li>\n<li>\u4e24\u5927\u6838\u5fc3\u7279\u70b9<\/li>\n<li>\u65f6\u5e8f\u6027\u6570\u636e<\/li>\n<li>\u6570\u636e\u6781\u5c11\u66f4\u65b0\u6216\u6ca1\u6709\u66f4\u65b0<\/li>\n<\/ol>\n<h3>\u521b\u5efaData Stream \u6838\u5fc3\u6b65\u9aa4<\/h3>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043342012\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5b98\u7f51\u6587\u6863\u5730\u5740\uff1a  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=GAUSxKDFtTduMluQGupECQ%3D%3D.Jgd6I0ilmYC4D9YlV4J9Yox1%2BJs9gJ0vC38HpGGcGJqeEiz2dk1gxU7D3hm1cPVawsYdKV43AvNV0PK296W0tBTXN0xTgXO4gwuvDX7xpWm%2F4BRCwzrQ7dzjAbhpj7%2Fb\" rel=\"nofollow\">https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/8.1\/set-up-a-data-stream.html<\/a><\/p>\n<h4>Set up a data stream<\/h4>\n<p>To set up a data stream, follow these steps:<\/p>\n<ol>\n<li>Create an index lifecycle policy<\/li>\n<li>Create component templates<\/li>\n<li>Create an index template<\/li>\n<li>Create the data stream<\/li>\n<li>Secure the data stream<\/li>\n<\/ol>\n<h3>\u6f14\u7ec3<\/h3>\n<p>1. \u521b\u5efa\u4e00\u4e2adata stream\uff0c\u540d\u79f0\u4e3amy-data-stream<\/p>\n<p>2. index_template \u540d\u79f0\u4e3a my-index-template<\/p>\n<p>3. \u6ee1\u8db3index\u683c\u5f0f\u3010&#8221;my-data-stream*&#8221;\u3011\u7684\u7d22\u5f15\u90fd\u8981\u88ab\u5e94\u7528\u5230<\/p>\n<p>4. \u6570\u636e\u63d2\u5165\u7684\u65f6\u5019\uff0c\u5728data_hot\u8282\u70b9<\/p>\n<p>5. \u8fc73\u5206\u949f\u4e4b\u540e\u8981rollover\u5230data_warm\u8282\u70b9<\/p>\n<p>6. \u518d\u8fc75\u5206\u949f\u8981\u5230data_cold\u8282\u70b9<\/p>\n<pre><code># \u6b65\u9aa41 \u3002\u521b\u5efa lim policy\nPUT _ilm\/policy\/my-lifecycle-policy\n{\n  &quot;policy&quot;: {\n    &quot;phases&quot;: {\n      &quot;hot&quot;: {\n        &quot;actions&quot;: {\n          &quot;rollover&quot;: {\n            &quot;max_size&quot;: &quot;50gb&quot;,\n            &quot;max_age&quot;: &quot;3m&quot;,\n            &quot;max_docs&quot;: 5\n          },\n          &quot;set_priority&quot;: {\n            &quot;priority&quot;: 100\n          }\n        }\n      },\n      &quot;warm&quot;: {\n        &quot;min_age&quot;: &quot;5m&quot;,\n        &quot;actions&quot;: {\n          &quot;allocate&quot;: {\n            &quot;number_of_replicas&quot;: 0\n          }, \n          &quot;forcemerge&quot;: {\n            &quot;max_num_segments&quot;: 1\n          },\n          &quot;set_priority&quot;: {\n            &quot;priority&quot;: 50\n          }\n        }\n      },\n      &quot;cold&quot;: {\n        &quot;min_age&quot;: &quot;6m&quot;,\n        &quot;actions&quot;: {\n          &quot;freeze&quot;:{}\n        }\n      },\n      &quot;delete&quot;: {\n        &quot;min_age&quot;: &quot;45s&quot;,\n        &quot;actions&quot;: {\n          &quot;delete&quot;: {}\n        }\n      }\n    }\n  }\n}\n\n# \u6b65\u9aa42 \u521b\u5efa\u7ec4\u4ef6\u6a21\u677f - mapping\nPUT _component_template\/my-mappings\n{\n  &quot;template&quot;: {\n    &quot;mappings&quot;: {\n      &quot;properties&quot;: {\n        &quot;@timestamp&quot;: {\n          &quot;type&quot;: &quot;date&quot;,\n          &quot;format&quot;: &quot;date_optional_time||epoch_millis&quot;\n        },\n        &quot;message&quot;: {\n          &quot;type&quot;: &quot;wildcard&quot;\n        }\n      }\n    }\n  },\n  &quot;_meta&quot;: {\n    &quot;description&quot;: &quot;Mappings for @timestamp and message fields&quot;,\n    &quot;my-custom-meta-field&quot;: &quot;More arbitrary metadata&quot;\n  }\n}\n\n# \u6b65\u9aa43 \u521b\u5efa\u7ec4\u4ef6\u6a21\u677f - setting\nPUT _component_template\/my-settings\n{\n  &quot;template&quot;: {\n    &quot;settings&quot;: {\n      &quot;index.lifecycle.name&quot;: &quot;my-lifecycle-policy&quot;,\n      &quot;index.routing.allocation.include._tier_preference&quot;:&quot;data_hot&quot;\n    }\n  },\n  &quot;_meta&quot;: {\n    &quot;description&quot;: &quot;Settings for ILM&quot;,\n    &quot;my-custom-meta-field&quot;: &quot;More arbitrary metadata&quot;\n  }\n}\n\n# \u6b65\u9aa44 \u521b\u5efa\u7d22\u5f15\u6a21\u677f\nPUT _index_template\/my-index-template\n{\n  &quot;index_patterns&quot;: [&quot;my-data-stream*&quot;],\n  &quot;data_stream&quot;: { },\n  &quot;composed_of&quot;: [ &quot;my-mappings&quot;, &quot;my-settings&quot; ],\n  &quot;priority&quot;: 500,\n  &quot;_meta&quot;: {\n    &quot;description&quot;: &quot;Template for my time series data&quot;,\n    &quot;my-custom-meta-field&quot;: &quot;More arbitrary metadata&quot;\n  }\n}\n\n# \u6b65\u9aa45 \u521b\u5efa data stream  \u5e76 \u5199\u5165\u6570\u636e\u6d4b\u8bd5\nPUT my-data-stream\/_bulk\n{ &quot;create&quot;:{ } }\n{ &quot;@timestamp&quot;: &quot;2099-05-06T16:21:15.000Z&quot;, &quot;message&quot;: &quot;192.0.2.42 - - [06\/May\/2099:16:21:15 +0000] \/&quot;GET \/images\/bg.jpg HTTP\/1.0\/&quot; 200 24736&quot; }\n{ &quot;create&quot;:{ } }\n{ &quot;@timestamp&quot;: &quot;2099-05-06T16:25:42.000Z&quot;, &quot;message&quot;: &quot;192.0.2.255 - - [06\/May\/2099:16:25:42 +0000] \/&quot;GET \/favicon.ico HTTP\/1.0\/&quot; 200 3638&quot; }\n\nPOST my-data-stream\/_doc\n{\n  &quot;@timestamp&quot;: &quot;2099-05-06T16:21:15.000Z&quot;,\n  &quot;message&quot;: &quot;192.0.2.42 - - [06\/May\/2099:16:21:15 +0000] \/&quot;GET \/images\/bg.jpg HTTP\/1.0\/&quot; 200 24736&quot;\n}\n\n\n# \u6b65\u9aa46 \u67e5\u770bdata stream \u540e\u53f0\u7d22\u5f15\u4fe1\u606f\nGET \/_resolve\/index\/my-data-stream*\n<\/code><\/pre>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043342000\">https:\/\/segmentfault.com\/a\/1190000043342000<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eac\u4e1c\u7269\u6d41\uff1a\u5eb7\u777f \u59da\u518d\u6bc5 \u674e\u632f \u5218\u658c \u738b\u5317\u6c38 \u8bf4\u660e\uff1a\u4ee5\u4e0b\u5168\u90e8\u5747\u57fa\u4e8e ElasticSearch 8.1 \u7248\u672c \u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10007094","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10007094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10007094"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10007094\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10007094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10007094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10007094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}