9

I am a newbie of elasticsearch. I create a mapping using such code:

PUT /my-demo1
{
  "mappings": {
    "properties": {
      "dsu_sn": {
        "type": "keyword"
      },
      "iot_id": {
        "type": "keyword"
      },
      "test_suite_id": {
        "type": "text"
      },
      "error_code": {
        "type": "long"
      }
    }
  }
}

ES responses mapper [iot_id] cannot be changed from type [keyword] to [text] when I index a document using such code:

POST /my-demo1/1
{
  "dsu_sn": "ssl123321",
  "iot_id": "550068573720395776",
  "test_suite_id": "com.example.test.wifi",
  "error_code": 2
}
Amit
  • 30,756
  • 6
  • 57
  • 88
Vin Qin
  • 129
  • 1
  • 1
  • 8

2 Answers2

19

You need to add _doc in URL while posting a document to Elasticsearch, change the URL to POST /my-demo1/_doc/1

Refer removal of types for more info.

Amit
  • 30,756
  • 6
  • 57
  • 88
  • 2
    Yes, it works. Thanks. But the error response confuses me a lot :) – Vin Qin Nov 27 '20 at 02:47
  • 1
    Thanks for this! I was using logstash 6.x with elasticsearch 7.x in conjunction with explicit mapping templates. So I got a related error "Cannot update parameter [norms] from [false] to [true]" After simply adding the below to my elasticsearch output within logstash, these errors went away: document_type => "_doc" – Chris Jun 23 '21 at 21:52
1

I got this error becuase of a missing index alias. I deleted the index, set up the new mapping and settings, but forgot to set the alias. Then I tried to post documents to the alias...

orszaczky
  • 13,301
  • 8
  • 47
  • 54
  • Yes, just came across this. Elasticsearch created a new index, without a mapping (was expecting the alias to point it at an index with mapping) with the name of the alias. – Joe May 25 '22 at 14:29