根映射定义具有不受支持的参数问题

时间:2020-04-07 13:53:59

标签: elasticsearch-mapping elasticsearch-7

我正在发布到我几乎创建的Elasticsearch服务,但是无法发布映射。我无法确定哪个部分不受支持。有什么建议吗?

{
    "mappings": {
        "employees": {
            "properties": {
                "FirstName": {
                    "type": "text"
                },
                "LastName": {
                    "type": "text"
                },
                "Designation": {
                    "type": "text"
                },
                "Salary": {
                    "type": "integer"
                },
                "DateOfJoining": {
                    "type": "date",
                    "format": "yyyy-MM-dd"
                },
                "Address": {
                    "type": "text"
                },
                "Gender": {
                    "type": "text"
                },
                "Age": {
                    "type": "integer"
                },
                "MaritalStatus": {
                    "type": "text"
                },
                "Interests": {
                    "type": "text"
                }
            }
        }
    }
}

我一直收到此错误。

{
    "error": {
        "root_cause": [
            {
                "type": "mapper_parsing_exception",
                "reason": "Root mapping definition has unsupported parameters:  [employees : {properties={Designation={type=text}, Salary={type=integer}, MaritalStatus={type=text}, DateOfJoining={format=yyyy-MM-dd, type=date}, Address={type=text}, FirstName={type=text}, LastName={type=text}, Gender={type=text}, Age={type=integer}, Interests={type=text}}}]"
            }

使用版本7.6.2

2 个答案:

答案 0 :(得分:2)

由于您没有指定您的Elasticsearch版本,我也在评论中问到了

我有多个版本的Elasticsearch,当您使用text时,我以Elasticsearch 7开头,同时您在映射中还指定了employees,这通常是因为定义了在较早的版本中,其中定义了类型。

有关更多信息,请参见removal of types official doc,但不会在即将发布的主要版本8.X中将其完全删除

我能够使用Elasticsearch 7.6重现该问题,并得到相同的错误:

 "error": {
        "root_cause": [
            {
                "type": "mapper_parsing_exception",
                "reason": "Root mapping definition has unsupported parameters:  [employees : {properties={Designation={type=text}, Salary={type=integer}, MaritalStatus={type=text}, DateOfJoining={format=yyyy-MM-dd, type=date}, Address={type=text}, FirstName={type=text}, LastName={type=text}, Gender={type=text}, Age={type=integer}, Interests={type=text}}}]"
            }
        ],
        "type": "mapper_parsing_exception",
        "reason": "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [employees : {properties={Designation={type=text}, Salary={type=integer}, MaritalStatus={type=text}, DateOfJoining={format=yyyy-MM-dd, type=date}, Address={type=text}, FirstName={type=text}, LastName={type=text}, Gender={type=text}, Age={type=integer}, Interests={type=text}}}]",
        "caused_by": {
            "type": "mapper_parsing_exception",
            "reason": "Root mapping definition has unsupported parameters:  [employees : {properties={Designation={type=text}, Salary={type=integer}, MaritalStatus={type=text}, DateOfJoining={format=yyyy-MM-dd, type=date}, Address={type=text}, FirstName={type=text}, LastName={type=text}, Gender={type=text}, Age={type=integer}, Interests={type=text}}}]"
        }
    },
    "status": 400
}

解决方案

只需从employee中删除mapping并使用下面的映射。

{
    "mappings": {
        "properties": { --> note `employees` removed.
            "FirstName": {
                "type": "text"
            },
            "LastName": {
                "type": "text"
            },
            "Designation": {
                "type": "text"
            },
            "Salary": {
                "type": "integer"
            },
            "DateOfJoining": {
                "type": "date",
                "format": "yyyy-MM-dd"
            },
            "Address": {
                "type": "text"
            },
            "Gender": {
                "type": "text"
            },
            "Age": {
                "type": "integer"
            },
            "MaritalStatus": {
                "type": "text"
            },
            "Interests": {
                "type": "text"
            }
        }
    }
}

成功创建索引

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "mustnot"
}

答案 1 :(得分:0)

您似乎正在使用Elasticsearch的7.x版本,该版本已doesn't support mapping types。您只需要删除employees,就像这样:

{
  "mappings": {
    "properties": {
      "FirstName": {
        "type": "text"
      },
      "LastName": {
        "type": "text"
      },
      "Designation": {
        "type": "text"
      },
      "Salary": {
        "type": "integer"
      },
      "DateOfJoining": {
        "type": "date",
        "format": "yyyy-MM-dd"
      },
      "Address": {
        "type": "text"
      },
      "Gender": {
        "type": "text"
      },
      "Age": {
        "type": "integer"
      },
      "MaritalStatus": {
        "type": "text"
      },
      "Interests": {
        "type": "text"
      }
    }
  }
}