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()