{"id":210438,"date":"2020-11-29T22:30:37","date_gmt":"2020-11-29T14:30:37","guid":{"rendered":"http:\/\/4563.org\/?p=210438"},"modified":"2020-11-29T22:30:37","modified_gmt":"2020-11-29T14:30:37","slug":"%e6%b1%82%e5%8a%a9%ef%bc%9a-es-%e8%81%9a%e5%90%88%e6%9f%a5%e8%af%a2%ef%bc%8c%e4%bd%bf%e7%94%a8%e4%ba%86-nested%ef%bc%8c%e5%a6%82%e4%bd%95%e5%86%8d%e5%af%b9%e6%9f%90%e4%b8%aa%e5%ad%97%e6%ae%b5%e6%8e%92","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=210438","title":{"rendered":"\u6c42\u52a9\uff1a ES \u805a\u5408\u67e5\u8be2\uff0c\u4f7f\u7528\u4e86 nested\uff0c\u5982\u4f55\u518d\u5bf9\u67d0\u4e2a\u5b57\u6bb5\u6392\u5e8f\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6c42\u52a9\uff1a ES \u805a\u5408\u67e5\u8be2\uff0c\u4f7f\u7528\u4e86 nested\uff0c\u5982\u4f55\u518d\u5bf9\u67d0\u4e2a\u5b57\u6bb5\u6392\u5e8f\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sniperking1234 <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u67e5\u8be2\u8bed\u53e5\u5982\u4e0b\u9762\u6240\u793a<\/p>\n<pre><code>{     \"size\": 0,     \"aggs\": {         \"tags\": {             \"nested\": {                 \"path\": \"tags\"             },             \"aggs\": {                 \"key\": {                     \"filter\": {                         \"term\": {                             \"tags.key\": \"http.url\"                         }                     },                     \"aggs\": {                         \"values\": {                             \"terms\": {                                 \"field\": \"tags.value\",                                 \"size\": 100                             },                             \"aggs\": {                                 \"rev\": {                                     \"reverse_nested\": {},                                     \"aggs\": {                                         \"duration\": {                                             \"avg\": {                                                 \"field\": \"duration\"                                             }                                         }                                     }                                 }                             }                         }                     }                 }             }         }     } } <\/code><\/pre>\n<p>\u6211\u60f3\u5bf9 duration \u8fd9\u4e2a\u5b57\u6bb5\u6309\u7167\u5e73\u5747\u503c\u4ece\u5927\u5230\u5c0f\u6392\u5e8f\uff0c\u627e\u51fa\u524d 100 \u6761\u6570\u636e\uff0c\u90a3\u4e48\u8fd9\u4e48\u6392\u5e8f\u8981\u52a0\u5728\u4ec0\u4e48\u5730\u65b9\u5462\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4365450\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zsl199512101234 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/www.elastic.co\/guide\/cn\/elasticsearch\/guide\/current\/nested-sorting.html                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4365451\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : sniperking1234 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zsl199512101234 \u6211\u8bd5\u4e86\u4e0b\uff0c\u8fd9\u6837\u5199 sort \u8c8c\u4f3c\u5bf9\u6709\u805a\u5408\u7684\u67e5\u8be2\u4e0d\u8d77\u4f5c\u7528\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4365452\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : sniperking1234 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u627e\u5230\u65b9\u6cd5\u4e86\uff0c\u8fd9\u4e48\u5199\u5c31\u53ef\u4ee5<br \/>{<br \/> &#8220;size&#8221;: 0,<br \/> &#8220;aggs&#8221;: {<br \/> &#8220;tags&#8221;: {<br \/> &#8220;nested&#8221;: {<br \/> &#8220;path&#8221;: &#8220;tags&#8221;<br \/> },<br \/> &#8220;aggs&#8221;: {<br \/> &#8220;key&#8221;: {<br \/> &#8220;filter&#8221;: {<br \/> &#8220;term&#8221;: {<br \/> &#8220;tags.key&#8221;: &#8220;http.url&#8221;<br \/> }<br \/> },<br \/> &#8220;aggs&#8221;: {<br \/> &#8220;values&#8221;: {<br \/> &#8220;terms&#8221;: {<br \/> &#8220;field&#8221;: &#8220;tags.value&#8221;,<br \/> &#8220;size&#8221;: 200,<br \/> &#8220;order&#8221;: {&#8220;rev&gt;duration&#8221;: &#8220;desc&#8221;} <br \/> },<br \/> &#8220;aggs&#8221;: {<br \/> &#8220;rev&#8221;: {<br \/> &#8220;reverse_nested&#8221;: {},<br \/> &#8220;aggs&#8221;: {<br \/> &#8220;duration&#8221;: {<br \/> &#8220;avg&#8221;: {<br \/> &#8220;field&#8221;: &#8220;duration&#8221;<br \/> }<br \/> }<br \/> }<br \/> }<br \/> }<br \/> }<br \/> }<br \/> }<br \/> }<br \/> }<br \/> }<br \/>}                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6c42\u52a9\uff1a ES \u805a\u5408\u67e5\u8be2\uff0c\u4f7f\u7528\u4e86 n&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\/210438"}],"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=210438"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/210438\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=210438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=210438"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=210438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}