聚合优化参考:https://www.elastic.co/guide/cn/elasticsearch/guide/current/_preventing_combinatorial_explosions.html
ES笔记(有道云):
http://note.youdao.com/noteshare?id=2a9e896be3fd997d29a868bd17d1241a&sub=57DBAF694BBB459B89EE19D7FE731FD7
优化聚合查询:
https://www.elastic.co/guide/cn/elasticsearch/guide/current/_preventing_combinatorial_explosions.html#_preventing_combinatorial_explosions
1,ES配置(参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html)
http://47.96.229.136:9200/_cluster/health?level=indices
贸易搜索: { "size": 0, "query": { "bool": { "must": [{ "match_phrase": { "details": { "query": "books", "slop": 0, "zero_terms_query": "NONE", "boost": 1.0 } } }], "must_not": [{ "terms": { "buyer.keyword": ["N/A", "NVL", "", "NULL", "null", "n/a", "nvl"], "boost": 1.0 } }], "adjust_pure_negative": true, "boost": 1.0 } }, "aggregations": { "buyer_count": { "terms": { "field": "buyer.keyword", "size": 10, "min_doc_count": 1, "shard_min_doc_count": 0, "show_term_doc_count_error": false, "order": [{ "max_arrivaldate ": "desc" }, { "_key": "asc" }] }, "aggregations": { "TOP": { "top_hits": { "from": 0, "size": 1, "version": false, "explain": false, "sort": [{ "arrivaldate": { "order": "desc" } }] } }, "max_arrivaldate": { "max": { "field": "arrivaldate" } } } } } } 记录条数: { "size": 0, "query": { "bool": { "must": [{ "term": { "buyer.keyword": { "value": "SAAD TRADING", "boost": 1.0 } } }, { "match_phrase": { "details": { "query": "lamana", "slop": 0, "zero_terms_query": "NONE", "boost": 1.0 } } }], "adjust_pure_negative": true, "boost": 1.0 } } } 总金额: { "size": 0, "query": { "bool": { "must": [{ "term": { "buyer.keyword": { "value": "SILCOM S A", "boost": 1.0 } } }, { "range": { "arrivaldate": { "from": 1500171889297, "to": 1531707889297, "include_lower": true, "include_upper": true, "boost": 1.0 } } }, { "bool": { "should": [{ "term": { "htsCodes.keyword": { "value": "1106300000", "boost": 1.0 } } }, { "term": { "hsCode.keyword": { "value": "1106300000", "boost": 1.0 } } }], "adjust_pure_negative": true, "boost": 1.0 } }], "adjust_pure_negative": true, "boost": 1.0 } }, "sort": [{ "arrivaldate": { "order": "desc" } }, { "_id": { "order": "desc" } }], "aggregations": { "totalValueUsd": { "sum": { "field": "totalValueUsd" } }, "totalFob": { "sum": { "field": "totalFob" } }, "totalCif": { "sum": { "field": "totalCif" } } } } 贸易趋势: { "size": 0, "query": { "bool": { "must": [{ "term": { "buyer.keyword": { "value": "ASSOULINE PUBLISHING", "boost": 1.0 } } }, { "match_phrase": { "details": { "query": "books", "slop": 0, "zero_terms_query": "NONE", "boost": 1.0 } } }, { "range": { "arrivaldate": { "from": 1498838399000, "to": 1532966401000, "include_lower": true, "include_upper": true, "boost": 1.0 } } }], "adjust_pure_negative": true, "boost": 1.0 } }, "sort": [{ "arrivaldate": { "order": "desc" } }, { "_id": { "order": "desc" } }], "aggregations": { "count": { "terms": { "field": "arrivaldateMonth", "size": 10, "min_doc_count": 1, "shard_min_doc_count": 0, "show_term_doc_count_error": false, "order": [{ "_count": "desc" }, { "_key": "asc" }] } } } } 贸易记录: { "from": 0, "size": 10, "query": { "bool": { "must": [{ "term": { "buyer.keyword": { "value": "ASSOULINE PUBLISHING", "boost": 1.0 } } }, { "match_phrase": { "details": { "query": "books", "slop": 0, "zero_terms_query": "NONE", "boost": 1.0 } } }], "adjust_pure_negative": true, "boost": 1.0 } }, "sort": [{ "arrivaldate": { "order": "desc" } }, { "_id": { "order": "desc" } }] }