{"id":1105,"date":"2023-03-12T11:42:42","date_gmt":"2023-03-12T03:42:42","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1105"},"modified":"2023-04-29T11:24:36","modified_gmt":"2023-04-29T03:24:36","slug":"elasticsearch-7-search-aggregation-query-indicator-aggregation","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/elasticsearch-7-search-aggregation-query-indicator-aggregation\/","title":{"rendered":"ElasticSearch 7 \u641c\u7d22\uff0810\uff09\u805a\u5408\u67e5\u8be2\u6307\u6807\u805a\u5408"},"content":{"rendered":"<p>ES\u805a\u5408\u5206\u6790\u662f\u4ec0\u4e48<\/p>\n<ol>\n<li>\u805a\u5408\u5206\u6790\u662f\u6570\u636e\u5e93\u4e2d\u91cd\u8981\u7684\u529f\u80fd\u7279\u6027\uff0c\u5b8c\u6210\u5bf9\u4e00\u4e2a\u67e5\u8be2\u7684\u6570\u636e\u96c6\u4e2d\u6570\u636e\u7684\u805a\u5408\u8ba1\u7b97\uff0c\u5982\uff1a\u627e\u51fa\u67d0\u5b57\u6bb5\uff08\u6216\u8ba1\u7b97\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\uff09\u7684\u6700\u5927\u503c\u3001\u6700\u5c0f\u503c\uff0c\u8ba1\u7b97\u548c\u3001\u5e73\u5747\u503c\u7b49\u3002ES\u4f5c\u4e3a\u641c\u7d22\u5f15\u64ce\u517c\u6570\u636e\u5e93\uff0c\u540c\u6837\u63d0\u4f9b\u4e86\u5f3a\u2f24\u7684\u805a\u5408\u5206\u6790\u80fd\u529b<\/li>\n<li>\u5bf9\u4e00\u4e2a\u6570\u636e\u96c6\u6c42\u6700\u5927\u3001\u6700\u5c0f\u3001\u548c\u3001\u5e73\u5747\u503c\u7b49\u6307\u6807\u7684\u805a\u5408\uff0c\u5728ES\u4e2d\u79f0\u4e3a<strong>\u6307\u6807\u805a\u5408<\/strong> <\/li>\n<li>\u800c\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e2d\u9664\u4e86\u6709\u805a\u5408\u51fd\u6570\u5916\uff0c\u8fd8\u53ef\u4ee5\u5bf9\u67e5\u8be2\u51fa\u7684\u6570\u636e\u884c\u5206\u7ec4<code>group by<\/code>\uff0c\u518d\u5728\u7ec4\u4e0a\u8fdb\u884c\u6307\u6807\u805a\u5408\u3002\u5728ES\u4e2d\u79f0\u4e3a<strong>\u6876\u805a\u5408<\/strong><\/li>\n<\/ol>\n<p><!-- more --><\/p>\n<h3>max min sum avg \u6307\u6807\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: \u67e5\u8be2\u706b\u7bad\u961f\u7403\u5458\u5e73\u5747\u5e74\u9f84\n  &quot;query&quot;: {\n    &quot;term&quot;: {\n      &quot;teamNameEn&quot;: &quot;Rockets&quot;\n    }\n  },\n  &quot;aggs&quot;: { \/\/ aggs \u4ee3\u8868\u4f7f\u7528\u805a\u5408\u51fd\u6570\n    &quot;avgAge&quot;: { \/\/ avgAge\u662f\u81ea\u5b9a\u4e49\u7684\uff0c\u56e0\u4e3a\u662f\u67e5\u5e74\u5e74\u9f84\u5e73\u5747\u6240\u4ee5\u8d77\u540davgAge\n      &quot;avg&quot;: { \/\/ avg \u5e73\u5747\n        &quot;field&quot;: &quot;age&quot;\n      }\n    }\n  }, \n  &quot;size&quot;: 0 \/\/ \u4e0d\u770b\u6570\u636e\u53ea\u770b\u6307\u6807\u805a\u5408\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;avgAge&quot; : {\n      &quot;value&quot; : 26.761904761904763 \/\/ \u5e73\u5747\u5e74\u9f84\n    }\n  }\n}<\/code><\/pre>\n<h3>value_count \u6307\u6807\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<p>\u7edf\u8ba1\u975e\u7a7a\u5b57\u6bb5\u7684\u6587\u6863\u6570<\/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: \u67e5\u8be2\u706b\u7bad\u961f\u4e2d\u7403\u5458\u6253\u7403\u65f6\u95f4\u4e0d\u4e3a\u7a7a\u7684\u6570\u91cf\n  &quot;query&quot;: {\n    &quot;term&quot;: {\n      &quot;teamNameEn&quot;: &quot;Rockets&quot;\n    }\n  },\n  &quot;aggs&quot;: {\n    &quot;countPlayerYear&quot;: {\n      &quot;value_count&quot;: {\n        &quot;field&quot;: &quot;playYear&quot;\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; : 4,\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;countPlayerYear&quot; : {\n      &quot;value&quot; : 21\n    }\n  }\n}<\/code><\/pre>\n<h3>_count \u6307\u6807\u805a\u5408\u67e5\u8be2\uff08\u4e25\u683c\u6765\u8bf4\u4e0d\u5c5e\u4e8e\u805a\u5408\uff09 GET\/POST<\/h3>\n<p>\u67e5\u8be2\u706b\u7bad\u961f\u6709\u591a\u5c11\u6587\u6863\uff0c\u4e5f\u5c31\u662f\u6709\u591a\u5c11\u7403\u5458<\/p>\n<ul>\n<li>\u8bf7\u6c42<\/li>\n<\/ul>\n<pre><code class=\"language-java\">localhost:9200\/nba\/_count<\/code><\/pre>\n<ul>\n<li>\u8bf7\u6c42\u4f53<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n  &quot;query&quot;: {\n    &quot;term&quot;: {\n      &quot;teamNameEn&quot;: &quot;Rockets&quot;\n    }\n  }\n}<\/code><\/pre>\n<ul>\n<li>\u54cd\u5e94<\/li>\n<\/ul>\n<pre><code class=\"language-json\">{\n    &quot;count&quot;: 21,\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}<\/code><\/pre>\n<h3>cardinality \u6307\u6807\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<ul>\n<li>\n<p>Cardinality \u503c\u53bb\u91cd\u8ba1\u7b97<\/p>\n<\/li>\n<li>\n<p>\u8bf7\u6c42<\/p>\n<\/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: \u67e5\u8be2\u706b\u7bad\u961f\u4e2d\u5e74\u9f84\u4e0d\u540c\u7684\u6570\u91cf\n  &quot;query&quot;: {\n    &quot;term&quot;: {\n      &quot;teamNameEn&quot;: &quot;Rockets&quot;\n    }\n  },\n  &quot;aggs&quot;: {\n    &quot;countAge&quot;: { \/\/ \u81ea\u5b9a\u4e49\u540d\u5b57\n      &quot;cardinality&quot;: { \/\/ \u53bb\u6389\u76f8\u540c\u7684\u53ea\u4fdd\u7559\u4e00\u4e2a\u503c\n        &quot;field&quot;: &quot;age&quot;\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;countAge&quot; : {\n      &quot;value&quot; : 13\n    }\n  }\n}<\/code><\/pre>\n<h3>stats 5\u79cd\u6307\u6807\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<p><code>stats<\/code>\u7edf\u8ba1<code>count max min avg sum<\/code>5\u4e2a\u503c<\/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: \u67e5\u8be2\u706b\u7bad\u7403\u5458\u7684\u5e74\u9f84status\n  &quot;query&quot;: {\n    &quot;term&quot;: {\n      &quot;teamNameEn&quot;: &quot;Rockets&quot;\n    }\n  },\n  &quot;aggs&quot;: {\n    &quot;status&quot;: {\n      &quot;stats&quot;: {\n        &quot;field&quot;: &quot;age&quot;\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;status&quot; : {\n      &quot;count&quot; : 21,\n      &quot;min&quot; : 21.0,\n      &quot;max&quot; : 37.0,\n      &quot;avg&quot; : 26.761904761904763,\n      &quot;sum&quot; : 562.0\n    }\n  }\n}\n<\/code><\/pre>\n<h3>extended status \u79cd\u6307\u6807\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<p><code>Extended stats<\/code>\u6bd4<code>stats<\/code>\u591a4\u4e2a\u7edf\u8ba1\u7ed3\u679c\uff1a\u5e73\u65b9\u548c\u3001\u65b9\u5dee\u3001\u6807\u51c6\u5dee\u3001\u5e73\u5747\u503c\u52a0\u51cf\u4e24\u4e2a\u6807\u51c6\u5dee\u7684\u533a\u95f4<\/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  \/\/ \u67e5\u51fa\u706b\u7bad\u961f\u7403\u5458\u7684\uf98e\u9f84Extend stats\n  &quot;query&quot;: {\n    &quot;term&quot;: {\n      &quot;teamNameEn&quot;: &quot;Rockets&quot;\n    }\n  },\n  &quot;aggs&quot;: {\n    &quot;extendedStatsAge&quot;: {\n      &quot;extended_stats&quot;: {\n        &quot;field&quot;: &quot;age&quot;\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;extendedStatsAge&quot; : {\n      &quot;count&quot; : 21,\n      &quot;min&quot; : 21.0,\n      &quot;max&quot; : 37.0,\n      &quot;avg&quot; : 26.761904761904763,\n      &quot;sum&quot; : 562.0,\n      &quot;sum_of_squares&quot; : 15534.0,\n      &quot;variance&quot; : 23.5147392290249,\n      &quot;std_deviation&quot; : 4.84919985451465,\n      &quot;std_deviation_bounds&quot; : {\n        &quot;upper&quot; : 36.46030447093406,\n        &quot;lower&quot; : 17.063505052875463\n      }\n    }\n  }\n}<\/code><\/pre>\n<h3>percentiles \u79cd\u6307\u6807\u805a\u5408\u67e5\u8be2 GET\/POST<\/h3>\n<p><code>Percentiles<\/code>\u5360\u6bd4\u767e\u5206\u4f4d\u5bf9\u5e94\u7684\u503c\u7edf\u8ba1\uff0c\u9ed8\u8ba4\u8fd4\u56de<code>[ 1, 5, 25, 50, 75, 95, 99 ]<\/code>\u5206\u4f4d\u4e0a\u7684\u503c<\/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: \u67e5\u51fa\u706b\u7bad\u7684\u7403\u5458\u7684\uf98e\u9f84\u5360\u6bd4\n  &quot;query&quot;: {\n    &quot;term&quot;: {\n      &quot;teamNameEn&quot;: &quot;Rockets&quot;\n    }\n  },\n  &quot;aggs&quot;: {\n    &quot;percentilesAge&quot;: {\n      &quot;percentiles&quot;: {\n        &quot;field&quot;: &quot;age&quot;,\n        \/\/ \u8fd9\u91cc\u53ef\u4ee5\u6307\u5b9a\uff0c\u4e0d\u4f7f\u7528\u9ed8\u8ba4\n        \/\/ &quot;percents&quot;: [\n        \/\/   25,\n        \/\/   50,\n        \/\/   75\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; : 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;percentilesAge&quot; : {\n      &quot;values&quot; : {\n        &quot;1.0&quot; : 21.0,\n        &quot;5.0&quot; : 21.0,\n        &quot;25.0&quot; : 22.75, \/\/ \u5c0f\u4e8e22.75\u5c81\u7684 \u536025%\n        &quot;50.0&quot; : 25.0,\n        &quot;75.0&quot; : 30.25,\/\/ \u5c0f\u4e8e30.25\u5c81\u7684 \u536075%\n        &quot;95.0&quot; : 35.349999999999994,\n        &quot;99.0&quot; : 37.0\n      }\n    }\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ES\u805a\u5408\u5206\u6790\u662f\u4ec0\u4e48 \u805a\u5408\u5206\u6790\u662f\u6570\u636e\u5e93\u4e2d\u91cd\u8981\u7684\u529f\u80fd\u7279\u6027\uff0c\u5b8c\u6210\u5bf9\u4e00\u4e2a\u67e5\u8be2\u7684\u6570\u636e\u96c6\u4e2d\u6570\u636e\u7684\u805a\u5408\u8ba1\u7b97\uff0c\u5982\uff1a\u627e\u51fa\u67d0\u5b57\u6bb5\uff08 [&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-1105","post","type-post","status-publish","format-standard","hentry","category-elasticsearch"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1105","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=1105"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1105\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}