# Help - Display correct document from multiple aggregation

**URL:** <https://discuss.elastic.co/t/help-display-correct-document-from-multiple-aggregation/329669>\
**Category:** Elasticsearch\
**Created:** [April 10, 2023, 3:18pm UTC](https://discuss.elastic.co/t/help-display-correct-document-from-multiple-aggregation/329669 "2023-04-10T15:18:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santiago\_Lovera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/santiago_lovera/32/119589_2.png) [@Santiago\_Lovera](https://discuss.elastic.co/u/Santiago_Lovera)\
**Post date:** [April 10, 2023, 3:18pm UTC](https://discuss.elastic.co/t/help-display-correct-document-from-multiple-aggregation/329669/1 "2023-04-10T15:18:35Z")

</div>

I need help please.

I want to display a label in vega with information returned by one aggregation operation.

I'm only looking for just 2 documents the minimum and the maximum for the  
**log.json.sequence** field.

When I access the values by **data('minsequence')[0].aggregations.min\_sequence.value** and **data('maxsequence')[0].aggregations.max\_sequence.value** It shows the correct values.

But when I access others values from respective documents like **data('minsequence')[0].hits.hits[0].\_source.time** and **data('maxsequence')[0].hits.hits[0].\_source.time** shows the wrong values and both of them looks like the same document.

Thanks

```auto
 "$schema": "https://vega.github.io/schema/vega/v5.json",
    "data": [
        {
          "name":"minsequence",
          "url": {
              "%context%": true,
              "%timefield%": "@timestamp",
              "index": "app.*",
              "body": {
                  "size": 1,
                  "aggs": 
                    {
                      "min_sequence": {
                          "min": {
                              "field": "log.json.sequence"
                          }
                      }                      
                    },
                    fields: ["*"]
              }
          }
        },
        {
          "name":"maxsequence",
          "url": {
              "%context%": true,
              "%timefield%": "@timestamp",
              "index": "app.*",
              "body": {
                  "size": 1,
                  "aggs": 
                    {
                      "max_sequence": {
                          "max": {
                              "field": "log.json.sequence"
                          }
                      }                      
                    },
                    fields: ["*"]
              }
          }
        }
    ],
    "marks": [
        {
            "type": "text",
            "encode": {
                "update": 
                {
                  "x": {"value": 0},
                  "y": {"value": 0},
                  "fontSize": {"value": 12},
                  "text": {
                      "signal": "'First log - Min Sequence Value - ' + data('minsequence')[0].aggregations.min_sequence.value + ', tempo - ' + data('minsequence')[0].hits.hits[0]._source.time"
                  }
                }
            }
        },
        {
            "type": "text",
            "encode": {
                "update": 
                {
                  "x": {"value": 0},
                  "y": {"value": 15},
                  "fontSize": {"value": 12},
                  "text": {
                      "signal": "'Last log - Min Sequence Value - ' + data('maxsequence')[0].aggregations.max_sequence.value + ', tempo - ' + data('maxsequence')[0].hits.hits[0]._source.time"
                  }
                }
            }
        }
    ] 
} 

```

---

<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:** [May 8, 2023, 3:18pm UTC](https://discuss.elastic.co/t/help-display-correct-document-from-multiple-aggregation/329669/2 "2023-05-08T15:18:52Z")

</div>

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