这里我们感兴趣的是使用高基数索引。(这是弹性搜索的一个问题)
我们已经从你方得知,对于
select count(distinct high_cardinality_field) from my_table
您已经进行了一些优化来计算它。会不会有一天我们可以这样写:
select count_via_hyperloglog(high_cardinality_field) from my_table
将count_via_hyperloglog作为UDF或其他东西,因为它现在可以通过ES-plugins在ES中实现?
在我们的backlog中,这个特性是作为一个额外的聚合函数使用hyperlog算法。我们计划使用presto http://prestodb.io/docs/current/functions/aggregate.html衍生的命名。您的示例可能看起来像:
select approx_distinct(high_cardinality_field) from my_table
但是,对于每个表中的一个特定字段,可能的性能改进是根据https://crate.io/docs/current/sql/ddl.html#routing
计划在1.1.0中使用HyperLogLog进行高基数计数,文档已经发布:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
的例子:
{
"aggs" : {
"author_count" : {
"cardinality" : {
"field" : "author"
}
}
}
}
对于像UDF这样的东西,您可以使用脚本,例如。通过将过滤器聚合与脚本过滤器
相结合{
"aggs": {
"in_stock_products": {
"filter": {
"script": {
"script": "doc['price'].value > minPrice"
"params": {
"minPrice": 5
}
}
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}