{"id":10006499,"date":"2022-09-16T11:31:13","date_gmt":"2022-09-16T03:31:13","guid":{"rendered":"https:\/\/ityet.com\/?p=10006499"},"modified":"2022-09-16T11:31:13","modified_gmt":"2022-09-16T03:31:13","slug":"join%e5%ad%97%e6%ae%b5%e7%b1%bb%e5%9e%8b%e8%b6%85%e5%ae%b9%e6%98%93%e4%b8%8a%e6%89%8b%e7%9a%84%e5%a5%bd%e5%90%a7elasticsearch","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006499","title":{"rendered":"Join\u5b57\u6bb5\u7c7b\u578b\u8d85\u5bb9\u6613\u4e0a\u624b\u7684\u597d\u5427(Elasticsearch)"},"content":{"rendered":"<p>\u6700\u8fd1\u56e0\u4e3a\u5de5\u4f5c\u539f\u56e0\u5417\uff0c\u6bd4\u8f83\u5fd9\uff0c\u7136\u540e\u4e2a\u4eba\u4e5f\u6bd4\u8f83\u61d2\uff0c\u8f93\u51fa\u53c8\u6162\u4e0b\u6765\u4e86\uff0c\u540e\u9762\u4f1a\u6162\u6162\u6062\u590d\u7684\uff0c\u5b9a\u671f\u4fdd\u8bc1\u5468\u66f4\u5427\uff0c\u5e76\u4e14\u4fdd\u8bc1\u8d28\u91cf\u8f93\u51fa\u3002<\/p>\n<p>\u9605\u8bfb\u672c\u6587\u9700\u8981\u4e00\u5b9a\u7684<code>Elasticsearch<\/code>\u57fa\u7840\u54e6\uff0c\u672c\u6587\u6df1\u5ea6\u6709\uff0c\u4f46\u662f\u4e0d\u6df1<\/p>\n<h2>\u6982\u8ff0<\/h2>\n<p>Elasticsearch\u4e2d<code>Join<\/code>\u6570\u636e\u7c7b\u578b\u7684\u5b57\u6bb5\u76f8\u4fe1\u5927\u5bb6\u4e5f\u90fd\u7528\u8fc7\uff0c\u4e5f\u5c31\u662f\u53e3\u4e2d\u5e38\u8c08\u7684\u7236\u5b50\u6587\u6863\u3002\u5728Elasticsearch\u4e2d<code>Join<\/code>\u4e0d\u80fd\u8de8\u7d22\u5f15\u548c\u5206\u7247\uff0c\u6240\u4ee5\u4fdd\u5b58\u6587\u6863\u4fe1\u606f\u65f6\u8981\u4fdd\u8bc1\u7236\u5b50\u6587\u6863\u4f7f\u7528<strong>\u76f8\u540c\u7684\u8def\u7531\u53c2\u6570<\/strong>\u6765\u4fdd\u8bc1\u7236\u6587\u6863\u4e0e\u5b50\u6587\u6863\u4fdd\u5b58\u5728\u540c\u4e00\u4e2a\u7d22\u5f15\u7684\u540c\u4e00\u4e2a\u5206\u7247\uff0c\u90a3\u4e48\u90fd\u6709\u54ea\u4e9b\u9650\u5236\u5462\uff1f<\/p>\n<h2>\u7236\u5b50\u5173\u7cfb\u7684\u9650\u5236<\/h2>\n<ul>\n<li>\u6bcf\u4e2a\u7d22\u5f15\u4e2d\u53ea\u80fd\u6709\u4e00\u4e2a\u5173\u7cfb\u5b57\u6bb5<\/li>\n<li>\u7236\u6587\u6863\u4e0e\u5b50\u6587\u6863\u5fc5\u987b\u5728\u540c\u4e00\u4e2a\u7d22\u5f15\u5206\u7247\u4e2d\uff0c\u6240\u4ee5\u6211\u4eec\u5728\u5bf9\u7236\u5b50\u6587\u6863\u589e\u52a0\u3001\u5220\u9664\u3001\u4fee\u6539\u65f6\u8981\u8bbe\u7f6e\u8def\u7531\u503c\uff0c\u4fdd\u8bc1\u6570\u636e\u90fd\u5728\u540c\u4e00\u5206\u7247<\/li>\n<li>\u4e00\u4e2a\u7236\u6587\u6863\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u5b50\u6587\u6863\uff0c\u4f46\u662f\u4e00\u4e2a\u5b50\u6587\u6863\u53ea\u80fd\u6709\u4e00\u4e2a\u7236\u6587\u6863<\/li>\n<li>\u53ea\u80fd\u5728<code>Join<\/code>\u7c7b\u578b\u7684\u5b57\u6bb5\u4e0a\u5efa\u7acb\u5173\u7cfb<\/li>\n<li>\u5728\u4fdd\u8bc1\u5f53\u524d\u6587\u6863\u662f\u7236\u6587\u6863\u7684\u524d\u63d0\u4e0b\u53ef\u4ee5\u589e\u52a0\u5b50\u6587\u6863<\/li>\n<\/ul>\n<h2>Global ordinals<\/h2>\n<p>\u7ffb\u8bd1\u8fc7\u6765\u5c31\u662f\u5168\u5c40\u5e8f\u6570\u3002\u4ec0\u4e48\u662f\u5168\u5c40\u5e8f\u6570\u5462\uff0c\u5b98\u65b9\u6587\u6863\u4e2d\u8bf4\u660e\u4e86\uff0c\u8fd9\u5c31\u662f\u4e00\u4e2a\u52a0\u901f\u67e5\u8be2\u7684\u4e00\u4e2a\u4e1c\u897f\uff0c\u4f7f\u7528\u4e86\u5168\u5c40\u5e8f\u6570\u4e4b\u540e\u53ef\u4ee5\u8ba9\u6570\u636e\u66f4\u7d27\u51d1\uff1b\u8be6\u7ec6\u7684\u5c31\u4e0d\u5c55\u5f00\u4e86\uff0c\u540e\u9762\u6709\u673a\u4f1a\u518d\u8be6\u7ec6\u8bf4\u660e\u4e00\u4e0b\u5168\u5c40\u5e8f\u6570\uff0c\u5177\u4f53\u7684\u76ee\u524d\u53ef\u4ee5\u67e5\u770b\u4e00\u4e0b\u5b98\u65b9\u6587\u6863<\/p>\n<p>\u5bf9\u4e8e\u6211\u4eec\u672c\u7ae0\u8282\u5185\u5bb9\u6765\u8bf4\uff0c\u6211\u4eec\u77e5\u9053\u7236\u5b50\u6587\u6863<code>Join<\/code>\u7c7b\u578b\u662f\u4f7f\u7528\u5168\u5c40\u5e8f\u6570\u6765\u52a0\u901f\u67e5\u8be2\u7684\u5c31\u53ef\u4ee5\u4e86\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5168\u5c40\u5e8f\u6570\u57fa\u672c\u662f\u5b9e\u65f6\u6784\u5efa\u7684\uff0c\u5f53\u7d22\u5f15\u53d1\u751f\u53d8\u5316\uff0c\u5168\u5c40\u5e8f\u6570\u4f1a\u91cd\u65b0\u6784\u5efa\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u589e\u52a0<code>refresh<\/code>\u7684\u65f6\u95f4\uff0c\u5f53\u7136\u8fd9\u4e2a\u914d\u7f6e\u4e5f\u662f\u53ef\u4ee5\u5173\u95ed\u7684\uff0c\u4f46\u662f\u5173\u95ed\u4e4b\u540e\u4f1a\u5728\u6211\u4eec\u63a5\u4e0b\u6765\u9047\u5230\u7684\u7b2c\u4e00\u4e2a\u7236\u8fde\u63a5\u6216\u8005\u805a\u5408\u7684\u67e5\u8be2\u65f6\u91cd\u65b0\u6784\u5efa\u5168\u5c40\u5e8f\u6570\uff0c\u8fd9\u6837\u8fd9\u4e00\u90e8\u5206\u7684\u65f6\u95f4\u5c31\u53cd\u9988\u7ed9\u4e86\u7528\u6237\uff0c\u5b98\u65b9\u4e5f\u662f\u4e0d\u5efa\u8bae\u6211\u4eec\u8fd9\u6837\u505a\u7684\uff0c\u611f\u89c9\u5bf9\u7528\u6237\u6765\u8bf4\u4e0d\u662f\u90a3\u4e48\u7684\u53cb\u597d\uff0c\u4e3b\u8981\u8fd8\u662f\u5728\u4e00\u4e2a\u6743\u8861\u3002\u6700\u574f\u7684\u60c5\u51b5\u5c31\u662f\u540c\u65f6\u6709\u591a\u4e2a\u5199\u5165\uff0c\u4e5f\u5c31\u662f\u540c\u65f6\u6709\u591a\u4e2a\u5168\u5c40\u5e8f\u6570\u9700\u8981\u91cd\u65b0\u6784\u5efa\uff0c\u4e5f\u5c31\u4f1a\u9020\u6210\u5728\u5355\u4e2a<code>refresh<\/code>\u7684\u65f6\u95f4\u95f4\u9694\u5185\u8981\u91cd\u65b0\u6784\u5efa\u591a\u4e2a\u5168\u5c40\u5e8f\u6570<\/p>\n<p>\u5f53\u7136\u5982\u679c\u5173\u8054\u5b57\u6bb5\u4f7f\u7528\u7684\u4e0d\u662f\u5f88\u9891\u7e41\u5e76\u4e14\u5199\u5165\u4e8b\u4ef6\u5f88\u591a\uff0c\u7981\u7528\u6389\u662f\u503c\u5f97\u63a8\u8350\u7684\uff0c\u7981\u7528\u65b9\u5f0f\u5982\u4e0b<\/p>\n<pre><code class=\"text\">PUT my-index-000001\n{\n  &quot;mappings&quot;: {\n    &quot;properties&quot;: {\n      &quot;join_field&quot;: {\n        &quot;type&quot;: &quot;join&quot;,\n        &quot;relations&quot;: {\n           &quot;goods&quot;: [&quot;details&quot;,&quot;evaluate&quot;],\n           &quot;evaluate&quot;:&quot;vote&quot;\n        },\n        &quot;eager_global_ordinals&quot;: false\n      }\n    }\n  }\n}<\/code><\/pre>\n<p>\u5f53\u7136\uff0c\u5bf9\u4e8e\u5168\u5c40\u5e8f\u6570\u5360\u7528\u7684\u5806\u5927\u5c0f\u60c5\u51b5\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u8bed\u53e5\u67e5\u770b<\/p>\n<pre><code class=\"text\"># Per-index\nGET my-index-000001\/_stats\/fielddata?human&amp;fields=join_field#goods\n\n# Per-node per-index\nGET _nodes\/stats\/indices\/fielddata?human&amp;fields=join_field#goods<\/code><\/pre>\n<h2>\u7236\u5b50\u6587\u6863<\/h2>\n<ul>\n<li>\n<p>\u9996\u5148\u6211\u4eec\u8fd8\u662f\u521b\u5efa\u4e00\u4e2a\u6b63\u5e38\u7684\u7236\u5b50\u5173\u7cfb\u7d22\u5f15\uff0c<strong>\u5546\u54c1<\/strong>\u4f5c\u4e3a\u7236\u6587\u6863\uff0c<strong>\u8be6\u60c5<\/strong>\u4f5c\u4e3a\u5b50\u6587\u6863<\/p>\n<pre><code class=\"text\">DELETE my-index-000001\nPUT my-index-000001\n{\n  &quot;mappings&quot;: {\n    &quot;properties&quot;: {\n      &quot;id&quot;: {\n        &quot;type&quot;: &quot;keyword&quot;\n      },\n      &quot;join_field&quot;: { \n        &quot;type&quot;: &quot;join&quot;,\n        &quot;relations&quot;: {\n          &quot;goods&quot;: &quot;details&quot; \n        }\n      }\n    }\n  }\n}<\/code><\/pre>\n<ul>\n<li><strong>my-index-000001<\/strong>\uff1a\u7d22\u5f15\u540d\u79f0<\/li>\n<li><strong>id<\/strong>\uff1a\u6587\u6863\u4e3b\u952e<\/li>\n<li><strong>join_field<\/strong>\uff1a\u7236\u5b50\u5173\u7cfb\u5b57\u6bb5\uff0c<code>type<\/code>\u6807\u8bb0\u4e3a<code>Join<\/code>\u4e3a\u7236\u5b50\u6587\u6863<\/li>\n<li><strong>relations<\/strong>:  \u5b9a\u4e49\u7236\u5b50\u5173\u7cfb\uff0c<code>goods<\/code>\u4e3a\u7236\u6587\u6863\u7c7b\u578b\u540d\u79f0\uff0c<code>details<\/code>\u4e3a\u5b50\u6587\u6863\u7c7b\u578b\u540d\u79f0\uff0c\u540e\u9762\u63d2\u5165\u6570\u636e\uff0c\u67e5\u8be2\u90fd\u4f1a\u4f7f\u7528<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u63d2\u5165\u51e0\u6761\u6d4b\u8bd5\u6570\u636e\uff0c\u5546\u54c1\u6709<strong>iphon<\/strong>\u548c<strong>mac<\/strong>\uff0c\u8be6\u60c5\u4e3a\u989c\u8272\u5916\u89c2\u4e0e\u5185\u5b58\u914d\u7f6e\u7b49<\/p>\n<pre><code class=\"text\">PUT my-index-000001\/_doc\/1?refresh\n{\n  &quot;id&quot;: &quot;1&quot;,\n  &quot;text&quot;: &quot;iphone 14 pro max&quot;,\n  &quot;join_field&quot;: {\n    &quot;name&quot;: &quot;goods&quot; \n  }\n}\n\nPUT my-index-000001\/_doc\/2?refresh\n{\n  &quot;id&quot;: &quot;2&quot;,\n  &quot;text&quot;: &quot;macbook pro &quot;,\n  &quot;join_field&quot;: {\n    &quot;name&quot;: &quot;goods&quot;\n  }\n}\n\nPUT my-index-000001\/_doc\/3?routing=1&amp;refresh \n{\n  &quot;id&quot;: &quot;3&quot;,\n  &quot;text&quot;: &quot;512G 16\u6838&quot;,\n  &quot;join_field&quot;: {\n    &quot;name&quot;: &quot;details&quot;, \n    &quot;parent&quot;: &quot;1&quot; \n  }\n}\n\nPUT my-index-000001\/_doc\/4?routing=1&amp;refresh\n{\n  &quot;id&quot;: &quot;4&quot;,\n  &quot;text&quot;: &quot;\u7c89\/\u94f6\/\u9ed1\/\u62b9\u8336\u7eff&quot;,\n  &quot;join_field&quot;: {\n    &quot;name&quot;: &quot;details&quot;,\n    &quot;parent&quot;: &quot;1&quot;\n  }\n}\nPUT my-index-000001\/_doc\/5?routing=1&amp;refresh \n{\n  &quot;id&quot;: &quot;5&quot;,\n  &quot;text&quot;: &quot;1T 32G&quot;,\n  &quot;join_field&quot;: {\n    &quot;name&quot;: &quot;details&quot;, \n    &quot;parent&quot;: &quot;2&quot; \n  }\n}\n\nPUT my-index-000001\/_doc\/6?routing=1&amp;refresh\n{\n  &quot;id&quot;: &quot;6&quot;,\n  &quot;text&quot;: &quot;\u94f6\/\u9ed1&quot;,\n  &quot;join_field&quot;: {\n    &quot;name&quot;: &quot;details&quot;,\n    &quot;parent&quot;: &quot;2&quot;\n  }\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u4f7f\u7528<code>parent_id<\/code>\u67e5\u8be2\u7236\u5b50\u6587\u6863\uff0c\u4ee5\u4e0a\u9762\u63d2\u5165\u7684\u6d4b\u8bd5\u6570\u636e\u67e5\u8be2\uff0c\u67e5\u627e<code>mac<\/code>\u7684\u8be6\u60c5\u4fe1\u606f\u8bed\u53e5\u5982\u4e0b\uff0c\u524d\u63d0\u662f\u77e5\u9053\u7236\u6587\u6863\u7684<code>id<\/code><\/p>\n<pre><code class=\"text\">GET my-index-000001\/_search\n{\n  &quot;query&quot;: {\n    &quot;parent_id&quot;: {\n      &quot;type&quot;: &quot;details&quot;,\n      &quot;id&quot;:&quot;2&quot;\n    }\n  },\n  &quot;sort&quot;:[&quot;id&quot;]\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u5927\u90e8\u5206\u60c5\u51b5\u4e0a\u9762\u662f\u4e0d\u80fd\u6ee1\u8db3\u6211\u4eec\u7684\u67e5\u8be2\u8bf7\u6c42\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>has_parent<\/code>\u6216\u8005<code>has_child<\/code>\u67e5\u8be2<\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528<code>has_parent<\/code>\u67e5\u8be2\uff1a\u7236\u6587\u6863<code>goods<\/code>\u4e2d\u6240\u6709\u5305\u542b<code>macbook<\/code>\u7684\u5b50\u6587\u6863\uff08\u540e\u6587\u7684\u5b59\u5b50\u6587\u6863\u4e5f\u53ef\u4ee5\u67e5\u8be2\uff09<\/p>\n<pre><code class=\"text\">GET my-index-000001\/_search\n{\n  &quot;query&quot;: {\n    &quot;has_parent&quot;: {\n      &quot;parent_type&quot;: &quot;goods&quot;,\n      &quot;query&quot;: {\n        &quot;match&quot;: {\n          &quot;text&quot;: &quot;macbook&quot;\n        }\n      }\n    }\n  }\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u4f7f\u7528<code>hash_child<\/code>\u67e5\u770b<code>details<\/code>\u5b50\u6587\u6863\u4e2d\u6709<code>1T<\/code>\u5173\u952e\u5b57\u7684\u6240\u6709\u7236\u6587\u6863<\/p>\n<pre><code class=\"text\">GET my-index-000001\/_search\n{\n  &quot;query&quot;: {\n    &quot;has_child&quot;: {\n      &quot;type&quot;: &quot;details&quot;,\n      &quot;query&quot;: {\n        &quot;match&quot;: {\n          &quot;text&quot;: &quot;1T&quot;\n        }\n      }\n    }\n  }\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u4f7f\u7528<code>parent-join <\/code>\u67e5\u8be2\u6216\u8005\u805a\u5408<\/p>\n<p><code>Elasticsearch<\/code>\u5728\u4f7f\u7528<code>Join<\/code>\u7c7b\u578b\u6570\u636e\u7c7b\u578b\u65f6\uff0c\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u9644\u52a0\u7684\u5b57\u6bb5\uff0c\u7ed3\u6784\u4e3a<code>Join<\/code>\u7684\u5b57\u6bb5\u540d\u52a0<code>#\u53f7<\/code>\u52a0\u7236\u7c7b\u578b\uff0c\u4ee5\u4e0a\u6587\u4e3a\u4f8b\uff0c\u521b\u5efa\u4e00\u4e2a\u9644\u52a0\u5b57\u6bb5(<code>join_field#goods<\/code>)\uff0c\u5982\u4e0b\u662f\u4f7f\u7528<code>parent-join<\/code>\u5b57\u6bb5\u67e5\u8be2\u805a\u5408\u7684\u4e00\u4e2a\u4f8b\u5b50\uff0c\u53c2\u8003\u81ea\u5b98\u7f51\uff0c\u5e94\u7528\u4e86<code>8.1\u7248\u672c<\/code>\u7684\u65b0\u7279\u6027<strong>\u8fd0\u884c\u65f6\u5b57\u6bb5<\/strong><\/p>\n<pre><code class=\"text\">GET my-index-000001\/_search\n{\n  &quot;query&quot;: {\n    &quot;parent_id&quot;: { \n      &quot;type&quot;: &quot;details&quot;,\n      &quot;id&quot;: &quot;1&quot;\n    }\n  },\n  &quot;aggs&quot;: {\n    &quot;parents&quot;: {\n      &quot;terms&quot;: {\n        &quot;field&quot;: &quot;join_field#goods&quot;, \n        &quot;size&quot;: 10\n      }\n    }\n  },\n  &quot;runtime_mappings&quot;: {\n    &quot;my_parent_field&quot;: {\n      &quot;type&quot;: &quot;long&quot;,\n      &quot;script&quot;: &quot;&quot;&quot;\n        emit(Integer.parseInt(doc['join_field#goods'].value)) \n      &quot;&quot;&quot;\n    }\n  },\n  &quot;fields&quot;: [\n    { &quot;field&quot;: &quot;my_parent_field&quot; }\n  ]\n}<\/code><\/pre>\n<\/li>\n<li>\n<p><code>Join<\/code>\u7c7b\u578b\u7684\u7236\u5b50\u6587\u6863\uff0c\u4e0a\u9762\u6211\u4eec\u6f14\u793a\u4e86\u4e00\u4e2a\u7236\u6587\u6863\u5bf9\u5e94\u4e00\u79cd\u5b50\u6587\u6863\u7c7b\u578b\u7684\u4f8b\u5b50\uff0c<code>Join<\/code>\u7c7b\u578b\u4e5f\u652f\u6301\u4e00\u4e2a\u7236\u7c7b\u578b\u6709\u591a\u4e2a\u5b50\u7c7b\u578b\uff0c\u4ee5\u4e0a\u6587\u4e3a\u57fa\u7840\uff0c\u52a0\u5165\u4e0b\u9762\u8bed\u53e5\u6d4b\u8bd5<\/p>\n<pre><code class=\"text\">DELETE my-index-000001\nPUT my-index-000001\n{\n  &quot;mappings&quot;: {\n    &quot;properties&quot;: {\n      &quot;id&quot;: {\n        &quot;type&quot;: &quot;keyword&quot;\n      },\n      &quot;join_field&quot;: { \n        &quot;type&quot;: &quot;join&quot;,\n        &quot;relations&quot;: {\n          &quot;goods&quot;: [&quot;details&quot;,&quot;evaluate&quot;] \n        }\n      }\n    }\n  }\n}\nPUT my-index-000001\/_doc\/7?routing=1&amp;refresh\n{\n  &quot;id&quot;: &quot;7&quot;,\n  &quot;text&quot;: &quot;\u8fd0\u884c\u6d41\u7a0b\uff0c\u65e0\u5361\u987f\uff0c\u5f85\u673a\u65f6\u95f4\u957f&quot;,\n  &quot;join_field&quot;: {\n    &quot;name&quot;: &quot;evaluate&quot;,\n    &quot;parent&quot;: &quot;1&quot;\n  }\n}\nPUT my-index-000001\/_doc\/8?routing=1&amp;refresh\n{\n  &quot;id&quot;: &quot;8&quot;,\n  &quot;text&quot;: &quot;\u4f53\u91cd\u8f7b\uff0c\u643a\u5e26\u65b9\u4fbf\uff0c\u7f16\u7801\u5229\u5668&quot;,\n  &quot;join_field&quot;: {\n    &quot;name&quot;: &quot;evaluate&quot;,\n    &quot;parent&quot;: &quot;2&quot;\n  }\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>\u540c\u6837\u7684\uff0c\u7ec6\u5fc3\u7684\u540c\u5b66\u5df2\u7ecf\u770b\u5230\u4e86\uff0c\u4e0a\u6587\u5df2\u7ecf\u6807\u8bb0\u4e86\u5b59\u5b50\u6587\u6863\uff0c\u5bf9\u7684\uff0c\u4f60\u6ca1\u770b\u9519\u5c31\u662f\u5b59\u5b50\u6587\u6863\uff0c\u4e09\u7ea7\u7684\u5c42\u7ea7\uff0c\u7ea7\u522b\u53ef\u4ee5\u66f4\u6df1\uff0c\u4f46\u662f<code>Elasticsearch<\/code>\u4e0d\u5efa\u8bae\u5f88\u6df1\u7684\u5c42\u6b21\uff0c\u6bd5\u7adf<code>Join<\/code>\u5f88\u6d88\u8017\u6027\u80fd\u7684\uff0c\u5c42\u7ea7\u518d\u6df1\u70b9\u6ca1\u6cd5\u7528\u4e86,\u4e0b\u9762\u5c31\u662f\u591a\u7ea7\u522b\u7684\u8bed\u53e5\u6d4b\u8bd5\uff0c\u6b64\u65f6\u4ed6\u4eec\u4e09\u8005\u7684\u5173\u7cfb\u5c31\u5982\u4e0b\u6240\u793a<\/li>\n<\/ul>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042489665\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<pre><code class=\"text\">DELETE my-index-000001\nPUT my-index-000001\n{\n  &quot;mappings&quot;: {\n    &quot;properties&quot;: {\n      &quot;id&quot;: {\n        &quot;type&quot;: &quot;keyword&quot;\n      },\n      &quot;join_field&quot;: { \n        &quot;type&quot;: &quot;join&quot;,\n        &quot;relations&quot;: {\n          &quot;goods&quot;: [&quot;details&quot;,&quot;evaluate&quot;],\n          &quot;evaluate&quot;:&quot;vote&quot;\n        }\n      }\n    }\n  }\n}\nPUT my-index-000001\/_doc\/9?routing=1&amp;refresh\n{\n  &quot;id&quot;: &quot;9&quot;,\n  &quot;text&quot;: &quot;\u8fd9\u662f\u6295\u7968\u4fe1\u606f\uff1a\u6211\u4e70iphone\u662f\u56e0\u4e3a\u6027\u4ef7\u6bd4\u9ad8\uff0c\u4fdd\u503c&quot;,\n  &quot;join_field&quot;: {\n    &quot;name&quot;: &quot;vote&quot;,\n    &quot;parent&quot;: &quot;1&quot;\n  }\n}\nPUT my-index-000001\/_doc\/10?routing=1&amp;refresh\n{\n  &quot;id&quot;: &quot;10&quot;,\n  &quot;text&quot;: &quot;\u8fd9\u662f\u6295\u7968\u4fe1\u606f\uff1a\u6211\u4e70mac\u662f\u56e0\u4e3a\u8f7b\uff0c\u643a\u5e26\u65b9\u4fbf\uff0c\u6ca1\u6709\u6d41\u6c13\u8f6f\u4ef6&quot;,\n  &quot;join_field&quot;: {\n    &quot;name&quot;: &quot;vote&quot;,\n    &quot;parent&quot;: &quot;2&quot;\n  }\n}<\/code><\/pre>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u76f8\u4fe1\u5927\u5bb6\u4e5f\u770b\u51fa\u6765\u4e86\uff0c\u5b98\u65b9\u90fd\u4e0d\u5efa\u8bae\u4f7f\u7528\u7236\u5b50\u6587\u6863\u7684\uff0c\u6bd5\u7adf\u6027\u80fd\u662f\u4e00\u5927\u95ee\u9898\uff0c\u76f8\u4fe1\u5927\u5bb6\u7528<code>Elasticsearch<\/code>\u80af\u5b9a\u5927\u90e8\u5206\u90fd\u662f\u56fe\u901f\u5ea6\u5feb\uff0c\u7528\u4e86<code>Join<\/code>\u5b57\u6bb5\u53d8\u6162\u4e86\uff0c\u8fd9\u8c01\u80fd\u540c\u610f\u5462\u662f\u5427\uff0c\u6709\u5229\u6709\u5f0a\u5427\uff0c\u770b\u5927\u5bb6\u9009\u62e9\uff0c\u4e0b\u4e00\u7bc7\u5e26\u7ed9\u5927\u5bb6\u7684\u7b97\u662f<code>Elasticsearch<\/code>\u63a8\u8350<code>Join<\/code>\u5b57\u6bb5\u66ff\u4ee3\u7c7b\u578b<code>Nested<\/code><\/p>\n<p>\u672c\u6587\u7531<a href=\"https:\/\/link.segmentfault.com\/?enc=BUHq%2FFS7tNuszmG5jBPG4Q%3D%3D.IoenKeqP4LQ3t8KN5YyRRKxa3K%2FEVGpDkf%2BWYrTU38E%3D\" rel=\"nofollow\">mdnice<\/a>\u591a\u5e73\u53f0\u53d1\u5e03<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042489663\">https:\/\/segmentfault.com\/a\/1190000042489663<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u56e0\u4e3a\u5de5\u4f5c\u539f\u56e0\u5417\uff0c\u6bd4\u8f83\u5fd9\uff0c\u7136\u540e\u4e2a\u4eba\u4e5f\u6bd4\u8f83\u61d2\uff0c\u8f93\u51fa\u53c8\u6162\u4e0b\u6765\u4e86\uff0c\u540e\u9762\u4f1a\u6162\u6162\u6062\u590d\u7684\uff0c\u5b9a\u671f\u4fdd\u8bc1\u5468\u66f4\u5427\uff0c\u5e76\u4e14\u4fdd\u8bc1\u8d28\u91cf\u8f93 [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006499","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006499","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"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006499"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006499\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}