Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch-7.9.0 cannot be changed from type [keyword] to [text]

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
}
like image 966
Vin Qin Avatar asked Nov 27 '20 02:11

Vin Qin


People also ask

Is type deprecated in Elasticsearch?

Types are deprecated in APIs in 7.0, with breaking changes to the index creation, put mapping, get mapping, put template, get template and get field mappings APIs.

What is the difference between text and keyword in Elasticsearch?

The crucial difference between them is that Elasticsearch will analyze the Text before it's stored into the Inverted Index while it won't analyze Keyword type. Analyzed or not analyzed will affect how it will behave when getting queried.

What is doctype in Elasticsearch?

Basically, a type in Elasticsearch represented a class of similar documents and had a name such as customer or item . Lucene has no concept of document data types, so Elasticsearch would store the type name of each document in a metadata field of a document called _type.

What is keyword field in Elasticsearch?

Keyword fields in Elasticsearch are used to index and search for text values. They are also used to store metadata about the documents they are associated with.


Video Answer


2 Answers

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.

like image 56
Amit Avatar answered Oct 17 '22 14:10

Amit


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...

like image 1
orszaczky Avatar answered Oct 17 '22 14:10

orszaczky