{"id":10006601,"date":"2022-09-26T16:34:24","date_gmt":"2022-09-26T08:34:24","guid":{"rendered":"https:\/\/ityet.com\/?p=10006601"},"modified":"2022-09-26T16:34:24","modified_gmt":"2022-09-26T08:34:24","slug":"nested%e5%b5%8c%e5%a5%97%e5%af%b9%e8%b1%a1%e7%b1%bb%e5%9e%8b%e8%bf%98%e6%8c%ba%e5%ae%9e%e7%94%a8","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006601","title":{"rendered":"Nested\u5d4c\u5957\u5bf9\u8c61\u7c7b\u578b\u8fd8\u633a\u5b9e\u7528"},"content":{"rendered":"<p>\u4e0a\u4e00\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5b66\u4e60\u4e86<code>Join<\/code>\u7c7b\u578b\u7684\u7236\u5b50\u6587\u6863\uff0c\u4eca\u5929\u7ee7\u7eed\u5b66\u4e60\u4e00\u4e0b\u5d4c\u5957\u6587\u6863\uff0c\u6bd5\u7adf\u5d4c\u5957\u6587\u6863\u4e5f\u662f<code>Elasticsearch<\/code>\u63a8\u8350\u7684\uff0c\u9996\u5148\u6211\u4eec\u770b\u4e0b\u9762\u8fd9\u6761\u8bed\u53e5<\/p>\n<pre><code class=\"text\">PUT word_document\/_doc\/1\n{\n  &quot;title&quot; : &quot;up&quot;,\n  &quot;user&quot; : [ \n    {\n      &quot;name&quot; : &quot;honghong&quot;,\n      &quot;sex&quot; :  &quot;female&quot;,\n      &quot;numberOfLikes&quot;:500\n    },\n    {\n      &quot;name&quot; : &quot;mingming&quot;,\n      &quot;sex&quot; :  &quot;male&quot;,\n      &quot;numberOfLikes&quot;:50\n    },\n    {\n      &quot;name&quot; : &quot;lanlan&quot;,\n      &quot;sex&quot; :  &quot;male&quot;,\n      &quot;numberOfLikes&quot;:100\n    }\n  ]\n}<\/code><\/pre>\n<p>\u5bf9\u4e8e\u4e0a\u9762\u8fd9\u79cd\u683c\u5f0f\u7684\u6570\u636e\uff0c<code>user<\/code>\u5c31\u662f\u5d4c\u5957\u5bf9\u8c61\u6570\u7ec4\uff0c\u90a3\u4e48<code>user<\/code>\u5728<code>Elasticsearch<\/code>\u4e2d\u662f\u600e\u4e48\u5b58\u50a8\u7684\u5462\uff1f\u5982\u679c\u6211\u4eec\u8981\u5bf9\u5d4c\u5957\u7684\u5b50\u5bf9\u8c61\u8fdb\u884c\u68c0\u7d22\uff0c\u600e\u4e48\u624d\u80fd\u68c0\u7d22\u51fa\u6211\u4eec\u6240\u9700\u8981\u7684\u6570\u636e\u5462\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u7814\u7a76\u4e0b<code>Nested<\/code>\u6570\u636e\u7c7b\u578b<\/p>\n<h2>\u73af\u5883<\/h2>\n<ul>\n<li>macos 10.14.6<\/li>\n<li>Elasticsearch 8.1<\/li>\n<li>Kibana 8.1<\/li>\n<\/ul>\n<h2>Nested<\/h2>\n<p>\u5f00\u5934\u6211\u4eec\u8fd8\u662f\u5148\u4e86\u89e3\u4e00\u4e0b\uff0c\u4ec0\u4e48\u662f<code>Nested<\/code>\u7c7b\u578b\uff0c\u5176\u5b9e\u5c31\u662f\u5b57\u9762\u610f\u601d\uff0c<code>Nested<\/code>\u5c31\u662f\u5d4c\u5957\uff0c\u4e5f\u5c31\u662f\u6587\u7ae0\u5f00\u5934<code>user<\/code>\u6570\u636e\u7c7b\u578b\u90a3\u79cd\uff0c\u6240\u4ee5\u53ef\u4ee5\u770b\u4e3a\u662f\u4e00\u79cd\u7279\u6b8a\u7684<code>Object<\/code>\u7c7b\u578b\u3002\u8fd8\u662f\u4ee5\u6587\u7ae0\u5f00\u5934\u7684\u6570\u636e\u4e3a\u4f8b<\/p>\n<pre><code class=\"text\">PUT word_document\/_doc\/1\n{\n  &quot;title&quot; : &quot;up&quot;,\n  &quot;user&quot; : [ \n    {\n      &quot;name&quot; : &quot;honghong&quot;,\n      &quot;sex&quot; :  &quot;female&quot;,\n      &quot;numberOfLikes&quot;:500\n    },\n    {\n      &quot;name&quot; : &quot;mingming&quot;,\n      &quot;sex&quot; :  &quot;male&quot;,\n      &quot;numberOfLikes&quot;:50\n    },\n    {\n      &quot;name&quot; : &quot;lanlan&quot;,\n      &quot;sex&quot; :  &quot;male&quot;,\n      &quot;numberOfLikes&quot;:100\n    }\n  ]\n}<\/code><\/pre>\n<p>\u5982\u679c\u6211\u4eec\u6ca1\u6709\u5bf9<code>word_document<\/code>\u7d22\u5f15\u8fdb\u884c\u663e\u793a\u8bbe\u7f6e\u6570\u636e\u7c7b\u578b\uff0c\u5728\u4e0a\u9762\u8fd9\u4e2a\u8bed\u53e5\u6267\u884c\u4e4b\u540e\uff0cElasticsearch\u4f1a\u9ed8\u8ba4\u63a8\u65ad\u6570\u636e\u7c7b\u578b\uff0c\u5728Elasticsearch\u4e2d\u5185\u5bb9\u4f1a\u8f6c\u6362\u4e3a\u53ef\u80fd\u5982\u4e0b\u7684\u5f62\u5f0f\uff0c\u6241\u5e73\u5316\u7684\u5904\u7406\u6570\u636e<\/p>\n<pre><code class=\"json\">{\n  &quot;title&quot;:&quot;up&quot;,\n  &quot;user.name&quot;:[&quot;honghong&quot;,&quot;mingming&quot;,&quot;lanlan&quot;],\n  &quot;user.sex&quot;:[&quot;male&quot;,&quot;male&quot;,&quot;female&quot;],\n  &quot;user.numberOfLikes&quot;:[500,50,100]\n}<\/code><\/pre>\n<p>\u76f8\u4fe1\u5927\u5bb6\u4e5f\u770b\u51fa\u6765\u4e86\uff0c\u5982\u679c\u88ab<code>Elasticsearch<\/code>\u8f6c\u6362\u6210\u4e0a\u9762\u7684\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u4e4b\u540e\uff0c\u6211\u4eec\u7684\u641c\u7d22\u7ed3\u679c\u662f\u4f1a\u88ab\u5f71\u54cd\u7684\uff0c\u5047\u5982\u6211\u4eec\u4f7f\u7528\u5982\u4e0b\u8fd9\u4e2a\u8bed\u53e5\u8fdb\u884c\u67e5\u8be2\uff0c\u6211\u4eec\u60f3\u641c\u7d22<code>name<\/code>\u662f<code>honghong<\/code>\uff0c<code>sex<\/code>\u662f<code>male<\/code>\uff0c\u9884\u671f\u7ed3\u679c\u662f\u6ca1\u6709\u5339\u914d\u7684\u6587\u6863\uff0c\u4f46\u662f\u56e0\u4e3a<code>Elasticsearch<\/code>\u5bf9\u4e0a\u8ff0\u7684\u7ed3\u679c\u8fdb\u884c\u4e86\u6241\u5e73\u5316\u7684\u5904\u7406\uff0c\u9020\u6210\u4e86\u9519\u8bef\u7684\u5339\u914d<\/p>\n<pre><code class=\"text\">GET word_document\/_search\n{\n  &quot;query&quot;: {\n    &quot;bool&quot;: {\n      &quot;must&quot;: [\n        { &quot;match&quot;: { &quot;user.name&quot;: &quot;honghong&quot; }},\n        { &quot;match&quot;: { &quot;user.sex&quot;:  &quot;male&quot; }}\n      ]\n    }\n  }\n}<\/code><\/pre>\n<p>\u5982\u4f55\u907f\u514d\u4e0a\u8ff0\u60c5\u51b5\u7684\u53d1\u751f\u5462\uff0c\u90a3\u5c31\u662f\u4f7f\u7528<code>Elasticsearch<\/code>\u63d0\u4f9b\u7684<code>Nested<\/code>\u6570\u636e\u7c7b\u578b\uff0c<code>Nested<\/code> \u6570\u636e\u7c7b\u578b\u4fdd\u8bc1\u4e86\u5d4c\u5957\u5bf9\u8c61\u7684\u72ec\u7acb\u6027\uff0c\u4e5f\u5c31\u662f\u8ba9\u6211\u4eec\u53ef\u4ee5\u5bf9\u5d4c\u5957\u5bf9\u8c61\u7684\u5185\u5bb9\u8fdb\u884c\u68c0\u7d22\uff0c\u4ece\u800c\u4e0d\u4f1a\u53d1\u751f\u4e0a\u8ff0\u7684\u8fd9\u79cd\u60c5\u51b5<\/p>\n<ul>\n<li>\n<p>\u9996\u5148\u6211\u4eec\u8fd8\u662f\u4ee5\u4e0a\u9762\u6587\u6863\u4e3a\u4f8b\uff0c\u4e0d\u8fc7\u662f\u8fd9\u6b21\u6211\u4eec\u4f18\u5148\u521b\u5efa\u7d22\u5f15\uff0c\u5e76\u6307\u5b9a<code>user<\/code>\u5b57\u6bb5\u4e3a<code>nested<\/code><\/p>\n<pre><code class=\"text\">PUT word_document\n{\n  &quot;mappings&quot;: {\n    &quot;properties&quot;: {\n      &quot;title&quot;:{\n        &quot;type&quot;: &quot;keyword&quot;\n        },\n      &quot;user&quot;: {\n        &quot;type&quot;: &quot;nested&quot; \n      },\n      &quot;numberOfLikes&quot;:{\n        &quot;type&quot;: &quot;integer&quot;\n      }\n    }\n  }\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u4e0b\u9762\u52a0\u5165\u6211\u4eec\u7684\u6d4b\u8bd5\u6570\u636e\uff0c\u6765\u9a8c\u8bc1\u6211\u4eec\u7684\u641c\u7d22\u8bed\u53e5<\/p>\n<pre><code class=\"text\">PUT word_document\/_doc\/1\n{\n  &quot;title&quot; : &quot;up&quot;,\n  &quot;user&quot; : [ \n    {\n      &quot;name&quot; : &quot;honghong&quot;,\n      &quot;sex&quot; :  &quot;female&quot;,\n      &quot;numberOfLikes&quot;:500\n    },\n    {\n      &quot;name&quot; : &quot;mingming&quot;,\n      &quot;sex&quot; :  &quot;male&quot;,\n      &quot;numberOfLikes&quot;:50\n    },\n    {\n      &quot;name&quot; : &quot;lanlan&quot;,\n      &quot;sex&quot; :  &quot;male&quot;,\n      &quot;numberOfLikes&quot;:100\n    }\n  ]\n}\nPUT word_document\/_doc\/2\n{\n  &quot;title&quot; : &quot;up&quot;,\n  &quot;user&quot; : [ \n      {\n      &quot;name&quot; : &quot;honghong&quot;,\n      &quot;sex&quot; :  &quot;female&quot;,\n      &quot;numberOfLikes&quot;:20\n    },\n    {\n      &quot;name&quot; : &quot;mingming&quot;,\n      &quot;sex&quot; :  &quot;male&quot;,\n      &quot;numberOfLikes&quot;:30\n    },\n    {\n      &quot;name&quot; : &quot;lanlan&quot;,\n      &quot;sex&quot; :  &quot;male&quot;,\n      &quot;numberOfLikes&quot;:50\n    }\n  ]\n}\nPUT word_document\/_doc\/3\n{\n  &quot;title&quot; : &quot;up&quot;,\n  &quot;user&quot; : [ \n    {\n      &quot;name&quot; : &quot;honghong&quot;,\n      &quot;sex&quot; :  &quot;female&quot;,\n      &quot;numberOfLikes&quot;:50\n    },\n    {\n      &quot;name&quot; : &quot;mingming&quot;,\n      &quot;sex&quot; :  &quot;male&quot;,\n      &quot;numberOfLikes&quot;:50\n    },\n    {\n      &quot;name&quot; : &quot;lanlan&quot;,\n      &quot;sex&quot; :  &quot;male&quot;,\n      &quot;numberOfLikes&quot;:50\n    }\n  ]\n}<\/code><\/pre>\n<\/li>\n<li>\n<p>\u4e0b\u9762\u8fd8\u662f\u521a\u624d\u90a3\u4e2a\u641c\u7d22\u8bed\u53e5\uff0c\u6b64\u65f6\u5c31\u4e0d\u4f1a\u6709\u5339\u914d\u7684\u6587\u6863\u8fd4\u56de\uff0c\u8fd4\u56de\u7ed3\u679c\u4e3a\u7a7a<\/p>\n<pre><code class=\"text\">GET word_document\/_search\n{\n  &quot;query&quot;: {\n    &quot;nested&quot;: {\n      &quot;path&quot;: &quot;user&quot;,\n      &quot;query&quot;: {\n        &quot;bool&quot;: {\n          &quot;must&quot;: [\n            { &quot;match&quot;: { &quot;user.name&quot;: &quot;honghong&quot; }},\n            { &quot;match&quot;: { &quot;user.sex&quot;:  &quot;male&quot; }} \n          ]\n        }\n      }\n    }\n  }\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u90a3\u4e48\u5bf9\u4e8e\u5d4c\u5957\u6587\u6863\u6211\u4eec\u53ef\u4ee5\u600e\u4e48\u67e5\u8be2\u5462\uff0c\u90a3\u5c31\u662f\u6307\u5b9a<code>nested<\/code>\u67e5\u8be2\u7c7b\u578b\uff0c\u4f7f\u7528\u666e\u901a\u7684\u67e5\u8be2\u662f\u67e5\u8be2\u4e0d\u5230\u7684\u54e6\uff0c<code>nested<\/code>\u67e5\u8be2\u8bed\u53e5\u5982\u4e0b\u6240\u793a\uff0c\u6b64\u65f6\u8fd4\u56de\u7684\u5c31\u662f\u6211\u4eec<\/p>\n<pre><code class=\"text\">GET word_document\/_search\n{\n  &quot;query&quot;: {\n    &quot;nested&quot;: {\n      &quot;path&quot;: &quot;user&quot;,\n      &quot;query&quot;: {\n        &quot;bool&quot;: {\n          &quot;must&quot;: [\n            { &quot;match&quot;: { &quot;user.name&quot;: &quot;honghong&quot; }},\n            { &quot;match&quot;: { &quot;user.sex&quot;:  &quot;female&quot; }} \n          ]\n        }\n      },\n      &quot;inner_hits&quot;: { \n        &quot;highlight&quot;: {\n          &quot;fields&quot;: {\n            &quot;user.name&quot;: {}\n          }\n        }\n      }\n    }\n  }\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u6b64\u5916\u6211\u4eec\u8fd8\u53ef\u4ee5\u6839\u636e\u5d4c\u5957\u5bf9\u8c61\u4e2d\u7684\u5b57\u6bb5\u8fdb\u884c\u6392\u5e8f\uff0c\u5347\u5e8f\u65f6\u83b7\u53d6\u5d4c\u5957\u5bf9\u8c61\u4e2d\u6700\u5c0f\u7684\u503c\u6700\u4e3a\u6bd4\u8f83\u503c\uff0c\u964d\u5e8f\u65f6\u83b7\u53d6\u5d4c\u5957\u5bf9\u8c61\u6700\u5927\u7684\u503c\u4f5c\u4e3a\u6bd4\u8f83\u503c<\/p>\n<pre><code class=\"text\">GET word_document\/_search\n{\n  &quot;query&quot;: {\n    &quot;nested&quot;: {\n      &quot;path&quot;: &quot;user&quot;,\n      &quot;query&quot;: {\n        &quot;match&quot;: {\n          &quot;user.sex&quot;: &quot;male&quot;\n        }\n      }\n    }\n  },\n  &quot;sort&quot;:[\n    {\n      &quot;user.numberOfLikes&quot;: {\n        &quot;order&quot;: &quot;asc&quot;, \n        &quot;nested&quot;: {\n          &quot;path&quot;:&quot;user&quot;\n        }\n      }\n    }\n    ]\n}<\/code><\/pre>\n<p>\u8fd4\u56de\u5982\u4e0b<\/p>\n<pre><code class=\"text\">{\n  &quot;took&quot; : 101,\n  &quot;timed_out&quot; : false,\n  &quot;_shards&quot; : {\n    &quot;total&quot; : 1,\n    &quot;successful&quot; : 1,\n    &quot;skipped&quot; : 0,\n    &quot;failed&quot; : 0\n  },\n  &quot;hits&quot; : {\n    &quot;total&quot; : {\n      &quot;value&quot; : 3,\n      &quot;relation&quot; : &quot;eq&quot;\n    },\n    &quot;max_score&quot; : null,\n    &quot;hits&quot; : [\n      {\n        &quot;_index&quot; : &quot;word_document&quot;,\n        &quot;_id&quot; : &quot;2&quot;,\n        &quot;_score&quot; : null,\n        &quot;_source&quot; : {\n          &quot;title&quot; : &quot;up&quot;,\n          &quot;user&quot; : [\n            {\n              &quot;name&quot; : &quot;honghong&quot;,\n              &quot;sex&quot; : &quot;female&quot;,\n              &quot;numberOfLikes&quot; : 20\n            },\n            {\n              &quot;name&quot; : &quot;mingming&quot;,\n              &quot;sex&quot; : &quot;male&quot;,\n              &quot;numberOfLikes&quot; : 30\n            },\n            {\n              &quot;name&quot; : &quot;lanlan&quot;,\n              &quot;sex&quot; : &quot;male&quot;,\n              &quot;numberOfLikes&quot; : 50\n            }\n          ]\n        },\n        &quot;sort&quot; : [\n          20\n        ]\n      },\n      {\n        &quot;_index&quot; : &quot;word_document&quot;,\n        &quot;_id&quot; : &quot;1&quot;,\n        &quot;_score&quot; : null,\n        &quot;_source&quot; : {\n          &quot;title&quot; : &quot;up&quot;,\n          &quot;user&quot; : [\n            {\n              &quot;name&quot; : &quot;honghong&quot;,\n              &quot;sex&quot; : &quot;female&quot;,\n              &quot;numberOfLikes&quot; : 500\n            },\n            {\n              &quot;name&quot; : &quot;mingming&quot;,\n              &quot;sex&quot; : &quot;male&quot;,\n              &quot;numberOfLikes&quot; : 50\n            },\n            {\n              &quot;name&quot; : &quot;lanlan&quot;,\n              &quot;sex&quot; : &quot;male&quot;,\n              &quot;numberOfLikes&quot; : 100\n            }\n          ]\n        },\n        &quot;sort&quot; : [\n          50\n        ]\n      },\n      {\n        &quot;_index&quot; : &quot;word_document&quot;,\n        &quot;_id&quot; : &quot;3&quot;,\n        &quot;_score&quot; : null,\n        &quot;_source&quot; : {\n          &quot;title&quot; : &quot;up&quot;,\n          &quot;user&quot; : [\n            {\n              &quot;name&quot; : &quot;honghong&quot;,\n              &quot;sex&quot; : &quot;female&quot;,\n              &quot;numberOfLikes&quot; : 50\n            },\n            {\n              &quot;name&quot; : &quot;mingming&quot;,\n              &quot;sex&quot; : &quot;male&quot;,\n              &quot;numberOfLikes&quot; : 50\n            },\n            {\n              &quot;name&quot; : &quot;lanlan&quot;,\n              &quot;sex&quot; : &quot;male&quot;,\n              &quot;numberOfLikes&quot; : 50\n            }\n          ]\n        },\n        &quot;sort&quot; : [\n          50\n        ]\n      }\n    ]\n  }\n}\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u5bf9\u5d4c\u5957\u5bf9\u8c61\u8fdb\u884c\u805a\u5408\u64cd\u4f5c\uff0c\u5982\u4e0b\u6211\u4eec\u83b7\u53d6\u7d22\u5f15\u4e2d<code>user.name=honghong<\/code>,<code>user.sex=female<\/code>\u7684\u6240\u6709\u6587\u6863\uff0c\u805a\u5408\u7edf\u8ba1<code>numberOfLikes<\/code>\u7684\u6700\u5c0f\u503c<\/p>\n<pre><code class=\"text\">GET word_document\/_search\n{\n  &quot;query&quot;: {\n    &quot;nested&quot;: {\n      &quot;path&quot;: &quot;user&quot;,\n      &quot;query&quot;: {\n        &quot;bool&quot;: {\n          &quot;must&quot;: [\n            {\n              &quot;match&quot;: {\n                &quot;user.name&quot;: &quot;honghong&quot;\n              }\n            },\n            {\n              &quot;match&quot;: {\n                &quot;user.sex&quot;: &quot;female&quot;\n              }\n            }\n          ]\n        }\n      }\n    }\n  },\n  &quot;aggs&quot;: {\n    &quot;my_min_value&quot;: {\n      &quot;nested&quot;: {\n        &quot;path&quot;: &quot;user&quot;\n      }, \n      &quot;aggs&quot;: {\n        &quot;min_value&quot;: {\n          &quot;min&quot;: {\n            &quot;field&quot;: &quot;user.numberOfLikes&quot;\n          }\n        }\n      }\n    }\n  }\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u4e0a\u9762\u7684\u805a\u5408\u7edf\u8ba1\u53ea\u662f\u5bf9\u5916\u90e8\u7684\u6587\u6863\u8fc7\u6ee4\uff0c\u90a3\u5982\u679c\u6211\u4eec\u6709\u8fd9\u4e48\u4e00\u4e2a\u9700\u6c42\uff0c\u805a\u5408\u7edf\u8ba1\u5d4c\u5957\u5bf9\u8c61<code>user<\/code>\u5185\u5bb9<code>sex=male<\/code>\u7684\u6700\u5c0f\u503c\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b<strong>filter<\/strong>\uff0c\u4e0b\u9762\u8fd9\u4e2a\u8bed\u53e5\u4f18\u5148\u8fc7\u6ee4<code>title=up<\/code>\u7684\u6587\u6863\uff0c\u805a\u5408\u7edf\u8ba1<code>user.sex=male<\/code>\u7684<code>numberOfLikes<\/code>\u6700\u5c0f\u503c<\/p>\n<pre><code class=\"text\">GET \/word_document\/_search?size=0\n{\n  &quot;query&quot;: {\n    &quot;match&quot;: {\n      &quot;title&quot;: &quot;up&quot;\n    }\n  },\n  &quot;aggs&quot;: {\n    &quot;my_user&quot;: {\n      &quot;nested&quot;: {\n        &quot;path&quot;: &quot;user&quot;\n      },\n      &quot;aggs&quot;: {\n        &quot;filter_my_user&quot;: {\n          &quot;filter&quot;: {\n            &quot;bool&quot;: {\n              &quot;filter&quot;: [\n                {\n                  &quot;match&quot;: {\n                    &quot;user.sex&quot;: &quot;male&quot;\n                  }\n                }\n              ]\n            }\n          },\n          &quot;aggs&quot;: {\n            &quot;min_price&quot;: {\n              &quot;min&quot;: {\n                &quot;field&quot;: &quot;user.numberOfLikes&quot;\n              }\n            }\n          }\n        },\n        &quot;no_filter_my_user&quot;:{\n          &quot;min&quot;: {\n            &quot;field&quot;: &quot;user.numberOfLikes&quot;\n          }\n        }\n      }\n    }\n  }\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u6700\u540e\u8fd8\u6709\u4e00\u79cd\u5c31\u662f\u53cd\u5411\u5d4c\u5957\u805a\u5408\uff0c\u901a\u8fc7\u5d4c\u5957\u5bf9\u8c61\u805a\u5408\u7236\u6587\u6863\uff0c\u8fd4\u56de\u7236\u6587\u6863\u4fe1\u606f<\/p>\n<p>\u9996\u5148\u6211\u4eec\u8fd8\u662f\u5148\u521b\u5efa\u4e00\u4e2a\u7d22\u5f15\u6dfb\u52a0\u51e0\u6761\u6570\u636e\u7528\u6765\u6d4b\u8bd5<\/p>\n<pre><code class=\"text\">PUT \/issues\n{\n  &quot;mappings&quot;: {\n    &quot;properties&quot;: {\n      &quot;tags&quot;: { &quot;type&quot;: &quot;keyword&quot; },\n      &quot;comments&quot;: {                            \n        &quot;type&quot;: &quot;nested&quot;,\n        &quot;properties&quot;: {\n          &quot;username&quot;: { &quot;type&quot;: &quot;keyword&quot; },\n          &quot;comment&quot;: { &quot;type&quot;: &quot;text&quot; }\n        }\n      }\n    }\n  }\n}\nPUT \/issues\/_doc\/1\n{\n  &quot;tags&quot;:&quot;\u8df3\u821e&quot;,\n  &quot;comments&quot;:[{\n    &quot;username&quot;:&quot;\u5c0f\u674e&quot;,\n    &quot;comment&quot;:&quot;\u5c0f\u674e\u60f3\u5b66\u8df3\u821e&quot;\n  },\n  {\n    &quot;username&quot;:&quot;\u5c0f\u7ea2&quot;,\n    &quot;comment&quot;:&quot;\u5c0f\u7ea2\u8df3\u821e\u5f88\u6709\u5929\u8d4b&quot;\n  }\n  ]\n}\nPUT \/issues\/_doc\/2\n{\n  &quot;tags&quot;:&quot;\u5531\u6b4c&quot;,\n  &quot;comments&quot;:[{\n    &quot;username&quot;:&quot;\u5c0f\u674e&quot;,\n    &quot;comment&quot;:&quot;\u5c0f\u674e\u4f1a\u5531\u6b4c&quot;\n  },\n  {\n    &quot;username&quot;:&quot;\u5c0f\u674e&quot;,\n    &quot;comment&quot;:&quot;\u5c0f\u674e\u5531\u6b4c\u6709\u5929\u8d4b&quot;\n  },\n  {\n    &quot;username&quot;:&quot;\u5c0f\u7ea2&quot;,\n    &quot;comment&quot;:&quot;\u5c0f\u7ea2\u662f\u6b4c\u624b&quot;\n  }\n  ]\n}\nPUT \/issues\/_doc\/3\n{\n  &quot;tags&quot;:&quot;\u8df3\u821e&quot;,\n  &quot;comments&quot;:[\n  {\n    &quot;username&quot;:&quot;\u5c0f\u7ea2&quot;,\n    &quot;comment&quot;:&quot;\u5c0f\u7ea2\u4f1a\u8df3\u821e&quot;\n  },\n  {\n    &quot;username&quot;:&quot;\u5c0f\u7ea2&quot;,\n    &quot;comment&quot;:&quot;\u5c0f\u7ea2\u662f\u821e\u795e&quot;\n  }\n  ]\n}\nPUT \/issues\/_doc\/4\n{\n  &quot;tags&quot;:&quot;\u5531\u6b4c&quot;,\n  &quot;comments&quot;:[\n  {\n    &quot;username&quot;:&quot;\u5c0f\u674e&quot;,\n    &quot;comment&quot;:&quot;\u5c0f\u674e\u7b80\u76f4\u5c31\u662f\u5929\u751f\u6b4c\u624b&quot;\n  }\n  ]\n}\nPUT \/issues\/_doc\/5\n{\n  &quot;tags&quot;:&quot;\u8df3\u821e&quot;,\n  &quot;comments&quot;:[\n  {\n    &quot;username&quot;:&quot;\u5c0f\u7ea2&quot;,\n    &quot;comment&quot;:&quot;\u5c0f\u7ea2\u821e\u59ff\u5f88\u7f8e&quot;\n  }\n  ]\n}<\/code><\/pre>\n<blockquote><p>issues  \u95ee\u9898\uff1btags \u6807\u7b7e\uff1busername \u540d\u5b57\uff1bcomment \u8bc4\u8bba\uff1b<\/p><\/blockquote>\n<p>\u4e0b\u9762\u6211\u4eec\u4f7f\u7528\u53cd\u5411\u5d4c\u5957\u805a\u5408\u7236\u6587\u6863\uff0c\u9700\u6c42\u5982\u4e0b\uff1a<\/p>\n<p>1\u3001\u5148\u805a\u5408\u7edf\u8ba1\u51fa\u8bc4\u8bba\u6700\u591a\u7684<code>username<\/code><\/p>\n<p>2\u3001\u5728\u805a\u5408\u7edf\u8ba1<code>username<\/code>\u4e2d<code>comment<\/code>\u6700\u591a\u7684<code>tag<\/code><\/p>\n<pre><code class=\"text\">GET \/issues\/_search?size=0\n{\n  &quot;query&quot;: {\n    &quot;match_all&quot;: {}\n  },\n  &quot;aggs&quot;: {\n    &quot;comments&quot;: {\n      &quot;nested&quot;: {\n        &quot;path&quot;: &quot;comments&quot;\n      },\n      &quot;aggs&quot;: {\n        &quot;top_usernames&quot;: {\n          &quot;terms&quot;: {\n            &quot;field&quot;: &quot;comments.username&quot;\n          },\n          &quot;aggs&quot;: {\n            &quot;comment_to_issue&quot;: {\n              &quot;reverse_nested&quot;: {}, \n              &quot;aggs&quot;: {\n                &quot;top_tags_per_comment&quot;: {\n                  &quot;terms&quot;: {\n                    &quot;field&quot;: &quot;tags&quot;\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}<\/code><\/pre>\n<p>\u7ed3\u679c\u5982\u4e0b\uff0c\u5f97\u51fa\u7ed3\u8bba\uff1a<code>\u5c0f\u7ea2<\/code>\u8bc4\u8bba\u6b21\u6570\u6700\u591a\uff0c\u8bc4\u8bba\u4e86<code>5\u6b21<\/code>\uff0c\u5c0f\u7ea2\u8bc4\u8bba\u6700\u591a\u7684\u6807\u7b7e\u662f<code>\u8df3\u821e<\/code>\uff0c\u6709<code>3\u6b21<\/code><\/p>\n<pre><code class=\"text\">{\n  &quot;aggregations&quot; : {\n    &quot;comments&quot; : {\n      &quot;doc_count&quot; : 9,\n      &quot;top_usernames&quot; : {\n        &quot;doc_count_error_upper_bound&quot; : 0,\n        &quot;sum_other_doc_count&quot; : 0,\n        &quot;buckets&quot; : [\n          {\n            &quot;key&quot; : &quot;\u5c0f\u7ea2&quot;,\n            &quot;doc_count&quot; : 5,\n            &quot;comment_to_issue&quot; : {\n              &quot;doc_count&quot; : 4,\n              &quot;top_tags_per_comment&quot; : {\n                &quot;doc_count_error_upper_bound&quot; : 0,\n                &quot;sum_other_doc_count&quot; : 0,\n                &quot;buckets&quot; : [\n                  {\n                    &quot;key&quot; : &quot;\u8df3\u821e&quot;,\n                    &quot;doc_count&quot; : 3\n                  },\n                  {\n                    &quot;key&quot; : &quot;\u5531\u6b4c&quot;,\n                    &quot;doc_count&quot; : 1\n                  }\n                ]\n              }\n            }\n          },\n          {\n            &quot;key&quot; : &quot;\u5c0f\u674e&quot;,\n            &quot;doc_count&quot; : 4,\n            &quot;comment_to_issue&quot; : {\n              &quot;doc_count&quot; : 3,\n              &quot;top_tags_per_comment&quot; : {\n                &quot;doc_count_error_upper_bound&quot; : 0,\n                &quot;sum_other_doc_count&quot; : 0,\n                &quot;buckets&quot; : [\n                  {\n                    &quot;key&quot; : &quot;\u5531\u6b4c&quot;,\n                    &quot;doc_count&quot; : 2\n                  },\n                  {\n                    &quot;key&quot; : &quot;\u8df3\u821e&quot;,\n                    &quot;doc_count&quot; : 1\n                  }\n                ]\n              }\n            }\n          }\n        ]\n      }\n    }\n  }\n}\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>Nested \u652f\u6301\u7684\u53c2\u6570\u6709\u54ea\u4e9b<\/h2>\n<p><code>Nested<\/code>\u4e5f\u53ea\u662f\u7279\u6b8a\u7684<code>Object<\/code>\u7684\u4e00\u79cd\uff0c\u4e5f\u662f\u6709\u652f\u6301\u7684\u51e0\u79cd\u53c2\u6570<\/p>\n<ul>\n<li><code>dynamic<\/code>: (\u53ef\u9009\u53c2\u6570) \u662f\u5426\u5141\u8bb8\u5728\u7d22\u5f15<code>mapping<\/code>\u6587\u4ef6\u672a\u5b9a\u4e49\u5b57\u6bb5\u7684\u60c5\u51b5\u4e0b\u5bf9\u65b0\u5b57\u6bb5\u7684\u5904\u7406\uff0c\u9ed8\u8ba4\u662f\u52a0\u5165\u5230\u73b0\u6709\u7684\u5d4c\u5957\u5bf9\u8c61\u4e2d(<code>true<\/code>),\u8fd8\u652f\u6301<code>false<\/code>\uff0c<code>strict<\/code><\/li>\n<li><code>properties<\/code>: (\u53ef\u9009\u53c2\u6570) \u5d4c\u5957\u5bf9\u8c61\u5b57\u6bb5\u5185\u5bb9\u5c5e\u6027\u8bbe\u7f6e<\/li>\n<li><code>include_in_parent<\/code>:(\u53ef\u9009\u53c2\u6570) \u9ed8\u8ba4<code>false<\/code>\uff0c\u5982\u679c\u4e3a<code>true<\/code>\uff0c\u5d4c\u5957\u5bf9\u8c61\u7684\u5b57\u6bb5\u4e5f\u4f1a\u4f5c\u4e3a\u666e\u901a\u5b57\u6bb5\u7684\u5f62\u5f0f(<code>flat<\/code>)\u6dfb\u52a0\u5230\u7236\u6587\u6863<\/li>\n<li><code>include_in_root<\/code>:(\u53ef\u9009\u53c2\u6570) \u9ed8\u8ba4<code>false<\/code>\uff0c\u5982\u679c\u4e3a<code>true<\/code>\uff0c\u5d4c\u5957\u5bf9\u8c61\u7684\u5b57\u6bb5\u4e5f\u4f1a\u4f5c\u4e3a\u666e\u901a\u5b57\u6bb5\u7684\u5f62\u5f0f(<code>flat<\/code>)\u6dfb\u52a0\u5230\u6839\u6587\u6863<\/li>\n<\/ul>\n<h2>Nested \u7c7b\u578b\u7684\u7ea6\u675f<\/h2>\n<p>\u901a\u8fc7\u524d\u9762\u7684\u5b66\u4e60\uff0c\u6211\u4eec\u4e5f\u77e5\u9053\u4e86nested\u7c7b\u578b\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u5355\u72ec\u7684<code>Lucene<\/code>\u6587\u6863\u8fdb\u884c\u6240\u6709\uff0c\u5f53\u6211\u4eec\u6709<code>100<\/code>\u4e2a\u5d4c\u5957\u5bf9\u8c61\u7684\u65f6\u5019\u6211\u4eec\u9700\u8981<code>101<\/code>\u4e2a\u6587\u6863\u6765\u5b58\u50a8\u6620\u5c04\u5173\u7cfb\uff0c\u4e00\u4e2a\u7528\u4e8e\u7236\u6587\u6863\uff0c\u4e00\u4e2a\u7528\u4e8e\u5d4c\u5957\u6587\u6863\uff0c\u6240\u4ee5\u8fd9\u4e00\u90e8\u5206\u7684\u5f00\u9500\uff0c<code>ELasticsearch<\/code>\u6765\u901a\u8fc7\u4e00\u4e0b\u8bbe\u7f6e\u8fdb\u884c\u4e86\u7ea6\u675f<\/p>\n<ul>\n<li>\n<p><code>index.mapping.nested_fields.limit<\/code><\/p>\n<p>\u4e00\u4e2a\u7d22\u5f15\u4e2d\uff0c\u5d4c\u5957\u7c7b\u578b\u5b57\u6bb5(nested)\u6700\u591a\u5b58\u5728\u591a\u4e2a\u9650\u5236\uff0c\u9ed8\u8ba4<code>50\u4e2a<\/code>\uff0c\u5982\u6211\u4eec\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u4e5f\u5c31\u662f\u53ea\u5360\u7528\u4e86\u4e00\u4e2a<\/p>\n<\/li>\n<li>\n<p><code>index.mapping.nested_objects.limit<\/code><\/p>\n<p>\u4e00\u4e2a\u7d22\u5f15\u4e2d\uff0c\u5355\u4e2a\u5d4c\u5957\u7c7b\u578b\u5b57\u6bb5\u5305\u542b\u7684\u5d4c\u5957<code>JSON<\/code>\u5bf9\u8c61\u7684\u6700\u5927\u6570\u91cf\uff0c\u9ed8\u8ba4<code>10000<\/code><\/p>\n<\/li>\n<\/ul>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u5b66\u4e60\u5b9e\u8df5\uff0c\u6211\u4eec\u53ef\u4ee5\u77e5\u9053<code>Nested<\/code>\u5d4c\u5957\u7c7b\u578b\u662f<code>Elasticsearch<\/code>\u63a8\u8350\u7684\u76f8\u5bf9\u4e8e<code>Join<\/code>\u7c7b\u578b\uff0c\u5e76\u4e14<code>Nested<\/code>\u53ef\u4ee5\u5b9e\u73b0\u67e5\u8be2\uff0c\u805a\u5408\uff0c\u6392\u5e8f\u7b49\uff0c\u57fa\u672c\u6ee1\u8db3\u4e86\u5de5\u4f5c\u7684\u9700\u8981\u3002\u597d\u4e86\uff0c\u5230\u8fd9\u5c31\u7ed3\u675f\u5427\uff0c\u6709\u4ec0\u4e48\u9700\u8981\u6df1\u5165\u4e86\u89e3\u7684\uff0c\u7559\u8a00\u54e6\uff0c\u4e5f\u53ef\u4ee5\u53bb\u5b98\u7f51\u67e5\u770b\uff0c\u6bd5\u7adf\u5b98\u7f51\u8fd8\u662f\u4e00\u624b\u8d44\u6599\uff0c\u535a\u4e3b\u7684\u4e5f\u53ea\u80fd\u7b97\u662f\u5165\u95e8\u542f\u8499\u7b14\u8bb0\uff0c\u5b9e\u8df5\u8d77\u6765\u5427\uff0c\u52a0\u6cb9\uff01<\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=e%2F%2F5kOiuKFiNzWQPC3bUVA%3D%3D.TmAOlSYTaZRb%2B7tqWJ9S1QJcXa0pmGjIXG4Vn9ausK%2B4wkcAUFxhodZ%2B1pJDwNcvFQCMl9q2Nimi6oz6MxGj5w%3D%3D\" rel=\"nofollow\">Join \u5b57\u6bb5\u7684\u8be6\u89e3\u53ef\u4ee5\u53c2\u8003\u535a\u4e3b\u7684\u8fd9\u4e00\u7bc7\u6587\u7ae0\u54e6<\/a><\/p>\n<p>\u672c\u6587\u7531<a href=\"https:\/\/link.segmentfault.com\/?enc=lp%2FW02weCMnajdBIu9gHGQ%3D%3D.X57eI4A04Fwjc2AH2lGjKUfR7ww%2B7m%2FGXmRxfPX8N1o%3D\" rel=\"nofollow\">mdnice<\/a>\u591a\u5e73\u53f0\u53d1\u5e03<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042543995\">https:\/\/segmentfault.com\/a\/1190000042543995<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u4e00\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5b66\u4e60\u4e86Join\u7c7b\u578b\u7684\u7236\u5b50\u6587\u6863\uff0c\u4eca\u5929\u7ee7\u7eed\u5b66\u4e60\u4e00\u4e0b\u5d4c\u5957\u6587\u6863\uff0c\u6bd5\u7adf\u5d4c\u5957\u6587\u6863\u4e5f\u662fElasticsea [&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-10006601","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\/10006601","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=10006601"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006601\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}