# Source for min eggs

**URL:** <https://discuss.elastic.co/t/source-for-min-eggs/140168>\
**Category:** Elasticsearch\
**Created:** [July 16, 2018, 3:04pm UTC](https://discuss.elastic.co/t/source-for-min-eggs/140168 "2018-07-16T15:04:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lebilien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lebilien/32/23755_2.png) [@lebilien](https://discuss.elastic.co/u/lebilien)\
**Post date:** [July 16, 2018, 3:04pm UTC](https://discuss.elastic.co/t/source-for-min-eggs/140168/1 "2018-07-16T15:04:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [July 20, 2018, 7:21am UTC](https://discuss.elastic.co/t/source-for-min-eggs/140168/2 "2018-07-20T07:21:32Z")

</div>

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
              }
            }
          }
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 17, 2018, 7:21am UTC](https://discuss.elastic.co/t/source-for-min-eggs/140168/3 "2018-08-17T07:21:35Z")

</div>

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