Reindex API changed _version of docs

Dears,

Why reindex API does not copy original doc _version to new index?
Is there any trick to force it?

query:

GET test/_search?version=true
{
"query": {
  "match_all": {}
  }
}

result:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "2",
        "_version" : 1,
        "_score" : 1.0,
        "_source" : {
          "counter" : 1,
          "title" : "Allo",
          "tags" : [
            "green"
          ]
        }
      },
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "1",
        "_version" : 2,
        "_score" : 1.0,
        "_source" : {
          "counter" : 2,
          "title" : "Hey",
          "tags" : [
            "red"
          ]
        }
      }
    ]
  }
}

reidnex test index to new index test_ds:

POST _reindex
{
  "source": {
    "index": "test"
  },
  "dest": {
    "index": "test_ds1"
  }
}

query new index:

POST _reindex
{
  "source": {
    "index": "test"
  },
  "dest": {
    "index": "test_ds1"
  }
}

and result:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test_ds1",
        "_type" : "_doc",
        "_id" : "2",
        "_version" : 1,
        "_score" : 1.0,
        "_source" : {
          "counter" : 1,
          "title" : "Allo",
          "tags" : [
            "green"
          ]
        }
      },
      {
        "_index" : "test_ds1",
        "_type" : "_doc",
        "_id" : "1",
        "_version" : 1,
        "_score" : 1.0,
        "_source" : {
          "counter" : 2,
          "title" : "Hey",
          "tags" : [
            "red"
          ]
        }
      }
    ]
  }
}

The _version of docs was changed.

Best Regards,
Dan

I believe you can set version_type: external on the dest request. External isn't a great word for this, but it's the word you use when sending an index request. It says "I'm giving you the version, only perform the change if the index I give is more than your previous version".

1 Like

@nik9000
It's working, thanks a lot.

Regards,
Dan

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