0

我学会了如何编写ES查询来计算百分位数,但它似乎适用于一个字段。如果我想在多个领域获得百分位数,则不起作用。如果我在百分节只是一个场(场A或B,但不能同时),但我想有10场以上的如何在一个ElasticSearch查询中获取多个字段的百分位

"aggs": { 
     "distinct_UUID": { 
      "terms": { 
       "field": "cust_uuid" 
      }, 
       "aggs": { 
        "perf_percentiles" : { 
       "percentiles" : { 
     "field":"A", 
     "field":"B" 
     } 
     } 

上面的代码工作正常。我该如何解决它?

回答

2

只需添加更多的子聚合,每一个领域:

{ 
    "aggs": { 
    "distinct_UUID": { 
     "terms": { 
     "field": "cust_uuid" 
     }, 
     "aggs": { 
     "percentile_a": { 
      "percentiles": { 
      "field": "A" 
      } 
     }, 
     "percentile_b": { 
      "percentiles": { 
      "field": "B" 
      } 
     }, 
     "percentile_c": { 
      "percentiles": { 
      "field": "C" 
      } 
     } 
     } 
    } 
    } 
} 
+0

谢谢!这很有帮助。我使用网站上的ES权威指南。你有推荐的其他参考吗? –

+0

很酷,很高兴它有帮助。这和[官方文档](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)是一个好的开始。 – Val

相关问题