ElasticSearch POST _doc and doc issue

Hi everyone,

I through curl to POST new index with doc like

curl -XPOST -H "Content-Type: application/json" 'http://localhost:9200/portstats/doc/' -d '{"bytesReceived":0,"bytesSent":0,"@timestamp":"2022-07-10T23:43:01.637Z"}'

But I will get this error.

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [portstats] as the final mapping would have more than 1 type: [_doc, doc]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [portstats] as the final mapping would have more than 1 type: [_doc, doc]"},"status":400}%

Even if I remove the index porstats

curl -XDELETE http://127.0.0.1:9200/portstats

It's useless, when I POST again I will get the same error message.
I guess when I POST it will create type _doc automatically, but I don't know why the type isn't "doc"

Does anyone knows? Thanks.

Hi @Even_Zhang .

What is version ES you are using?

Hi @Even_Zhang Welcome to the community

If you are using Elasticsearch version 7.x+ that would be _doc not doc

http://localhost:9200/portstats/_doc/
................................^

_doc Is the only non-deprecated _type allowed

See this ... For an explanation.

Hi @stephenb,

My Elasticsearch version is 7.9

I'm going to change doc to _doc.

Because the other index can use doc, but only "portstats" can't.

That's the reason I was confusing.

Anyways, I will change the type to _doc and thank you for the speedy reply.

I fixed my previous post... an index can only have 1 _type... it looks like you set it to doc first then tried to use _doc... once you set it / use it the first time you must continue to use the same value.

Apologies I should have been more clear ... in 7.x you can only have 1 _type per index.
The correct value is _doc but you can still use other values which is highly discourage as that ability has been completely removed in 8.x where the only value _type allowed is _doc. You will not be able to migrate indices with _type set to any other value that _doc to version 8.x that is why you should do it now.

Thank you for your kind replay and advice.

I will correct the value to _doc. :+1:

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