# Possible bug with sorting dynamically mapped fields

**URL:** <https://discuss.elastic.co/t/possible-bug-with-sorting-dynamically-mapped-fields/349149>\
**Category:** Elasticsearch\
**Created:** [December 12, 2023, 1:05pm UTC](https://discuss.elastic.co/t/possible-bug-with-sorting-dynamically-mapped-fields/349149 "2023-12-12T13:05:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evgeni\_Dzhelyov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/evgeni_dzhelyov/32/56047_2.png) [@Evgeni\_Dzhelyov](https://discuss.elastic.co/u/Evgeni_Dzhelyov)\
**Post date:** [December 12, 2023, 1:05pm UTC](https://discuss.elastic.co/t/possible-bug-with-sorting-dynamically-mapped-fields/349149/1 "2023-12-12T13:05:01Z")

</div>

We ingest a lot of custom logs in Elasticsearch. For the application logs we use a custom schema with dynamic mappings, but when sorting for some of the fields we hit a strange bug:

1. Sort by a `dext.duration#double` field which is mapped to `double` by a dynamic mapping:

```auto
    {
      "double": {
        "path_match": "dext.*#double",
        "mapping": {
          "type": "double"
        }
      }
    },

```

- And we get a `Can't sort on field [__anonymous_]; the field has incompatible sort types: [DOUBLE] and [LONG] across shards!`. It reports as `__anonymous_`.

 ![Screenshot 2023-12-12 at 11.43.32](https://us1.discourse-cdn.com/elastic/original/3X/3/9/396b4da1bfe9e48eaa6ac73045ce7d223664aa60.png)

- If I add a filter for `dext.duration#double exists`, see the screenshot, it returns results:

 ![Screenshot 2023-12-12 at 11.47.01](https://us1.discourse-cdn.com/elastic/original/3X/7/4/7457fbabd236d8ccaeb093a7360df42dd2bd9665.jpeg)

- I don't have documents where the field doesn't exist, so it's very strange behavior.

 ![Screenshot 2023-12-12 at 11.50.58](https://us1.discourse-cdn.com/elastic/original/3X/4/f/4f0541b172dd8184c863a76b95489806d0ed9472.png)

Can you advise what is the possible cause?  
I can provide more debug information if needed, if you can guide me on how to debug it.

---

<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, 2024, 1:05pm UTC](https://discuss.elastic.co/t/possible-bug-with-sorting-dynamically-mapped-fields/349149/2 "2024-01-09T13:05:20Z")

</div>

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