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

version : 7.6.2

we search the docs:

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)

"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:

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

the resp body is

{"_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

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

the response body is

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

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.

@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:

    "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

That is true. Did not spot that.

@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

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

{
  "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

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

then we can find this doc without routing

{"_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

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.

@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)

That I can not explain.

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