在我的索引"process“中,我有一个类型为"logs”。对于这种类型,我有这样的映射:
{
"process": {
"mappings": {
"logs": {
"properties": {
"channel": {
"type": "string"
},
"context": {
"type": "object"
},
"datetime": {
"type": "date",
"format": "dateOptionalTime"
},
"extra": {
"type": "object"
"level": {
"type": "long"
},
"level_name": {
"type": "string"
},
"message": {
"type": "string"
}
}
}
}
}
}问题是,“上下文”属性和“额外”属性是动态字段,每个文档可以有不同数量的具有不同名称的附加&上下文子元素。当我设置这个映射,然后检查http://localhost:9200/process/_mapping/logs时,我看到了这个映射。所以起作用了。另外,这个设置的答案是{acknowledge: true}。到目前一切尚好。
然后,我添加几个文档,或者至少我尝试一下。第一个文档更改ES映射!
新的制图是:
{
"process" : {
"mappings" : {
"logs" : {
"properties" : {
"channel" : {
"type" : "string"
},
"context" : {
"properties" : {
"columns" : {
"type" : "string"
},
"count" : {
"type" : "long"
},
"errorMessage" : {
"type" : "string"
},
"serviice" : {
"type" : "string"
}
}
},
"datetime" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"extra" : {
"properties" : {
"uid" : {
"type" : "string"
}
}
},
"level" : {
"type" : "long"
},
"level_name" : {
"type" : "string"
},
"message" : {
"type" : "string"
}
}
}
}
}
}当我尝试添加一个新文档时,它不匹配这个新映射并触发此错误:
MapperParsingException[object mapping [context] trying to serialize a value with no field associated with it, current value [pid]]所以我显然遗漏了一些东西。
编辑:插入并似乎更新映射的文档:
{
"message": "Starting background process `{service}`, registered under the ID ",
"context": {
"id": null,
"serviice": "fiduceo.import"
},
"level": 250,
"level_name": "NOTICE",
"channel": "process",
"datetime": "2016-06-09T11:23:42.304859+02:00",
"extra": {
"uid": "d1cb925"
}
}而失败的人:
{
"message": "Background process created (pid: {pid})",
"context": [
"pid",
18871
],
"level": 250,
"level_name": "NOTICE",
"channel": "process",
"datetime": "2016-06-09T11:23:41.519456+02:00",
"extra": {
"uid": "09fe183"
}
}发布于 2016-06-09 10:18:13
上下文字段包含无效的JSON
它应该是这样的:
"context": {
"pid": 18871
},与您的版本相比:
"context": [
"pid",
18871
]编辑:为了给出完整的答案(并重复注释中所写的内容):
https://stackoverflow.com/questions/37721278
复制相似问题