【发布时间】:2019-12-02 22:28:47
【问题描述】:
我目前正在为我的工作探索 celery,并且我正在尝试设置 Elasticsearch 后端。有没有办法将结果值作为字典/JSON而不是文本发送?因此,Elasticsearch 中的结果会正确显示并且可以使用嵌套类型吗?
celery 创建的自动映射
{
"celery" : {
"mappings" : {
"backend" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},
"result" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
我尝试使用嵌套字段创建自己的映射,但结果是 elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'object mapping for [result] tried to parse field [result] as object, but found a concrete value')
更新
结果已经用 JSON 编码,并且在 Elasticsearch 包装器中 JSON 字符串保存在字典中。添加json.loads(result) 作为快速修复实际上会有所帮助。
快速修复新映射出现后:
{
"celery" : {
"mappings" : {
"backend" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},
"result" : {
"properties" : {
"date_done" : {
"type" : "date"
},
"result" : {
"type" : "long"
},
"status" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"task_id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
}
有什么方法可以在 Celery 中禁用结果序列化?
我可以添加一个带有解包 JSON 的拉取请求,仅用于 Elasticsearch,但它看起来像一个 hack。
【问题讨论】:
标签: python json elasticsearch celery