# Changing the \_type of all entries

**URL:** <https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669>\
**Category:** Elasticsearch\
**Created:** [October 29, 2017, 5:05pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669 "2017-10-29T17:05:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChaosMTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chaosmta/32/23372_2.png) [@ChaosMTA](https://discuss.elastic.co/u/ChaosMTA)\
**Post date:** [October 29, 2017, 5:05pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/1 "2017-10-29T17:05:55Z")

</div>

Hey guys,

Would really appreciate if someone could tell me how I can change all of my \_type entries in a index to be the same.

Right now some are 'log' and some are 'doc' when really they should all be doc.  
I hear that reindexing would work however I want to keep the index name, furthermore doesn't reindexing cause issues with mapping? Since I want the mapping to remain the same.

The only reason this is needed, is because Elastic's python API seems to limit search queries based on the \_type which is causing major headache. I'd like to keep all \_type's the same otherwise not all the entries get returned. More info here: [https://github.com/elastic/elasticsearch-dsl-py/issues/761#issuecomment-340278067](https://github.com/elastic/elasticsearch-dsl-py/issues/761#issuecomment-340278067)

Thank you.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 29, 2017, 7:56pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/2 "2017-10-29T19:56:59Z")

</div>

You need to reindex. If you do that into the same index it will not change the mapping, because it will use the existing template.

You will have to run a delete by query after you are done, to remove the documents with the old type.

---

<div class="post-metadata">

**Author:** ![ChaosMTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chaosmta/32/23372_2.png) [@ChaosMTA](https://discuss.elastic.co/u/ChaosMTA)\
**Post date:** [October 29, 2017, 8:46pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/3 "2017-10-29T20:46:12Z")

</div>

To do so I am trying to reindex like so. I have setup the mapping for the new index.  
However I keep getting the error  
`{ "error" : { "root_cause" : [{ "type" : "null_pointer_exception", "reason" : "Can't reindex without a destination type!" }], "type" : "null_pointer_exception", "reason" : "Can't reindex without a destination type!" }, "status" : 500 }`

This is my query:

```auto
curl -XPOST -d '{
  "source": {
    "index": "logs",
    "type": ["log", "doc"]
  },
  "dest": {
    "index": "new_logs",
    "type": "doc"
  },
  "script": {
    "source": "ctx._type = 'doc';"
  }
}' 'localhost:9200/_reindex?pretty'

```

This should take `log` and `doc` types and add them to the new index all under the `doc` type. However I can't see to solve the error I keep getting about how the destination needs a type. I thought I specified that properly?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 29, 2017, 8:49pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/4 "2017-10-29T20:49:45Z")

</div>

Why not just reindex the current `log` types to be `doc` and in the existing index? They won't conflict and you reduce your reindex load by half (of the types).

---

<div class="post-metadata">

**Author:** ![ChaosMTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chaosmta/32/23372_2.png) [@ChaosMTA](https://discuss.elastic.co/u/ChaosMTA)\
**Post date:** [October 29, 2017, 8:53pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/5 "2017-10-29T20:53:15Z")

</div>

I'm confused I thought you just said that wasn't possible to reindex in an existing index? How could I change all the log types to doc then?

And thanks for taking the time to help me out Mark, I appreciate it

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 29, 2017, 9:04pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/6 "2017-10-29T21:04:30Z")

</div>

> [@ChaosMTA](#):
>
> I'm confused I thought you just said that wasn't possible to reindex in an existing index?

Nope?

> [@ChaosMTA](#):
>
> How could I change all the log types to doc then?

Something like what you have, eg;

```auto
curl -XPOST -d '{
  "source": {
    "index": "logs",
    "type": "log"
  },
  "dest": {
    "index": "logs",
    "type": "doc"
  },
  "script": {
    "source": "ctx._type = 'doc';"
  }
}' 'localhost:9200/_reindex?pretty'

```

---

<div class="post-metadata">

**Author:** ![ChaosMTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chaosmta/32/23372_2.png) [@ChaosMTA](https://discuss.elastic.co/u/ChaosMTA)\
**Post date:** [October 29, 2017, 9:07pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/7 "2017-10-29T21:07:30Z")

</div>

Haha this is why I was getting confused about your replies, because `_reindex` does not allow source and dest to be the same.

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "action_request_validation_exception",
        "reason" : "Validation Failed: 1: reindex cannot write into an index its reading from [logs];"
      }
    ],
    "type" : "action_request_validation_exception",
    "reason" : "Validation Failed: 1: reindex cannot write into an index its reading from [logs];"
  },
  "status" : 400
}

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 29, 2017, 9:09pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/8 "2017-10-29T21:09:19Z")

</div>

Oh, my mistake then ☹

---

<div class="post-metadata">

**Author:** ![ChaosMTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chaosmta/32/23372_2.png) [@ChaosMTA](https://discuss.elastic.co/u/ChaosMTA)\
**Post date:** [October 29, 2017, 9:10pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/9 "2017-10-29T21:10:28Z")

</div>

Solved thanks 🙂

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 29, 2017, 11:32pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/10 "2017-10-29T23:32:08Z")

</div>

How'd you end up solving it? It might be useful for others in future 🙂

---

<div class="post-metadata">

**Author:** ![ChaosMTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chaosmta/32/23372_2.png) [@ChaosMTA](https://discuss.elastic.co/u/ChaosMTA)\
**Post date:** [October 29, 2017, 11:44pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/11 "2017-10-29T23:44:35Z")

</div>

Removing the script completely, specifying the type to import to fixed the issue in the new index! It combined the `log` and `doc` types from the `logs` index into `new_logs`.

```auto
curl -XPOST -d '{
  "source": {
    "index": "logs",
  },
  "dest": {
    "index": "new_logs",
    "type": "doc"
  }
}' 'localhost:9200/_reindex?pretty'

```

---

<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:** [November 26, 2017, 11:44pm UTC](https://discuss.elastic.co/t/changing-the-type-of-all-entries/105669/12 "2017-11-26T23:44:40Z")

</div>

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