# Update-by-query: No mapping found for \[id\] in order to sort on

**URL:** https://discuss.elastic.co/t/update-by-query-no-mapping-found-for-id-in-order-to-sort-on/339671
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [July 31, 2023, 9:35am UTC](https://discuss.elastic.co/t/update-by-query-no-mapping-found-for-id-in-order-to-sort-on/339671 "2023-07-31T09:35:10Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![davysteegen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davysteegen/32/124103_2.png) [@davysteegen](https://discuss.elastic.co/u/davysteegen)
#### Post date: [July 31, 2023, 9:35am UTC](https://discuss.elastic.co/t/update-by-query-no-mapping-found-for-id-in-order-to-sort-on/339671/1 "2023-07-31T09:35:10Z")

</div>

Hi,

We are in the process of migrating from Elasticsearch 2.3 to 8.6. One thing I noticed is that the sorting in the update-by-query API now only allows to provide a comma separated list of field/sort direction combos. In the past this was an object where you could also provide an unmapped type in case not all documents in the index have the field where you want to apply the sorting on.  
We are no getting the `No mapping found for [field] in order to sort on` error when the index is empty or not all documents have the sorted field.

So my question is, is there a workaround for this issue?

---

<div class="post-metadata">

### Author: ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)
#### Post date: [July 31, 2023, 10:27am UTC](https://discuss.elastic.co/t/update-by-query-no-mapping-found-for-id-in-order-to-sort-on/339671/2 "2023-07-31T10:27:06Z")

</div>

Hi @davysteegen,

Welcome to the community! Have you tried using [the `missing_values` option](https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html#_missing_values) to see if that helps you with this error?

---

<div class="post-metadata">

### Author: ![davysteegen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davysteegen/32/124103_2.png) [@davysteegen](https://discuss.elastic.co/u/davysteegen)
#### Post date: [July 31, 2023, 12:57pm UTC](https://discuss.elastic.co/t/update-by-query-no-mapping-found-for-id-in-order-to-sort-on/339671/3 "2023-07-31T12:57:47Z")

</div>

@carly.richmond

Thank you for the feedback! I have already been looking into that as well but it turns out that the `update-by-query` API handles sorting slightly different than the normal `search` API.

When looking at the [docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html), it is stated that it should be provided with key/direction pairs (e.g: `name:asc,lastName:desc`). There does not seem to be a way to provide complex objects as the sorting is passed as a request parameter to the `update-by-query` API.

We are using the Java client library and that one only accepts a `List` of `String` for sorting.

---

<div class="post-metadata">

### Author: ![davysteegen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davysteegen/32/124103_2.png) [@davysteegen](https://discuss.elastic.co/u/davysteegen)
#### Post date: [August 10, 2023, 11:28am UTC](https://discuss.elastic.co/t/update-by-query-no-mapping-found-for-id-in-order-to-sort-on/339671/4 "2023-08-10T11:28:33Z")

</div>

@carly.richmond

Do you happen to have any update on this? 🙂

---

<div class="post-metadata">

### Author: ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)
#### Post date: [August 21, 2023, 1:00pm UTC](https://discuss.elastic.co/t/update-by-query-no-mapping-found-for-id-in-order-to-sort-on/339671/5 "2023-08-21T13:00:58Z")

</div>

Hi @davysteegen,

Sadly not I've been on vacation. Since you've using the Java client I've added the `language-clients` tag to see if that helps with a response. If I find anything else I'll let you know.

---

<div class="post-metadata">

### Author: ![davysteegen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davysteegen/32/124103_2.png) [@davysteegen](https://discuss.elastic.co/u/davysteegen)
#### Post date: [August 21, 2023, 1:17pm UTC](https://discuss.elastic.co/t/update-by-query-no-mapping-found-for-id-in-order-to-sort-on/339671/6 "2023-08-21T13:17:16Z")

</div>

Hi @carly.richmond

I just wanted to let you know that in the meantime I implemented a workaround. I first do a count on the index to see if there is at least one document before doing the actual update-by-query call. This makes sure that I never get the error regarding the unmapped field. So at least we are not blocked by this anymore 😉

---

<div class="post-metadata">

### Author: ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)
#### Post date: [August 21, 2023, 1:34pm UTC](https://discuss.elastic.co/t/update-by-query-no-mapping-found-for-id-in-order-to-sort-on/339671/7 "2023-08-21T13:34:27Z")

</div>

No worries at all @davysteegen. I'm glad you found a workaround. Thanks for sharing!

---

<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: [September 18, 2023, 1:34pm UTC](https://discuss.elastic.co/t/update-by-query-no-mapping-found-for-id-in-order-to-sort-on/339671/8 "2023-09-18T13:34:29Z")

</div>

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