Source for min eggs


(Driaux Cédric) #1

hi i want to know the date of my min and max value

i have this aggs

 "aggs": {
"infodate": {
  "date_histogram": {
    "field": "datecreation",
    "interval": "month"
  },
  "aggs": {

    "moyenneposition": {
      "avg": {
        "field": "position"
      }
      
    },
    "minpos":{
      
      "min": {
      
        "field": "position"
        
      }
    
    },
    "maxpos" :{
      "max": {
        "field": "position"
      }
    }
  }
}

}

but on the min and max for each mont i want to know the date for the min value and the date for the max value ? it's possible ?

in result

{
      "key_as_string": "2017-05-01T00:00:00.000Z",
      "key": 1493596800000,
      "doc_count": 241,
      "moyenneposition": {
        "value": 89.00165971829189
      },
      "minpos": {
        "value": 1
      },
      "maxpos": {
        "value": 450
      }
    }

and i want for example

  "maxpos": {
        "value": 450,
        "datecreation":"yyyy-mm-dd"
      }

thanks


#2

I don't think you can do that, so you have to add another aggregation to get this value :

{
  "aggs": {
    "infodate": {
      "date_histogram": {
        "field": "datecreation",
        "interval": "month"
      },
      "aggs": {
        "moyenneposition": {
          "avg": {
            "field": "position"
          }
        },
        "minpos": {
          "min": {
            "field": "position"
          },
          "aggs": {
            "min-date": {
              "terms": {
                "field": "datecreation",
                "size": 1
              }
            }
          }
        },
        "maxpos": {
          "max": {
            "field": "position"
          },
          "aggs": {
            "max-date": {
              "terms": {
                "field": "datecreation",
                "size": 1
              }
            }
          }
        }
      }
    }
  }
}

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.