# Elasticsearch API throws search\_phase\_execution\_exception error

**URL:** <https://discuss.elastic.co/t/elasticsearch-api-throws-search-phase-execution-exception-error/301495>\
**Category:** Elasticsearch\
**Created:** [April 4, 2022, 10:42am UTC](https://discuss.elastic.co/t/elasticsearch-api-throws-search-phase-execution-exception-error/301495 "2022-04-04T10:42:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![itsakiridisfs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itsakiridisfs/32/103909_2.png) [@itsakiridisfs](https://discuss.elastic.co/u/itsakiridisfs)\
**Post date:** [April 4, 2022, 10:42am UTC](https://discuss.elastic.co/t/elasticsearch-api-throws-search-phase-execution-exception-error/301495/1 "2022-04-04T10:42:52Z")

</div>

Hello, we are using the Elasticsearch API, to do an aggregation with two fields and we get the following error: `Merging/Reducing the multi_term aggregations failed when computing the aggregation GroupByLevel & GroupByProcessId because the field in the position 2 in the aggregation has two different types in two different indices`.

We are aggregating the `level.keyword` and the `processId` fields which are treated as `keyword` and `long` respectively and are both marked as aggregatable (checked the indexed fields from Kibana). This used to work some time ago, when the `level.keyword` field was treated as `string`, possibly due to invalid formatting/test logs, but after installing on a blank environment and creating new logs it threw the above error.

The request we send to the Elasticsearch API:

```auto
{
    "aggs": {
        "GroupByLevel & GroupByProcessId": {
            "aggs": {
                "GroupByLevel & GroupByProcessId": {
                    "aggs": {
                        "AvgProcessMemoryInMB": {
                            "aggs": {
                                "AvgProcessMemoryInMB": {
                                    "avg": {
                                        "field": "processMemoryInMB"
                                    }
                                }
                            },
                            "filter": {
                                "match_all": {}
                            }
                        }
                    },
                    "multi_terms": {
                        "terms": [
                            {
                                "field": "level.keyword"
                            },
                            {
                                "field": "processId"
                            }
                        ]
                    }
                }
            },
            "filter": {
                "match_all": {}
            },
            "meta": {
                "0": "level.keyword",
                "1": "processId"
            }
        }
    }
}

```

Elasticsearch version: 7.14.0  
Logstash version: 7.14.0  
Kibana version: 7.14.0

---

<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 2, 2022, 10:43am UTC](https://discuss.elastic.co/t/elasticsearch-api-throws-search-phase-execution-exception-error/301495/2 "2022-05-02T10:43:09Z")

</div>

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