How to remove a field from document?

Hello,
I am new to the forum so hi. I have the old _type field from previous elasticsearch versions in all my documents and want it removed from my documents. How can I do this?

Document:

"_index": "new-index",
"_type": "_doc",
"_id": "VB1pTXMBOl0fwoYtvNZ0",
"_score": 1,
"_source": {
    "result": "P",
    ......

Thanks Jake!

if _type is part of _source then you can use _update_by_query

POST new-index/_update_by_query?wait_for_completion=false&conflicts=proceed
{
  "script": "ctx._source.remove('_type')",
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "_type"
          }
        }
      ]
    }
  }
}

Hi, thanks for the answer.
Did what you said but the _type is still in the index.


Result:

{
    "task": "3fZNyFX-QlqmqzziGGcvCg:4777538"
}

Checking for tasks with /tasks tells me that no such task is active.
Searching the index with idexName/_search tells me that all the documents still have the _type field:

Any other ideas? Thanks for your time.

Yes the field _type is part of the metadata is will be there with default value "_doc"
befre es 6, it was possible to define multiple _type as part of the index mapping ....
And that was my reflex is that you still have a field _type under the _source part of the doc

...

So is it fine that the field type is still there? I heard that it wont be supported later on so I want to get rid of it to not run into issues with next versions.

It's ok, there is a default value _doc
All your documents are accessible from the endpoint _doc (so _doc is an endpoint now and no a type)

Example you can get a doc like this GET new-index/_doc/doc_id ...

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