gpt4 book ai didi

python - ElasticSearch 的 Celery 结果类型

转载 作者:太空宇宙 更新时间:2023-11-03 20:35:38 26 4
gpt4 key购买 nike

我目前正在为我的工作探索 celery,并尝试设置 Elasticsearch 后端。有没有办法将结果值作为字典/JSON而不是文本发送?因此,Elasticsearch 中的结果将正确显示并且可以使用嵌套类型吗?

enter image description here

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', '[result] 的对象映射尝试解析字段[结果] 作为对象,但找到了具体值')

更新

结果已经编码为 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
}
}
}
}
}
}
}
}
}
}

更新的 Kibana View : enter image description here

有什么方法可以禁用 Celery 中的结果序列化吗?

我可以添加一个带有解压 JSON 的拉取请求,仅适用于 Elasticsearch,但它看起来像是一个 hack。

最佳答案

自 v4.0 起,默认的 result_serializerjson,因此无论如何您都应该获得 JSON 格式的结果。也许您的配置使用了其他东西? - 在这种情况下,我建议您删除它(如果您使用 Celery >=4.0),您应该会享受 JSON 格式的结果。我更喜欢 msgpack,但另一方面,我不在 Celery 结果上使用 ElasticSearch...

关于python - ElasticSearch 的 Celery 结果类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57188494/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com