{"id":326152,"date":"2021-02-06T01:43:21","date_gmt":"2021-02-05T17:43:21","guid":{"rendered":"http:\/\/4563.org\/?p=326152"},"modified":"2021-02-06T01:43:21","modified_gmt":"2021-02-05T17:43:21","slug":"elasticsearch-%e4%b8%ad%e7%9a%84-terms-%e8%81%9a%e5%90%88%ef%bc%8c%e5%a6%82%e4%bd%95%e5%be%97%e5%88%b0%e6%89%80%e6%9c%89-buckets-%e7%9a%84%e6%95%b0%e9%87%8f%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=326152","title":{"rendered":"Elasticsearch \u4e2d\u7684 terms \u805a\u5408\uff0c\u5982\u4f55\u5f97\u5230\u6240\u6709 buckets \u7684\u6570\u91cf\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Elasticsearch \u4e2d\u7684 terms \u805a\u5408\uff0c\u5982\u4f55\u5f97\u5230\u6240\u6709 buckets \u7684\u6570\u91cf\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JJstyle <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u539f\u95ee\u9898\uff1a https:\/\/stackoverflow.com\/questions\/66043206\/how-to-get-the-buckets-count-from-terms-aggregation-in-elasticsearch<\/p>\n<p>\u6bd4\u5982\uff1a\u5f97\u5230\u6240\u6709\u8ba2\u5355\u6570\u91cf\u5927\u4e8e 10 \u7684\u7528\u6237\u603b\u6570\uff0c\u7c7b\u4f3c\u4e8e SQL \u8bed\u53e5\uff1a<\/p>\n<pre><code>select count(1) from (   select count(1) as cnt from orders group by userid having cnt &gt;= 10 ); <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>5<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5223708\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weofuh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             {<br \/> &#8220;aggs&#8221;: {<br \/> &#8220;user_order_cnt&#8221;: {<br \/> &#8220;terms&#8221;: {<br \/> &#8220;field&#8221;: &#8220;userid&#8221;<br \/> },<br \/> &#8220;aggs&#8221;: {<br \/> &#8220;count_bucket_selector&#8221;: {<br \/> &#8220;bucket_selector&#8221;: {<br \/> &#8220;buckets_path&#8221;: {<br \/> &#8220;count&#8221; :&#8221;_count&#8221;<br \/> },<br \/> &#8220;script&#8221;: &#8220;params.count&gt;10&#8221;<br \/> }<br \/> }<br \/> }<br \/> }<br \/> }<br \/>}                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5223709\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : JJstyle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @weofuh \u4f60\u8fd9\u4e2a\u662f\u8fc7\u6ee4\u51fa\u6765 count&gt;10 \u7684 buckets\uff0c\u4f46\u662f\u6211\u60f3\u8981\u7684\u662f\u8fd9\u4e9b buckets \u7684\u6570\u91cf                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5223710\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rykinia <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;`<br \/>{<br \/> &#8220;aggs&#8221;: {<br \/> &#8220;cnt&#8221;: {<br \/> &#8220;terms&#8221;: {<br \/> &#8220;field&#8221;: &#8220;userid&#8221;,<br \/> &#8220;size&#8221;: 1000,<br \/> &#8220;min_doc_count&#8221;: 10<br \/> }<br \/> }<br \/> },<br \/> &#8220;size&#8221;: 0<br \/>}<br \/>&#8220;`<\/p>\n<p>\u7ed3\u679c\uff1a<br \/>&#8220;`<br \/>&#8220;buckets&#8221; : [<br \/> {<br \/> &#8220;key&#8221; : &#8220;320581180&#8221;,<br \/> &#8220;doc_count&#8221; : 20<br \/> },<br \/> {<br \/> &#8220;key&#8221; : &#8220;2207021711&#8221;,<br \/> &#8220;doc_count&#8221; : 10<br \/> },<br \/>&#8220;`<\/p>\n<p>\u8fd9\u4e2a doc_count \u4e0d\u5c31\u662f\u6570\u91cf\u5417                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5223711\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : JJstyle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @rykinia \u4e0d\u662f\u7684\uff0c\u6211\u8981\u7684\u662f\u6240\u6709 doc_count&gt;10 \u7684 buckets \u7684\u6570\u91cf\uff0c\u800c\u4e0d\u662f buckets \u7684\u96c6\u5408                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5223712\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tairan2006 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8001\u54e5\uff0c\u4f60\u4e0d\u77e5\u9053`_sql\/translate`\u8fd9\u4e2a\u5de5\u5177\u4e48                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Elasticsearch \u4e2d\u7684 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/326152"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=326152"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/326152\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326152"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}