# Routing bug: no routing document get doc id not found, while set specific routing param found the docs

**URL:** <https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714>\
**Category:** Elasticsearch\
**Created:** [August 28, 2020, 5:05am UTC](https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714 "2020-08-28T05:05:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hackerwin7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hackerwin7/32/43223_2.png) [@hackerwin7](https://discuss.elastic.co/u/hackerwin7)\
**Post date:** [August 28, 2020, 5:05am UTC](https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714/1 "2020-08-28T05:05:22Z")

</div>

version : 7.6.2

we search the docs:

```auto
curl xxx.xxx.xxx.xx:9200/index-1/_search?pretty -H'Content-type: application/json' -d'
{
  "query": {
    "terms": {
        "field-1": ["xxxxxxx"]
    }
  }
}
'

```

the response body looks like: (there is no \_routing field and value)

```auto
"hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "index-1",
        "_type" : "_doc",
        "_id" : "OL6tLXQB7k8FSPLGd-TD",
        "_score" : 1.0,
        "_source" : {
          "field-1" : xxxxxxxxx,

```

while i use get doc by id:

```auto
curl xxx.xxx.xxx.xxx:9200/index-1/_doc/OL6tLXQB7k8FSPLGd-TD

```

the resp body is

```auto
{"_index":"index-1","_type":"_doc","_id":"OL6tLXQB7k8FSPLGd-TD","found":false}

```

it is very strange that I add a routing parameter with a value (I test a wild range of number of routing value) , and the get doc by id is founded

```auto
curl xxx.xxx.xxx.xxx:9200/index-1/_doc/OL6tLXQB7k8FSPLGd-TD?routing=568

```

the response body is

```auto
{"_index":"index-1","_type":"_doc","_id":"OL6tLXQB7k8FSPLGd-TD","_version":1,"_seq_no":18073027,"_primary_term":1,"found":true,"_source": ....

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 28, 2020, 6:18am UTC](https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714/2 "2020-08-28T06:18:46Z")

</div>

What you are describing seems to be the expected behaviour. It sounds like this document has been indexed with a routing key. When you specify a routing key this is used to determine which shard to send the document to. If you do not specify a routing value the document id is instead used. The search targets all shards so finds the document but when you get by id only a single shard is queried. Since the routing parameter and the document id point to different shards the document is not found by the get request.

---

<div class="post-metadata">

**Author:** ![hackerwin7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hackerwin7/32/43223_2.png) [@hackerwin7](https://discuss.elastic.co/u/hackerwin7)\
**Post date:** [August 28, 2020, 6:52am UTC](https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714/3 "2020-08-28T06:52:44Z")

</div>

@Christian_Dahlqvist

Thanks for reply, I test that if I index with a routing key, then the hits would have `_routing` filed，just like this:

```auto
    "hits" : [
      {
        "_index" : "index-1",
        "_type" : "_doc",
        "_id" : "xxxxxxx",
        "_routing": "${indexed routing value}"
        "_score" : 1.0,
        "_source" : {
          "field-1" : xxxxxxxxx,

```

however I get this docs don't have `_routing` field but need specify a `routing` parameter in get:

so lets summary the case:

- search with query without routing parameter we found it
- get with same doc id we don't find it
- get with doc id with routing parameter we found it
- this doc dose not have `_routing` field in return hits

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 28, 2020, 7:13am UTC](https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714/4 "2020-08-28T07:13:13Z")

</div>

That is true. Did not spot that.

---

<div class="post-metadata">

**Author:** ![hackerwin7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hackerwin7/32/43223_2.png) [@hackerwin7](https://discuss.elastic.co/u/hackerwin7)\
**Post date:** [August 28, 2020, 7:33am UTC](https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714/5 "2020-08-28T07:33:10Z")

</div>

@Christian_Dahlqvist

I retest in my local environment in ES-7.6.2:  
we index first 3 docs with routing and fourth doc without routing, like this

```auto
curl "127.0.0.1:9200/test1/_doc?routing=t1" -XPOST -H'Content-type: application/json' -d'{"test": "test1-1"}'
curl "127.0.0.1:9200/test1/_doc?routing=t2" -XPOST -H'Content-type: application/json' -d'{"test": "test1-2"}'
curl "127.0.0.1:9200/test1/_doc?routing=t3" -XPOST -H'Content-type: application/json' -d'{"test": "test1-3"}'
curl "127.0.0.1:9200/test1/_doc" -XPOST -H'Content-type: application/json' -d'{"test": "test1-4"}'

```

then we call search on this index, the hits are

```auto
{
  "took" : 85,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 4,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test1",
        "_type" : "_doc",
        "_id" : "vqz2M3QBCKLI3zykHsUd",
        "_score" : 1.0,
        "_routing" : "t1",
        "_source" : {
          "test" : "test1-1"
        }
      },
      {
        "_index" : "test1",
        "_type" : "_doc",
        "_id" : "v6z2M3QBCKLI3zykNMXU",
        "_score" : 1.0,
        "_routing" : "t2",
        "_source" : {
          "test" : "test1-2"
        }
      },
      {
        "_index" : "test1",
        "_type" : "_doc",
        "_id" : "wKz2M3QBCKLI3zykR8Xv",
        "_score" : 1.0,
        "_routing" : "t3",
        "_source" : {
          "test" : "test1-3"
        }
      },
      {
        "_index" : "test1",
        "_type" : "_doc",
        "_id" : "waz2M3QBCKLI3zykbMWk",
        "_score" : 1.0,
        "_source" : {
          "test" : "test1-4"
        }
      }
    ]
  }
}

```

we cloud see the fourth doc don't have `_routing` field.

and we call GET API to get fourth doc

```auto
curl "127.0.0.1:9200/test1/_doc/waz2M3QBCKLI3zykbMWk"

```

then we can find this doc without routing

```auto
{"_index":"test1","_type":"_doc","_id":"waz2M3QBCKLI3zykbMWk","_version":1,"_seq_no":3,"_primary_term":1,"found":true,"_source":{"test": "test1-4"}}

```

this is confusion with my production environment. just explain above, the doc don't have `_routing` field , but need GET API with routing to get the doc

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 28, 2020, 7:46am UTC](https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714/6 "2020-08-28T07:46:47Z")

</div>

If you index a document with routing parameter you also need to specify the routing parameter when using the GET api. For the fourth document you can use the GET api without routing as it was indexed with no routing parameter specified.

Retrieving any of the first three documents based on id without specifying the routing value may fail.

---

<div class="post-metadata">

**Author:** ![hackerwin7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hackerwin7/32/43223_2.png) [@hackerwin7](https://discuss.elastic.co/u/hackerwin7)\
**Post date:** [August 28, 2020, 10:09am UTC](https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714/7 "2020-08-28T10:09:36Z")

</div>

@Christian_Dahlqvist  
Yes, this is true.

But my question is , In my production environment:  
there is a doc indexed without routing parameter (because I can search it without routing and the doc don't have `_routing` meta field), however I can not use GET by \_id to get the doc, besides I can use GET with routing parameter to get the doc.

this is very confused that a indexed without routing doc require GET API with routing to get the doc. (we can SEARCH it but GET is failed except you add a routing with you GET)

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 28, 2020, 10:35am UTC](https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714/8 "2020-08-28T10:35:21Z")

</div>

That I can not explain.

---

<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 25, 2020, 10:35am UTC](https://discuss.elastic.co/t/routing-bug-no-routing-document-get-doc-id-not-found-while-set-specific-routing-param-found-the-docs/246714/9 "2020-09-25T10:35:21Z")

</div>

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