我需要保存一些数据,其中包括一个名为ID的字段,这是一个使用golang和 olivere flex 搜索包的 uuid im,这是我的代码
type Space struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
}
进行一些转换后 js := string(data)
// upto this place there is no error or warnings
ind, err := esclient.Index().
Index(Type).
BodyJson(js).
Do(ctx)
这是它引发的错误failed to parse field [id] of type [long] in document with id 'gPmI8HIBCIO6Ejb-Y51D'. Preview of field's value: 'a5c723c5-1f6e-457f-9556-47b7ebcfd183'
最佳答案
该错误消息非常清楚,您正在尝试存储a5c723c5-1f6e-457f-9556-47b7ebcfd183
(它是一个字符串),只要id
字段在您的Elasticsearch映射中映射为long
即可。
甚至还告诉您,使用_id
作为值的gPmI8HIBCIO6Ejb-Y51D
文档出错,因此您可以找到此文档并进行更正。
请根据您的情况发送以下字段的正确值,即有效的long
,以解决此问题。
ID string `json:"id"`
如果您想获取更多代码级别的详细信息,请引用Elasticsearch的this代码,该代码将解析值并引发异常。
关于go - 无法在elasticsearch中保存UUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62594940/