# Elastic No mapping found for \[\_shard\_doc\] in order to sort on

**URL:** https://discuss.elastic.co/t/elastic-no-mapping-found-for-shard-doc-in-order-to-sort-on/268188
**Category:** Elasticsearch
**Created:** [March 24, 2021, 9:41am UTC](https://discuss.elastic.co/t/elastic-no-mapping-found-for-shard-doc-in-order-to-sort-on/268188 "2021-03-24T09:41:58Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![111452](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111452/32/79499_2.png) [@111452](https://discuss.elastic.co/u/111452)
#### Post date: [March 24, 2021, 9:41am UTC](https://discuss.elastic.co/t/elastic-no-mapping-found-for-shard-doc-in-order-to-sort-on/268188/1 "2021-03-24T09:41:58Z")

</div>

I'm trying to use search after parameter in the query to retrieve the next page as it says in [Paginate search results | Elasticsearch Reference [7.12] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html).  
If I sort it like

```auto
"sort": [ 
    {"@timestamp": "asc"},
    {"_shard_doc": "desc"}
  ]

```

it fails with No mapping found for [\_shard\_doc] in order to sort on.  
Does anyone know how to add this mapping because I haven't found any information about it? \_shard\_doc is not my own mapping, it is the one that is recommended in the manual above for PIT.

---

<div class="post-metadata">

### Author: ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)
#### Post date: [March 26, 2021, 1:32pm UTC](https://discuss.elastic.co/t/elastic-no-mapping-found-for-shard-doc-in-order-to-sort-on/268188/2 "2021-03-26T13:32:41Z")

</div>

Are you using es 7.12 version where `_shard_doc` was introduced?

The documentation you linked has information about this field:

> The `_shard_doc` value is the combination of the shard index within the PIT and the Lucene’s internal doc ID, it is unique per document and constant within a PIT.

This is an automatic tie-breaker field, and is composed of Lucene internal doc ID and a shard ID. It makes sense only for searches with PIT, as PIT represents a point of time of the index, where Lucene internal doc IDs stay constant. Thus, if you use the same PIT request multiple times, you will always get the same order of documents.

You don't need to explicitly add `_shard_doc` to `sort` with PIT search, it will be automatically added as `"_shard_doc": "asc"`. The only way, where you want to explicitly add it, if you paginate backwards (going to previous results), then as an example shows you would add `{"_shard_doc": "desc"}`.

* * *

In the past before PIT was introduced, as index was changing, the same sort request may produce different results. Also with `search_after` we could get repeated results from previous page.  
Another problem was how to tie-breaking equal values. In the past, we were using expensive ways – unique fields such as elasticsearch doc `_id`, which represented long strings that need to be loaded into memory and compared. `_shard_doc` field is a cheap way to do tie-breaking.

---

<div class="post-metadata">

### Author: ![Reginald\_Lee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reginald_lee/32/86215_2.png) [@Reginald\_Lee](https://discuss.elastic.co/u/Reginald_Lee)
#### Post date: [March 29, 2021, 3:47am UTC](https://discuss.elastic.co/t/elastic-no-mapping-found-for-shard-doc-in-order-to-sort-on/268188/3 "2021-03-29T03:47:29Z")

</div>

I've met the exact same problem ever. It's suggested that double-check the es version you are using. Since this is the new feature invited at exactly v7.12, and it doesn't exist even at v7.11.

---

<div class="post-metadata">

### Author: ![111452](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/111452/32/79499_2.png) [@111452](https://discuss.elastic.co/u/111452)
#### Post date: [March 31, 2021, 8:48am UTC](https://discuss.elastic.co/t/elastic-no-mapping-found-for-shard-doc-in-order-to-sort-on/268188/5 "2021-03-31T08:48:16Z")

</div>

Thank you! The update helped me

---

<div class="post-metadata">

### Author: ![alexsunny123](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@alexsunny123](https://discuss.elastic.co/u/alexsunny123)
#### Post date: [April 8, 2021, 2:11pm UTC](https://discuss.elastic.co/t/elastic-no-mapping-found-for-shard-doc-in-order-to-sort-on/268188/6 "2021-04-08T14:11:32Z")

</div>

> [@Reginald\_Lee](#):
>
> I've met the exact same problem ever. It's suggested that double-check the es version you are using. Since this is the new feature invited at exactly v7.12, and it doesn't exist even at v7.11.

thanks my issue has been fixed.

---

<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 6, 2021, 2:11pm UTC](https://discuss.elastic.co/t/elastic-no-mapping-found-for-shard-doc-in-order-to-sort-on/268188/7 "2021-05-06T14:11:33Z")

</div>

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