# Field name collisions when sorting

**URL:** <https://discuss.elastic.co/t/field-name-collisions-when-sorting/27686>\
**Category:** Elasticsearch\
**Created:** [August 19, 2015, 3:43pm UTC](https://discuss.elastic.co/t/field-name-collisions-when-sorting/27686 "2015-08-19T15:43:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Chang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_chang/32/820_2.png) [@Daniel\_Chang](https://discuss.elastic.co/u/Daniel_Chang)\
**Post date:** [August 19, 2015, 3:43pm UTC](https://discuss.elastic.co/t/field-name-collisions-when-sorting/27686/1 "2015-08-19T15:43:15Z")

</div>

I am having a sorting issue where the documents returned are not respecting my sort criteria.  
I am using Elasticsearch version 1.4.4

I have a field **project.primary\_site** that is defined on two document types. In one (foobar-centric) project is defined as nested in the mappings, in the second one (donor-centric) project is just a regular object.

Doing a sort on donor-centric fails and it looked like the sort key is null.

```auto
{
  "sort": [
    {
      "project.primary_site": {
        "order": "asc"
      }
    }
  ]
}'

```

The gist below should illustrate this sorting problem, if I comment out the foobar-centric related curls, the sort works.

> <https://gist.github.com/mwdchang/76f6b54811b36ecf79b8>

I am wondering if I am running into the Type Gotchas documented here  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping.html#\_avoiding\_type\_gotchas](https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping.html#_avoiding_type_gotchas)

If so, is the solution to just fully qualify the field names with the document type? i.e., instead of **project.primary\_site** use **donor-centric.project.primary\_site** and **foobar-centric.project.primary\_site**?

Thanks,  
Daniel

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [August 21, 2015, 3:39pm UTC](https://discuss.elastic.co/t/field-name-collisions-when-sorting/27686/2 "2015-08-21T15:39:35Z")

</div>

Indeed this is due to your types being mapped differently. Specifying the type name might work, but it would be much better to use different field names or different indices to avoid this issue.

---

<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:** [July 5, 2017, 11:54pm UTC](https://discuss.elastic.co/t/field-name-collisions-when-sorting/27686/3 "2017-07-05T23:54:32Z")

</div>


