{"id":16483,"date":"2023-12-05T10:36:21","date_gmt":"2023-12-05T02:36:21","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=16483"},"modified":"2023-12-16T10:54:25","modified_gmt":"2023-12-16T02:54:25","slug":"elasticsearch-suo-yin-wen-dang-de-guo-cheng-4","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/05\/elasticsearch-suo-yin-wen-dang-de-guo-cheng-4\/","title":{"rendered":"ElasticSearch\u7d22\u5f15\u6587\u6863\u7684\u8fc7\u7a0b\uff1f"},"content":{"rendered":"<p>\u5728Elasticsearch\u4e2d\uff0c\u7d22\u5f15\u6587\u6863\u7684\u8fc7\u7a0b\u6d89\u53ca\u5230\u5c06\u6587\u6863\u5b58\u50a8\u5230\u4e00\u4e2a\u7d22\u5f15\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u8fdb\u884c\u641c\u7d22\u548c\u5206\u6790\u3002\u4ee5\u4e0b\u662f\u7d22\u5f15\u6587\u6863\u7684\u4e00\u822c\u8fc7\u7a0b\uff1a<\/p>\n<ol>\n<li>\n<strong>\u521b\u5efa\u7d22\u5f15\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u7d22\u5f15\u6587\u6863\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u76ee\u6807\u7d22\u5f15\u5df2\u7ecf\u5b58\u5728\u3002\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u7ba1\u7406 API \u6216\u901a\u8fc7 Elasticsearch \u7684\u7ba1\u7406\u5de5\u5177\uff08\u5982Kibana\uff09\u521b\u5efa\u4e00\u4e2a\u7d22\u5f15\u3002\u5982\u679c\u7d22\u5f15\u5df2\u7ecf\u5b58\u5728\uff0c\u53ef\u4ee5\u76f4\u63a5\u8df3\u8fc7\u8fd9\u4e00\u6b65\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-json\">PUT \/my_index\n{\n  &quot;settings&quot;: {\n    &quot;number_of_shards&quot;: 3,\n    &quot;number_of_replicas&quot;: 2\n  },\n  &quot;mappings&quot;: {\n    &quot;properties&quot;: {\n      &quot;field1&quot;: { &quot;type&quot;: &quot;text&quot; },\n      &quot;field2&quot;: { &quot;type&quot;: &quot;keyword&quot; }\n    }\n  }\n}\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\uff0c\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a <code>my_index<\/code> \u7684\u7d22\u5f15\uff0c\u5e76\u5b9a\u4e49\u4e86\u7d22\u5f15\u7684\u8bbe\u7f6e\u548c\u6620\u5c04\u3002\n<\/li>\n<li>\n<strong>\u51c6\u5907\u6587\u6863\u6570\u636e\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u5c06\u6587\u6863\u7d22\u5f15\u4e4b\u524d\uff0c\u9700\u8981\u51c6\u5907\u6587\u6863\u7684\u6570\u636e\u3002\u6587\u6863\u662f\u4e00\u4e2aJSON\u683c\u5f0f\u7684\u5bf9\u8c61\uff0c\u5305\u542b\u8981\u7d22\u5f15\u7684\u5b57\u6bb5\u548c\u76f8\u5e94\u7684\u503c\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;field1&quot;: &quot;value1&quot;,\n  &quot;field2&quot;: &quot;value2&quot;\n}\n<\/code><\/pre>\n<\/li>\n<li>\n<strong>\u7d22\u5f15\u6587\u6863\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u7d22\u5f15 API \u5c06\u6587\u6863\u7d22\u5f15\u5230\u6307\u5b9a\u7684\u7d22\u5f15\u4e2d\u3002\u7d22\u5f15 API \u5141\u8bb8\u4f60\u6307\u5b9a\u6587\u6863\u7684ID\uff0c\u5982\u679c\u4e0d\u6307\u5b9a\uff0cElasticsearch\u5c06\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u552f\u4e00\u7684ID\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-json\">POST \/my_index\/_doc\/1\n{\n  &quot;field1&quot;: &quot;value1&quot;,\n  &quot;field2&quot;: &quot;value2&quot;\n}\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\uff0c\u6587\u6863\u88ab\u7d22\u5f15\u5230 <code>my_index<\/code> \u7d22\u5f15\u7684 <code>_doc<\/code> \u7c7b\u578b\u4e0b\uff0c\u4f7f\u7528ID\u4e3a <code>1<\/code>\u3002\n<\/li>\n<li>\n<strong>\u7d22\u5f15\u54cd\u5e94\uff1a<\/strong><\/p>\n<ul>\n<li>\u7d22\u5f15\u64cd\u4f5c\u5c06\u8fd4\u56de\u4e00\u4e2a\u54cd\u5e94\uff0c\u5176\u4e2d\u5305\u542b\u6709\u5173\u7d22\u5f15\u64cd\u4f5c\u662f\u5426\u6210\u529f\u4ee5\u53ca\u76f8\u5173\u5143\u4fe1\u606f\u7684\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;_index&quot;: &quot;my_index&quot;,\n  &quot;_type&quot;: &quot;_doc&quot;,\n  &quot;_id&quot;: &quot;1&quot;,\n  &quot;_version&quot;: 1,\n  &quot;result&quot;: &quot;created&quot;,\n  &quot;_shards&quot;: {\n    &quot;total&quot;: 2,\n    &quot;successful&quot;: 1,\n    &quot;failed&quot;: 0\n  },\n  &quot;_seq_no&quot;: 0,\n  &quot;_primary_term&quot;: 1\n}\n<\/code><\/pre>\n<p>\u54cd\u5e94\u4e2d\u7684 <code>result<\/code> \u5b57\u6bb5\u8868\u793a\u6587\u6863\u662f\u5426\u662f\u65b0\u521b\u5efa\u7684\u3002\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\uff0c<code>result<\/code> \u4e3a <code>&quot;created&quot;<\/code>\uff0c\u8868\u793a\u6587\u6863\u662f\u65b0\u521b\u5efa\u7684\u3002\n<\/li>\n<li>\n<strong>\u66f4\u65b0\u6587\u6863\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u9700\u8981\u66f4\u65b0\u6587\u6863\uff0c\u53ef\u4ee5\u4f7f\u7528\u66f4\u65b0 API\u3002\u66f4\u65b0\u64cd\u4f5c\u4f1a\u5728\u73b0\u6709\u6587\u6863\u7684\u57fa\u7840\u4e0a\u8fdb\u884c\u66f4\u65b0\uff0c\u800c\u4e0d\u662f\u91cd\u65b0\u7d22\u5f15\u6574\u4e2a\u6587\u6863\u3002\u66f4\u65b0\u64cd\u4f5c\u5141\u8bb8\u4f60\u4fee\u6539\u6587\u6863\u4e2d\u7684\u5b57\u6bb5\u503c\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-json\">POST \/my_index\/_doc\/1\/_update\n{\n  &quot;doc&quot;: {\n    &quot;field2&quot;: &quot;new_value&quot;\n  }\n}\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\uff0c\u6587\u6863ID\u4e3a <code>1<\/code> \u7684 <code>field2<\/code> \u5b57\u6bb5\u88ab\u66f4\u65b0\u4e3a <code>&quot;new_value&quot;<\/code>\u3002\n<\/li>\n<\/ol>\n<p>\u8fd9\u6837\uff0c\u6587\u6863\u5c31\u88ab\u6210\u529f\u7d22\u5f15\u5230 Elasticsearch \u4e2d\u3002\u7d22\u5f15\u6587\u6863\u7684\u8fc7\u7a0b\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u7684\u9700\u6c42\u548c\u4f7f\u7528\u573a\u666f\u8fdb\u884c\u8c03\u6574\u548c\u6269\u5c55\u3002\u8bf7\u67e5\u9605<a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/index.html\">Elasticsearch\u5b98\u65b9\u6587\u6863<\/a>\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Elasticsearch\u4e2d\uff0c\u7d22\u5f15\u6587\u6863\u7684\u8fc7\u7a0b\u6d89\u53ca\u5230\u5c06\u6587\u6863\u5b58\u50a8\u5230\u4e00\u4e2a\u7d22\u5f15\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u8fdb\u884c\u641c\u7d22\u548c\u5206\u6790\u3002\u4ee5\u4e0b\u662f\u7d22\u5f15 [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[125],"tags":[],"class_list":["post-16483","post","type-post","status-publish","format-standard","hentry","category-elasticsearch"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/16483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=16483"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/16483\/revisions"}],"predecessor-version":[{"id":48389,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/16483\/revisions\/48389"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=16483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=16483"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=16483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}