es解析json JsonGe報錯 nerationException: Can not start an object, expecting field name

Error log

Exception in thread “main” com.fasterxml.jackson.core.JsonGenerationException: Can not start an object, expecting field name

code(獲取es索引大小)

val indicesStatsResponse: IndicesStatsResponse = client//init client
.admin()
.indices()
.prepareStats(“index_name”)
.all()
.execute().actionGet()

val builder: XContentBuilder = XContentFactory.jsonBuilder()
//error toXContent中已經調用startObject ----- es version6.4
builder.startObject() //重複調用
indicesStatsResponse.toXContent(builder, ToXContent.EMPTY_PARAMS)
builder.endObject()

val jsonResponse = Strings.toString(builder.prettyPrint())
val jsonParser = new JsonParser()
val sizeOfIndex = jsonParser.parse(jsonResponse)
.getAsJsonObject().get("_all")
.getAsJsonObject().get(“primaries”)
.getAsJsonObject().get(“store”)
.getAsJsonObject().get(“size_in_bytes”).getAsLong()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章