Convert strings to floats at aggregation time?

前端 未结 1 1894
我寻月下人不归
我寻月下人不归 2021-01-02 15:40

Is there any way to convert strings to floats when specifying a histogram aggregation? Because I have documents with fields that are floats but are not parsed by elasticsear

相关标签:
1条回答
  • 2021-01-02 16:13

    You need this

    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "sensorId": "D14UD021808ARZC"
              }
            },
            {
              "match": {
                "variableName": "CAUDAL"
              }
            }
          ]
        }
      },
      "aggs": {
        "caudal_per_month": {
          "date_histogram": {
            "field": "timestamp",
            "interval": "month"
          },
          "aggs": {
            "totalmonth": {
              "sum": {
                "script": "Float.parseFloat(doc['value'].value)"
              }
            }
          }
        }
      }
    }
    

    For a field that's called value: Float.parseFloat(doc['value'].value)

    0 讨论(0)
提交回复
热议问题