# Field collapsing on alias fields?

**URL:** <https://discuss.elastic.co/t/field-collapsing-on-alias-fields/211589>\
**Category:** Elasticsearch\
**Created:** [December 12, 2019, 8:10am UTC](https://discuss.elastic.co/t/field-collapsing-on-alias-fields/211589 "2019-12-12T08:10:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 12, 2019, 8:10am UTC](https://discuss.elastic.co/t/field-collapsing-on-alias-fields/211589/1 "2019-12-12T08:10:28Z")

</div>

I'm trying to collapse on a field name `field1` across different indexes. All indexes but one have the same field name `field1` and one index has a different field name `field2`. So, in that index, I'm defining an alias field `field1` which points to `field2`. My hope is to be able to collapse on `field1` across all indexes, but apparently this doesn't work.

Here is how to simply reproduce the problem I'm facing. First, we create two indexes:

```
PUT index1
{
  "settings": {
    "index.number_of_shards": 1
  }, 
  "mappings": {
    "properties": {
      "field1": {
        "type": "keyword"
      }
    }
  }
}

PUT index2
{
  "settings": {
    "index.number_of_shards": 1
  }, 
  "mappings": {
    "properties": {
      "field2": {
        "type": "keyword"
      },
      "field1": {
        "type": "alias",
        "path": "field2"
      }
    }
  }
}

```

Then we index one document in each index

```
PUT index1/_doc/1
{
  "field1": "test1"
}
PUT index2/_doc/1
{
  "field2": "test2"
}

```

And finally I'm trying to collapse on the "common" field

```
POST index*/_search 
{
  "collapse": {
    "field": "field1",
    "inner_hits": {
      "name": "hits"
    }
  }
}

```

And I get this:

```
{
  "error": {
    "root_cause": [],
    "type": "search_phase_execution_exception",
    "reason": "",
    "phase": "fetch",
    "grouped": true,
    "failed_shards": [],
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "collapse field differ across shards [field1] != [field2]"
    }
  },
  "status": 400
}

```

I could not find anything in the documentation or in Github issues that would explain this.

Given [this PR](https://github.com/elastic/elasticsearch/pull/32648), one would think that this is indeed possible, but apparently I'm missing something.

I'd appreciate if anyone could shed some light on this.  
Thank you so much!

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 12, 2019, 8:55am UTC](https://discuss.elastic.co/t/field-collapsing-on-alias-fields/211589/2 "2019-12-12T08:55:21Z")

</div>

the PR you referred to adds a test that only test field aliases within a single index and if those a properly resolved. Your use-case is a little bit different and thus the error occurs (field names differ after the resolving the field names).

Can you open an issue in the elasticsearch repo to figure out if this is a bug or at least needs an update in the docs to properly mention it.

Thanks!

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 12, 2019, 9:07am UTC](https://discuss.elastic.co/t/field-collapsing-on-alias-fields/211589/3 "2019-12-12T09:07:54Z")

</div>

Thank you so much Alex!  
Here it is: [https://github.com/elastic/elasticsearch/issues/50121](https://github.com/elastic/elasticsearch/issues/50121)

It's been confirmed it is indeed a bug.

---

<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:** [January 9, 2020, 9:07am UTC](https://discuss.elastic.co/t/field-collapsing-on-alias-fields/211589/4 "2020-01-09T09:07:56Z")

</div>

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