ElasticSearch:如何返回带有特定小数点个数的输出值

oiopk7p5  于 2022-12-22  发布在  ElasticSearch
关注(0)|答案(1)|浏览(133)
    • ElasticSearch:六、八、二十三**

我正在尝试返回当前具有指定小数点数目的聚合列的输出值,它返回具有13个小数点的输出。我已尝试在查询请求中设置格式,但它不起作用,使用的查询:

{
"size": 0,
"query": {
    "bool": {
        "adjust_pure_negative": true,
        "must": [{
                "range": {}
                }
            }, {
                "terms": {}
            }
        ]
    }
},
"aggs": {
    "composite_buckets": {
        "composite": {
            "sources": [{
                    "outputCol1": {
                        "terms": {
                            "missing_bucket": true,
                            "field": "col1",
                            "order": "asc"
                        }
                    }
                }, {
                    "outputCol2": {
                        "terms": {
                            "missing_bucket": true,
                            "field": "col2",
                            "order": "asc"
                        }
                    }
                }, {
                    "outputCol3": {
                        "terms": {
                            "value_type": "string",
                            "missing_bucket": true,
                            "script": {
                                "source": "1",
                                "lang": "painless"
                            },
                            "order": "asc"
                        }
                    }
                }
            ]
        },
        "aggregations": {
            "outputCol4": {
                "format": "0.000"
                "avg": {
                    "script": {
                        "source": "doc['col4'].value",
                        "lang": "painless"
                    }
                }
            }
        }
       }
   }

  }

我的问题:
1.当我们只查询某些字段时,是否可以更改小数点,因为输出也可以包含非十进制值,如IntegerString

  1. Elasticsearch服务级别中是否有任何属性可以限制输出或存储字段中的小数点总数?
new9mtju

new9mtju1#

我通过format属性格式化十进制输出(参见下面的示例)

{
"from": 0,
"size": 0,
"aggregations": {
    "aggr": {
        "type": "term",
        "field": "type.keyword",
        "size": 10,
        "order": {
            "myAggr2.value": "desc"
        },
        "aggregations": {
            "myAggr2": {
                "type": "sum",
                "field": "cable_length_attribute"
            }
        }
    },
    "total_myAggr2": {
        "type": "sum_bucket",
        "buckets_path": "aggr>myAggr2",
        "format": "#.##"
    }
},
"types": [
    "cable_feature"
],
"typeQuery": {
    "cable_feature": {
        "type": "bool",
        "must": [
            {
                "type": "matchAll"
            }
        ],
        "should": null,
        "must_not": null
    }
}

}

相关问题