본문 바로가기

developer/ElasticSearch

"Root mapping definition has unsupported parameters: [docs : {properties={chinese_field={analyzer=smartcn, type=text}...

ElasticSearch 7부터 Type이 사라졌기 때문에 이를 Kibana에서 이를 실행시키면

PUT /test3
{
  "mappings": {
    "docs": {
      "properties": {
        "body": {
          "type": "text"
        },
        "english_field": {
          "type": "text"
        },
        "korean_field": {
          "analyzer": "nori",
          "type": "text"
        },
        "japanese_field": {
          "analyzer": "kuromoji",
          "type": "text"
        },
        "chinese_field": {
          "analyzer": "smartcn",
          "type": "text"
        }
      }
    }
  }
}

아래의 오류가 발생한다.

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Root mapping definition has unsupported parameters:  [docs : {properties={chinese_field={analyzer=smartcn, type=text}, korean_field={analyzer=nori, type=text}, english_field={type=text}, body={type=text}, japanese_field={analyzer=kuromoji, type=text}}}]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [docs : {properties={chinese_field={analyzer=smartcn, type=text}, korean_field={analyzer=nori, type=text}, english_field={type=text}, body={type=text}, japanese_field={analyzer=kuromoji, type=text}}}]",
    "caused_by" : {
      "type" : "mapper_parsing_exception",
      "reason" : "Root mapping definition has unsupported parameters:  [docs : {properties={chinese_field={analyzer=smartcn, type=text}, korean_field={analyzer=nori, type=text}, english_field={type=text}, body={type=text}, japanese_field={analyzer=kuromoji, type=text}}}]"
    }
  },
  "status" : 400
}

따라서 이렇게 바꿔주어야 한다.

PUT /test3
{
  "mappings": {
      "properties": {
        "body": {
          "type": "text"
        },
        "english_field": {
          "type": "text"
        },
        "korean_field": {
          "analyzer": "nori",
          "type": "text"
        },
        "japanese_field": {
          "analyzer": "kuromoji",
          "type": "text"
        },
        "chinese_field": {
          "analyzer": "smartcn",
          "type": "text"
        }
      }
  }
}

 

* 그렇다면 ElasticSearch는 왜 Type을 삭제했을까? Type이란 원래 무엇이었을까?

- What are mapping types?
A mapping type was used to represent the type of document or entity being indexed, for instance a twitter index might have a user type and a tweet type.

Each mapping type could have its own fields, so the user type might have a full_name field, a user_name field, and an email field, while the tweet type could have a content field, a tweeted_at field and, like the user type, a user_name field.

공식 문서에 따르면, Type은 document의 type이나 entity의 유형을 나타내기 위해 사용되었었다.
각 매핑 유형마다
user tpye이 full_name / user_name / email
tweet type이 content / tweeted_at / user / user_name 
로 고유의 필드를 가질 수 있었다.

- Why are mapping types being removed?
Initially, we spoke about an “index” being similar to a “database” in an SQL database, and a “type” being equivalent to a “table”.

This was a bad analogy that led to incorrect assumptions. In an SQL database, tables are independent of each other. 

The columns in one table have no bearing on columns with the same name in another table. 

This is not the case for fields in a mapping type. 

In an Elasticsearch index, fields that have the same name in different mapping types are backed by the same Lucene field internally.

처음에는 "index"가 SQL의 데이터베이스와 유사하고 "type"이 테이블과 동등하다고 말했다.

하지만 이것을 잘못된 가정으로 인한 비유였다. SQL 데이터베이스에서 테이블들은 서로 독립적이다. 한 테이블의 열은 다른 테이블의 열과 관련이 없다. 하지만 mapping type의 필드에서는 이와 같지 않다.

Elasticsearch의 index에서는 다른 mapping type을 가진 같은 이름의 필드는 내부적으로 동일한 Lucene field에 의해 백업된다.


https://www.elastic.co/guide/en/elasticsearch/reference/7.0/removal-of-types.html#_why_are_mapping_types_being_removed