siltalau
siltalau

Reputation: 549

Elasticsearch reindex fails with _version error

I'm using Elasticsearch version 5.5.

I have my index A with mapping:

{
  "myobj": {
    "enabled": false
}

I've created index B with mapping:

{
  "myobj": {
    "_all": {"enabled": false},
    "properties": {
      "mykey": {"type": "keyword"}
    }
  }
}

When I call the reindex api with body:

{
  "source": {
    "index": "a"
  },
  "dest": {
    "index": "b"
  }
}

I get the error: Cannot generate dynamic mappings of type [_version] for [_version]

Here are the reindex request bodies I've tried:

{
  "source": {
    "index": "a"
  },
  "dest": {
    "index": "b",
    "version_type": "internal"
  }
}

==> Cannot generate dynamic mappings of type [_version] for [_version]


{
  "source": {
    "index": "a"
  },
  "dest": {
    "index": "b",
    "version_type": "external"
  }
}

==> Cannot generate dynamic mappings of type [_version] for [_version]


{
  "source": {
    "index": "a"
  },
  "dest": {
    "index": "b"
  },
    "script": {
      "inline": "ctx._version = ctx._source.remove(\"_version\")"
    }
}

==> [myobj][1]: version conflict, current version [-1] is different than the one provided [1507030478]


What am I doing wrong and how can I reindex these documents?

EDIT

I've since tried adding "conflicts": "proceed" which simply resulted in no documents being reindexed.

I also added "index.mapper.dynamic": false to the index B's settings with no observable change in the results.

Upvotes: 1

Views: 655

Answers (1)

est
est

Reputation: 11875

There are some "reserved" fields in ES you can not directly reindex, such as _id, _version or _index. (and the deprecated _type)

Try this body in your reindex to remove those reserved fields.

{
    'source': { ... },
    'dest': { ...  },
    "script": {
        'inline': 'ctx._source.remove("_id");ctx._source.remove("_version");'
    }

}

Upvotes: 0

Related Questions