Elasticsearch 中的嵌套类型:索引文档时 "object mapping can't be changed from nested to non-nested"
Nested type in Elasticsearch: "object mapping can't be changed from nested to non-nested" when indexing a document
我尝试将一些嵌套文档索引到如下所示的 Elasticsearch (v2.3.1) 映射中 (based on this example from the documentation):
PUT /my_index
{
"mappings": {
"blogpost": {
"properties": {
"title": { "type": "string" },
"comments": {
"type": "nested",
"properties": {
"name": { "type": "string" },
"comment": { "type": "string" }
}
}
}
}
}
}
但是,我不明白我的 JSON 文档必须是什么样子才能适应该映射。我试过
PUT /my_index/some_type/1
{
"title": "some_title",
"comments": {
"name": "some_name",
"comment": "some_comment"
}
}
以及
PUT /my_index_some_type/1
{
"title": "some_title",
"comments": [
{
"name": "some_name",
"comment": "some_comment"
}
]
}
两者都会导致
{
"error":
{
"root_cause":
[
{
"type": "remote_transport_exception",
"reason": "[Caiman][172.18.0.4:9300][indices:data/write/index[p]]"
}
],
"type": "illegal_argument_exception",
"reason": "object mapping [comments] can't be changed from nested to non-nested"
},
"status": 400
}
索引嵌套文档的正确格式是什么?非常感谢任何工作示例,SO 或其他页面上的大多数示例都集中在嵌套查询上,而不是之前如何对文档进行索引。
看来您确实在创建类型为 some_type
的文档,并且 comments
将默认为普通的 object
(即不是 nested
),这不是允许,因为您在同一索引的 blogpost
映射类型中已经有一个名为 comments
的嵌套对象。
试试这个,它应该有效:
PUT /my_index/blogpost/1
{
"title": "some_title",
"comments": {
"name": "some_name",
"comment": "some_comment"
}
}
我尝试将一些嵌套文档索引到如下所示的 Elasticsearch (v2.3.1) 映射中 (based on this example from the documentation):
PUT /my_index
{
"mappings": {
"blogpost": {
"properties": {
"title": { "type": "string" },
"comments": {
"type": "nested",
"properties": {
"name": { "type": "string" },
"comment": { "type": "string" }
}
}
}
}
}
}
但是,我不明白我的 JSON 文档必须是什么样子才能适应该映射。我试过
PUT /my_index/some_type/1
{
"title": "some_title",
"comments": {
"name": "some_name",
"comment": "some_comment"
}
}
以及
PUT /my_index_some_type/1
{
"title": "some_title",
"comments": [
{
"name": "some_name",
"comment": "some_comment"
}
]
}
两者都会导致
{
"error":
{
"root_cause":
[
{
"type": "remote_transport_exception",
"reason": "[Caiman][172.18.0.4:9300][indices:data/write/index[p]]"
}
],
"type": "illegal_argument_exception",
"reason": "object mapping [comments] can't be changed from nested to non-nested"
},
"status": 400
}
索引嵌套文档的正确格式是什么?非常感谢任何工作示例,SO 或其他页面上的大多数示例都集中在嵌套查询上,而不是之前如何对文档进行索引。
看来您确实在创建类型为 some_type
的文档,并且 comments
将默认为普通的 object
(即不是 nested
),这不是允许,因为您在同一索引的 blogpost
映射类型中已经有一个名为 comments
的嵌套对象。
试试这个,它应该有效:
PUT /my_index/blogpost/1
{
"title": "some_title",
"comments": {
"name": "some_name",
"comment": "some_comment"
}
}