4

我正在发布到我几乎创建的 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

4

2 回答 2

5

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

我有多个版本的 Elasticsearch,当您使用text时,我从Elasticsearch 7as 开始,您还在employees映射中指定,这造成了怀疑,因为这通常在定义类型的旧版本中定义。

请参阅删除类型官方文档以获取更多信息,并且不会在即将到来的 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"
}
于 2020-04-07T14:01:47.610 回答
1

您似乎使用的是 Elasticsearch 7.x 版,它不再支持映射类型。您只需要删除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"
      }
    }
  }
}
于 2020-04-07T13:56:32.847 回答