# Stats aggregation: as\_string fields missing when searching in multiple indices

**URL:** https://discuss.elastic.co/t/stats-aggregation-as-string-fields-missing-when-searching-in-multiple-indices/347016
**Category:** Elasticsearch
**Created:** [November 13, 2023, 1:23pm UTC](https://discuss.elastic.co/t/stats-aggregation-as-string-fields-missing-when-searching-in-multiple-indices/347016 "2023-11-13T13:23:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![msh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/msh/32/127492_2.png) [@msh](https://discuss.elastic.co/u/msh)
#### Post date: [November 13, 2023, 1:23pm UTC](https://discuss.elastic.co/t/stats-aggregation-as-string-fields-missing-when-searching-in-multiple-indices/347016/1 "2023-11-13T13:23:19Z")

</div>

Hi,

here are steps to reproduce:

- Fresh installation of ES v 8.11
- Create an index "items" with a document containing a date:

```auto
curl --location --request PUT 'localhost:9200/items/_doc/1' \
--header 'Content-Type: application/json' \
--data '{"date": "2023-01-01"}'

```

- Create another index "data" containing a document with a text:

```auto
curl --location --request PUT 'localhost:9200/data/_doc/1' \
--header 'Content-Type: application/json' \
--data '{"someText": "foobar"}'

```

- Aggregate with stats aggregation over date field in item index:

```auto
curl --location 'localhost:9200/items/_search?size=0' \
--header 'Content-Type: application/json' \
--data '{
    "aggregations": {
        "md.issued.date": {
            "stats": {
                "field": "date"
            }
        }
    }
}'

```

- Result:

```auto
{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "md.issued.date": {
            "count": 1,
            "min": 1.6725312E12,
            "max": 1.6725312E12,
            "avg": 1.6725312E12,
            "sum": 1.6725312E12,
            "min_as_string": "2023-01-01T00:00:00.000Z",
            "max_as_string": "2023-01-01T00:00:00.000Z",
            "avg_as_string": "2023-01-01T00:00:00.000Z",
            "sum_as_string": "2023-01-01T00:00:00.000Z"
        }
    }
}

```

- Aggregate with stats over date field in **all** (\*) indices:

```auto
curl --location 'localhost:9200/*/_search?size=0' \
--header 'Content-Type: application/json' \
--data '{
    "aggregations": {
        "md.issued.date": {
            "stats": {
                "field": "date"
            }
        }
    }
}'

```

- Response:

```auto
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 2,
        "successful": 2,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "md.issued.date": {
            "count": 1,
            "min": 1.6725312E12,
            "max": 1.6725312E12,
            "avg": 1.6725312E12,
            "sum": 1.6725312E12
        }
    }
}

```

Why are the \*\_as\_string fields (max\_as\_string, min\_as\_string, ...) missing in the response when I search over both indexes, and they are there when I search over the "items" index only? This used to work in Elasticsearch version 7.5, the fields were available in both cases.  
Is this a bug or intended behaviour?

Thank you for any help and hints.

---

<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: [December 11, 2023, 1:23pm UTC](https://discuss.elastic.co/t/stats-aggregation-as-string-fields-missing-when-searching-in-multiple-indices/347016/2 "2023-12-11T13:23:43Z")

</div>

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