{"id":1106,"date":"2023-03-12T11:43:27","date_gmt":"2023-03-12T03:43:27","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1106"},"modified":"2023-04-29T11:24:25","modified_gmt":"2023-04-29T03:24:25","slug":"elasticsearch-7-search-aggregation-query-bucket-aggregation","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/elasticsearch-7-search-aggregation-query-bucket-aggregation\/","title":{"rendered":"ElasticSearch 7 \u641c\u7d22\uff0811\uff09\u805a\u5408\u67e5\u8be2\u6876\u805a\u5408"},"content":{"rendered":"<h3>terms aggregation \u6876\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<ul>\n<li>\u8bf7\u6c42<\/li>\n<\/ul>\n<pre><code class=\"language-java\">localhost:9200\/nba\/_search<\/code><\/pre>\n<p><!-- more --><\/p>\n<ul>\n<li>\u8bf7\u6c42\u4f53<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  \/\/ \u8bed\u4e49: \u706b\u7bad\u961f\u6839\u636e\u5e74\u9f84\u8fdb\u884c\u5206\u7ec4\n  &quot;query&quot;: {\n    &quot;term&quot;: {\n      &quot;teamNameEn&quot;: &quot;Rockets&quot;\n    }\n  },\n  &quot;aggs&quot;: {\n    &quot;aggrAge&quot;: {\n      &quot;terms&quot;: { \/\/ \u56e0\u4e3a\u6839\u636e\u5e74\u9f84\u505a\u6876\u805a\u5408\u6240\u4ee5\u4f7f\u7528terms\n        &quot;field&quot;: &quot;age&quot;,\n        &quot;size&quot;: 3 \/\/ \u6307\u5b9a\u663e\u793a\u6876\u6570\n      }\n    }\n  },\n  &quot;size&quot;: 0\n}<\/code><\/pre>\n<ul>\n<li>\u54cd\u5e94<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;took&quot; : 1,\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; : 21,\n      &quot;relation&quot; : &quot;eq&quot;\n    },\n    &quot;max_score&quot; : null,\n    &quot;hits&quot; : [ ]\n  },\n  &quot;aggregations&quot; : {\n    &quot;aggrAge&quot; : {\n      &quot;doc_count_error_upper_bound&quot; : 0,\n      &quot;sum_other_doc_count&quot; : 3,\n      &quot;buckets&quot; : [\n        {\n          &quot;key&quot; : 21, \/\/ \u6307\u5b9a\u7684\u5b57\u6bb5 age\n          &quot;doc_count&quot; : 4 \/\/ 21\u5c81\u7684\u6587\u6863\u6570\u67094\u4e2a\n        },\n        {\n          &quot;key&quot; : 25,\n          &quot;doc_count&quot; : 3\n        },\n        {\n          &quot;key&quot; : 23,\n          &quot;doc_count&quot; : 2\n        }\n      ]\n    }\n  }\n}<\/code><\/pre>\n<h3>order \u7b2c\u4e00\u79cd\u5206\u7ec4\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<ul>\n<li>\u8bf7\u6c42<\/li>\n<\/ul>\n<pre><code class=\"language-java\">localhost:9200\/nba\/_search<\/code><\/pre>\n<ul>\n<li>\u8bf7\u6c42\u4f53<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  \/\/ \u8bed\u4e49: \u6839\u636e\u706b\u7bad\u961f\u5e74\u9f84\u8fdb\u884c\u5206\u7ec4\uff0c\u5206\u7ec4\u4fe1\u606f\u901a\u8fc7\u5e74\u9f84\u4ece\u5927\u5230\u5c0f\u6392\u5e8f\uff08\u901a\u8fc7\u6307\u5b9a\u5b57\u6bb5\uff09\n  &quot;query&quot;: {\n    &quot;term&quot;: {\n      &quot;teamNameEn&quot;: &quot;Rockets&quot;\n    }\n  },\n  &quot;aggs&quot;: {\n    &quot;aggrAge&quot;: {\n      &quot;terms&quot;: {\n        &quot;field&quot;: &quot;age&quot;,\n        &quot;size&quot;: 3,\n        &quot;order&quot;: {\n          &quot;key&quot;: &quot;desc&quot; \/\/_key\u5173\u952e\u5b57 \u5012\u5e8f\u6392\u5e8f\n          \/\/&quot;doc_count&quot;: &quot;desc&quot;  \u901a\u8fc7\u6587\u6863\u6392\u5e8f\n        }\n      }\n    }\n  },\n  &quot;size&quot;: 0\n}<\/code><\/pre>\n<ul>\n<li>\u54cd\u5e94<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;took&quot; : 0,\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; : 21,\n      &quot;relation&quot; : &quot;eq&quot;\n    },\n    &quot;max_score&quot; : null,\n    &quot;hits&quot; : [ ]\n  },\n  &quot;aggregations&quot; : {\n    &quot;aggrAge&quot; : {\n      &quot;doc_count_error_upper_bound&quot; : 0,\n      &quot;sum_other_doc_count&quot; : 17,\n      &quot;buckets&quot; : [\n        {\n          &quot;key&quot; : 37,\n          &quot;doc_count&quot; : 1\n        },\n        {\n          &quot;key&quot; : 34,\n          &quot;doc_count&quot; : 2\n        },\n        {\n          &quot;key&quot; : 33,\n          &quot;doc_count&quot; : 1\n        }\n      ]\n    }\n  }\n}<\/code><\/pre>\n<h3>order \u7b2c\u4e8c\u79cd\u5206\u7ec4\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<ul>\n<li>\u8bf7\u6c42<\/li>\n<\/ul>\n<pre><code class=\"language-java\">localhost:9200\/nba\/_search<\/code><\/pre>\n<ul>\n<li>\u8bf7\u6c42\u4f53<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  \/\/ \u8bed\u4e49: \u6bcf\u652f\u7403\u961f\u6309\u8be5\u961f\u6240\u6709\u7403\u5458\u7684\u5e73\u5747\u5e74\u9f84\u8fdb\u884c\u5206\u7ec4\u6392\u5e8f\uff08\u901a\u8fc7\u5206\u7ec4\u6307\u6807\u503c\uff09\n  &quot;aggs&quot;: {\n    &quot;aggsTeamName&quot;: {\n      &quot;terms&quot;: { \/\/ \u56e0\u4e3a\u4f7f\u7528\u5206\u7ec4\u6240\u4ee5\u7528terms\n        &quot;field&quot;: &quot;teamNameEn&quot;,\n        &quot;size&quot;: 3, \/\/ \u663e\u793a3\u6761\n        &quot;order&quot;: {\n          &quot;avgAge&quot;: &quot;desc&quot;\n        }\n      }, \/\/ \u56e0\u4e3a\u9700\u8981\u901a\u8fc7\u5bf9\u7403\u961f\u7684\u5e73\u5747\u5e74\u9f84\u8fdb\u884c\u5206\u7ec4\u6392\u5e8f\uff0c\u6240\u4ee5\u518d\u5199aggs\n      &quot;aggs&quot;: {\n        &quot;avgAge&quot;: {\n          &quot;avg&quot;: {\n            &quot;field&quot;: &quot;age&quot;\n          }\n        }\n      }\n    }\n  },\n  &quot;size&quot;: 0\n}<\/code><\/pre>\n<ul>\n<li>\u54cd\u5e94<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;took&quot; : 3,\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; : 566,\n      &quot;relation&quot; : &quot;eq&quot;\n    },\n    &quot;max_score&quot; : null,\n    &quot;hits&quot; : [ ]\n  },\n  &quot;aggregations&quot; : {\n    &quot;aggsTeamName&quot; : {\n      &quot;doc_count_error_upper_bound&quot; : -1,\n      &quot;sum_other_doc_count&quot; : 511,\n      &quot;buckets&quot; : [\n        {\n          &quot;key&quot; : &quot;Bucks&quot;,\n          &quot;doc_count&quot; : 14,\n          &quot;avgAge&quot; : {\n            &quot;value&quot; : 28.142857142857142\n          }\n        },\n        {\n          &quot;key&quot; : &quot;Mavericks&quot;,\n          &quot;doc_count&quot; : 20,\n          &quot;avgAge&quot; : {\n            &quot;value&quot; : 27.85\n          }\n        },\n        {\n          &quot;key&quot; : &quot;Lakers&quot;,\n          &quot;doc_count&quot; : 21,\n          &quot;avgAge&quot; : {\n            &quot;value&quot; : 27.714285714285715\n          }\n        }\n      ]\n    }\n  }\n}<\/code><\/pre>\n<h3>include \u7b5b\u9009\u5206\u7ec4\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<ul>\n<li>\u8bf7\u6c42<\/li>\n<\/ul>\n<pre><code class=\"language-java\">localhost:9200\/nba\/_search<\/code><\/pre>\n<ul>\n<li>\u8bf7\u6c42\u4f53<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  \/\/ \u8bed\u4e49: \u6e56\u4eba\u548c\u706b\u7bad\u961f\u6309\u7403\u961f\u5e73\u5747\u5e74\u9f84\u8fdb\u884c\u5206\u7ec4\u6392\u5e8f\uff08\u6307\u5b9a\u503c\u5217\u8868\uff09\n  &quot;aggs&quot;: {\n    &quot;aggsTeamName&quot;: {\n      &quot;terms&quot;: {\n        &quot;field&quot;: &quot;teamNameEn&quot;,\n        \/\/ include\u6307\u5b9a\u961f\u4f0d  [&quot;Lakes&quot;,&quot;Rockets&quot;,&quot;warriors&quot;]\n        &quot;include&quot;: [&quot;Lakes&quot;,&quot;Rockets&quot;,&quot;warriors&quot;], \n        \/\/ exclude\u53bb\u9664[&quot;warriors&quot;]\n        &quot;exclude&quot;: [&quot;warriors&quot;], \n        &quot;size&quot;: 3,\n        &quot;order&quot;: {\n          &quot;avgAge&quot;: &quot;desc&quot;\n        }\n      },\n      &quot;aggs&quot;: {\n        &quot;avgAge&quot;: {\n          &quot;avg&quot;: {\n            &quot;field&quot;: &quot;age&quot;\n          }\n        }\n      }\n    }\n  },\n  &quot;size&quot;: 0\n}<\/code><\/pre>\n<ul>\n<li>\u54cd\u5e94<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;took&quot; : 0,\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; : 566,\n      &quot;relation&quot; : &quot;eq&quot;\n    },\n    &quot;max_score&quot; : null,\n    &quot;hits&quot; : [ ]\n  },\n  &quot;aggregations&quot; : {\n    &quot;aggsTeamName&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;Rockets&quot;,\n          &quot;doc_count&quot; : 21,\n          &quot;avgAge&quot; : {\n            &quot;value&quot; : 26.761904761904763\n          }\n        }\n      ]\n    }\n  }\n}<\/code><\/pre>\n<h3>include \u6b63\u5219\u7b5b\u9009\u5206\u7ec4\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<ul>\n<li>\u8bf7\u6c42<\/li>\n<\/ul>\n<pre><code class=\"language-java\">localhost:9200\/nba\/_search<\/code><\/pre>\n<ul>\n<li>\u8bf7\u6c42\u4f53<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  \/\/ \u8bed\u4e49: \u6e56\u4eba\u548c\u706b\u7bad\u961f\u6309\u7403\u961f\u5e73\u5747\u5e74\u9f84\u8fdb\u884c\u5206\u7ec4\u6392\u5e8f\uff08\u6307\u5b9a\u503c\u5217\u8868 \uff09\n  &quot;aggs&quot;: {\n    &quot;aggsTeamName&quot;: {\n      &quot;terms&quot;: {\n        &quot;field&quot;: &quot;teamNameEn&quot;,\n        \/\/ \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\n        &quot;include&quot;: &quot;Lakers|Ro.*|Warriors.*&quot;,\n        &quot;exclude&quot;: &quot;warriors&quot;,\n        &quot;size&quot;: 3,\n        &quot;order&quot;: {\n          &quot;avgAge&quot;: &quot;desc&quot;\n        }\n      },\n      &quot;aggs&quot;: {\n        &quot;avgAge&quot;: {\n          &quot;avg&quot;: {\n            &quot;field&quot;: &quot;age&quot;\n          }\n        }\n      }\n    }\n  },\n  &quot;size&quot;: 0\n}<\/code><\/pre>\n<ul>\n<li>\u54cd\u5e94<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;took&quot; : 0,\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; : 566,\n      &quot;relation&quot; : &quot;eq&quot;\n    },\n    &quot;max_score&quot; : null,\n    &quot;hits&quot; : [ ]\n  },\n  &quot;aggregations&quot; : {\n    &quot;aggsTeamName&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;Lakers&quot;,\n          &quot;doc_count&quot; : 21,\n          &quot;avgAge&quot; : {\n            &quot;value&quot; : 27.714285714285715\n          }\n        },\n        {\n          &quot;key&quot; : &quot;Rockets&quot;,\n          &quot;doc_count&quot; : 21,\n          &quot;avgAge&quot; : {\n            &quot;value&quot; : 26.761904761904763\n          }\n        },\n        {\n          &quot;key&quot; : &quot;Warriors&quot;,\n          &quot;doc_count&quot; : 20,\n          &quot;avgAge&quot; : {\n            &quot;value&quot; : 26.25\n          }\n        }\n      ]\n    }\n  }\n}<\/code><\/pre>\n<h3>range aggregation \u8303\u56f4\u5206\u7ec4\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<ul>\n<li>\u8bf7\u6c42<\/li>\n<\/ul>\n<pre><code class=\"language-java\">localhost:9200\/nba\/_search<\/code><\/pre>\n<ul>\n<li>\u8bf7\u6c42\u4f53<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  \/\/ \u8bed\u4e49: \u7403\u5458\u5e74\u9f84\u630920\u300120-35\u300135 \u8fd9\u6837\u5206\u7ec4\n  &quot;aggs&quot;: {\n    &quot;ageRange&quot;: {\n      &quot;range&quot;: {\n        &quot;field&quot;: &quot;age&quot;,\n        &quot;ranges&quot;: [\n          {\n            &quot;to&quot;: 20,  \/\/ \u5c0f\u4e8e\u7b49\u4e8e 20\n            &quot;key&quot;: &quot;A&quot; \/\/\u522b\u540d A\n          },\n          {\n            &quot;from&quot;: 20, \/\/ \u5927\u4e8e\u7b49\u4e8e20\n            &quot;to&quot;: 35, \/\/  \u5c0f\u4e8e\u7b49\u4e8e 35\n            &quot;key&quot;: &quot;B&quot;  \/\/\u522b\u540d B\n          },\n          {\n            &quot;from&quot;: 35, \/\/ \u5927\u4e8e\u7b49\u4e8e35 \n            &quot;key&quot;: &quot;C&quot; \/\/\u522b\u540d C\n          }\n        ]\n      }\n    }\n  }, \n  &quot;size&quot;: 0\n}<\/code><\/pre>\n<ul>\n<li>\u54cd\u5e94<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;took&quot; : 0,\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; : 566,\n      &quot;relation&quot; : &quot;eq&quot;\n    },\n    &quot;max_score&quot; : null,\n    &quot;hits&quot; : [ ]\n  },\n  &quot;aggregations&quot; : {\n    &quot;ageRange&quot; : {\n      &quot;buckets&quot; : [\n        {\n          &quot;key&quot; : &quot;A&quot;,\n          &quot;to&quot; : 20.0,\n          &quot;doc_count&quot; : 15\n        },\n        {\n          &quot;key&quot; : &quot;B&quot;,\n          &quot;from&quot; : 20.0,\n          &quot;to&quot; : 35.0,\n          &quot;doc_count&quot; : 531\n        },\n        {\n          &quot;key&quot; : &quot;C&quot;,\n          &quot;from&quot; : 35.0,\n          &quot;doc_count&quot; : 20\n        }\n      ]\n    }\n  }\n}<\/code><\/pre>\n<h3>date_range aggregation \u65f6\u95f4\u8303\u56f4\u5206\u7ec4\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<ul>\n<li>\u8bf7\u6c42<\/li>\n<\/ul>\n<pre><code class=\"language-java\">localhost:9200\/nba\/_search<\/code><\/pre>\n<ul>\n<li>\u8bf7\u6c42\u4f53<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  \/\/ \u8bed\u4e49: \u7403\u5458\u6309\u51fa\u751f\u5e74\u6708\u5206\u7ec4\n  &quot;aggs&quot;: {\n    &quot;birthDayRange&quot;: {\n      &quot;date_range&quot;: {   \/\/ \u65f6\u95f4\u7c7b\u578b\n        &quot;field&quot;: &quot;birthDay&quot;, \/\/ \u751f\u65e5 \u751f\u65e5\u662f\u65f6\u95f4\u7c7b\u578b\n        &quot;format&quot;: &quot;MM-yyyy&quot;, \/\/\u65f6\u95f4\u683c\u5f0f \u6708\u4efd\u5e74\u4efd\n        &quot;ranges&quot;: [\n          {\n            &quot;from&quot;: &quot;01-1989&quot; \/\/ \u5c0f\u4e8e1989\u5e741\u6708\u51fa\u751f\n          },\n          {\n            &quot;from&quot;: &quot;01-1989&quot;, \/\/ 1989\u5e741\u6708\u52301999\u5e741\u6708\n            &quot;to&quot;: &quot;01-1999&quot;\n          },\n          {\n            &quot;from&quot;: &quot;01-1999&quot;, \/\/ 1999\u5e741\u6708\u52302009\u5e741\u6708\n            &quot;to&quot;: &quot;01-2009&quot;\n          },\n          {\n            &quot;from&quot;: &quot;01-2009&quot;\n          }\n        ]\n      }\n    }\n  }, \n  &quot;size&quot;: 0\n}<\/code><\/pre>\n<ul>\n<li>\u54cd\u5e94<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;took&quot; : 0,\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; : 566,\n      &quot;relation&quot; : &quot;eq&quot;\n    },\n    &quot;max_score&quot; : null,\n    &quot;hits&quot; : [ ]\n  },\n  &quot;aggregations&quot; : {\n    &quot;birthDayRange&quot; : {\n      &quot;buckets&quot; : [\n        {\n          &quot;key&quot; : &quot;01-1989-01-1999&quot;,\n          &quot;from&quot; : 5.99616E11,\n          &quot;from_as_string&quot; : &quot;01-1989&quot;,\n          &quot;to&quot; : 9.151488E11,\n          &quot;to_as_string&quot; : &quot;01-1999&quot;,\n          &quot;doc_count&quot; : 426\n        },\n        {\n          &quot;key&quot; : &quot;01-1989-*&quot;,\n          &quot;from&quot; : 5.99616E11,\n          &quot;from_as_string&quot; : &quot;01-1989&quot;,\n          &quot;doc_count&quot; : 469\n        },\n        {\n          &quot;key&quot; : &quot;01-1999-01-2009&quot;,\n          &quot;from&quot; : 9.151488E11,\n          &quot;from_as_string&quot; : &quot;01-1999&quot;,\n          &quot;to&quot; : 1.230768E12,\n          &quot;to_as_string&quot; : &quot;01-2009&quot;,\n          &quot;doc_count&quot; : 43\n        },\n        {\n          &quot;key&quot; : &quot;01-2009-*&quot;,\n          &quot;from&quot; : 1.230768E12,\n          &quot;from_as_string&quot; : &quot;01-2009&quot;,\n          &quot;doc_count&quot; : 0\n        }\n      ]\n    }\n  }\n}<\/code><\/pre>\n<h3>date_histogram aggregation \u65f6\u95f4\u8303\u56f4\u5206\u7ec4\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<p>\u6309\u5929\u3001\u6708\u3001\u5e74\u7b49\u8fdb\u884c\u805a\u5408\u7edf\u8ba1\u3002\u53ef\u6309<code>year (1y)<\/code>, <code>quarter (1q)<\/code>, <code>month (1M)<\/code>, <code>week (1w)<\/code>, <code>day (1d)<\/code>, <code>hour (1h)<\/code>, <code>minute (1m)<\/code>, <code>second (1s)<\/code>\u95f4\u9694\u805a\u5408<\/p>\n<ul>\n<li>\u8bf7\u6c42<\/li>\n<\/ul>\n<pre><code class=\"language-java\">localhost:9200\/nba\/_search<\/code><\/pre>\n<ul>\n<li>\u8bf7\u6c42\u4f53<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n    \/\/ \u8bed\u4e49: \u7403\u5458\u6309\u51fa\u751f\u5e74\u5206\u7ec4\n  &quot;aggs&quot;: {\n    &quot;birthday_aggs&quot;: {\n      &quot;date_histogram&quot;: {\n        &quot;field&quot;: &quot;birthDay&quot;, \/\/\u751f\u65e5\u5b57\u6bb5\n        &quot;format&quot;: &quot;yyyy&quot;,  \/\/ \u65f6\u95f4\u683c\u5f0f\n        &quot;calendar_interval&quot;: &quot;year&quot; \/\/ \u6839\u636e\u5e74\n      }\n    }\n  }, \n  &quot;size&quot;: 0\n}<\/code><\/pre>\n<ul>\n<li>\u54cd\u5e94<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;took&quot; : 1,\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; : 566,\n      &quot;relation&quot; : &quot;eq&quot;\n    },\n    &quot;max_score&quot; : null,\n    &quot;hits&quot; : [ ]\n  },\n  &quot;aggregations&quot; : {\n    &quot;birthday_aggs&quot; : {\n      &quot;buckets&quot; : [\n        {\n          &quot;key_as_string&quot; : &quot;1977&quot;,\n          &quot;key&quot; : 220924800000,\n          &quot;doc_count&quot; : 1\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1978&quot;,\n          &quot;key&quot; : 252460800000,\n          &quot;doc_count&quot; : 1\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1979&quot;,\n          &quot;key&quot; : 283996800000,\n          &quot;doc_count&quot; : 0\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1980&quot;,\n          &quot;key&quot; : 315532800000,\n          &quot;doc_count&quot; : 3\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1981&quot;,\n          &quot;key&quot; : 347155200000,\n          &quot;doc_count&quot; : 2\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1982&quot;,\n          &quot;key&quot; : 378691200000,\n          &quot;doc_count&quot; : 3\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1983&quot;,\n          &quot;key&quot; : 410227200000,\n          &quot;doc_count&quot; : 2\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1984&quot;,\n          &quot;key&quot; : 441763200000,\n          &quot;doc_count&quot; : 8\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1985&quot;,\n          &quot;key&quot; : 473385600000,\n          &quot;doc_count&quot; : 15\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1986&quot;,\n          &quot;key&quot; : 504921600000,\n          &quot;doc_count&quot; : 19\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1987&quot;,\n          &quot;key&quot; : 536457600000,\n          &quot;doc_count&quot; : 16\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1988&quot;,\n          &quot;key&quot; : 567993600000,\n          &quot;doc_count&quot; : 27\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1989&quot;,\n          &quot;key&quot; : 599616000000,\n          &quot;doc_count&quot; : 24\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1990&quot;,\n          &quot;key&quot; : 631152000000,\n          &quot;doc_count&quot; : 35\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1991&quot;,\n          &quot;key&quot; : 662688000000,\n          &quot;doc_count&quot; : 31\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1992&quot;,\n          &quot;key&quot; : 694224000000,\n          &quot;doc_count&quot; : 36\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1993&quot;,\n          &quot;key&quot; : 725846400000,\n          &quot;doc_count&quot; : 46\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1994&quot;,\n          &quot;key&quot; : 757382400000,\n          &quot;doc_count&quot; : 45\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1995&quot;,\n          &quot;key&quot; : 788918400000,\n          &quot;doc_count&quot; : 57\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1996&quot;,\n          &quot;key&quot; : 820454400000,\n          &quot;doc_count&quot; : 56\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1997&quot;,\n          &quot;key&quot; : 852076800000,\n          &quot;doc_count&quot; : 57\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1998&quot;,\n          &quot;key&quot; : 883612800000,\n          &quot;doc_count&quot; : 39\n        },\n        {\n          &quot;key_as_string&quot; : &quot;1999&quot;,\n          &quot;key&quot; : 915148800000,\n          &quot;doc_count&quot; : 28\n        },\n        {\n          &quot;key_as_string&quot; : &quot;2000&quot;,\n          &quot;key&quot; : 946684800000,\n          &quot;doc_count&quot; : 15\n        }\n      ]\n    }\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>terms aggregation \u6876\u805a\u5408\u67e5\u8be2 GET\/POST \u8bf7\u6c42 localhost:9200\/nba\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[301],"tags":[],"class_list":["post-1106","post","type-post","status-publish","format-standard","hentry","category-elasticsearch"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1106"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1106\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}