in golang 如何使用用户生成的 ID 并为每个新条目递增它?我试过了
Index(KpiIndex). Type(KpiDocType). Id(ids). => Id will take only stings. BodyJson(kpis). Do(elasticSearchContext)
当数据存储在ES中时,它被随机存储
{ "采取" : 5, "timed_out":假, "_shards" : { "总计" : 5, "成功" : 5, "失败" : 0 }, "命中" : { "总计" : 4, "max_score" : 1.0, "命中数" : [ { "_index" : "KPI", "_type" : "KPI", "_id" : "AWIexPLwnbh5r7Xr9nsL", "_score" : 1.0, "_source" : { "日期" : "2018-03-13 15:20:45", "关键帧率" : [ {
"Static_limit" : 0 }, { "CpuAverageLoad" : 0, ..., "NodeType" : "kkk", "State" : "online" } ] } }, { "_index" : "kpi", "_type" : "kpi", "_id" : "AWIexYy1_xnN0Y7Qo1HE", "_score" : 1.0, "_source" : { "date" : "2018-03-13 15:21:25", "kpi" : [ { "CpuAverageLoad" : 0, }, { "CpuAverageLoad" : 0, ..., "NodeType" : "kkk", "State" : "online" } ] } }, { "_index" : "kpi", "_type" : "kpi", "_id" : "AWIexdrLnbh5r7Xr9nsM", "_score" : 1.0, "_source" : { "date" : "2018-03-13 15:21:45", "kpi" : [ { "Static_limit" : 0 }, { "CpuAverageLoad" : 0, ..., "NodeType" : "kkk", "State" : "online" } ] } }, { "_index" : "kpi", "_type" : "kpi", "_id" : "AWIexT52BjtG8JuPSysx", "_score" : 1.0, "_source" : { "date" : "2018-03-13 15:21:05", "kpi" : [ { "Static_limit" : 0 }, { "CpuAverageLoad" : 0, ..., "NodeType" : "kkk", "State" : "online" } ] } } ]
} }
当我们观察"数据"字段时,顺序为
"date" : "2018-03-13 15:20:45",
"date" : "2018-03-13 15:21:25",
"date" : "2018-03-13 15:21:45",
"date" : "2018-03-13 15:21:05",
其中正确的顺序应该是
"date" : "2018-03-13 15:20:45",
"date" : "2018-03-13 15:21:05",
"date" : "2018-03-13 15:21:25",
"date" : "2018-03-13 15:21:45"
可以在 json 正文中使用属性,该属性的值将为 GUID。因此,将该属性定义为_id属性。这是定义索引 ID 的方法。