Converting a FacetBuilder to Json

(leonm) #1

I'm trying to write a little Unit Test to check that we setting up our objects correctly. To do this I'm setting up a FacetBuilder and convert it to Json that from where I can assert its correctness.

However, when I try to convert the FacetBuilder to Json I get an Exception:

TermsFacetBuilder facetBuilder = FacetBuilders.termsFacet("name").field("field");
String jsonString = facetBuilder.toXContent(XContentFactory.safeJsonBuilder(), EMPTY_PARAMS).string();

org.elasticsearch.common.jackson.JsonGenerationException: Can not write a field name, expecting a value
at org.elasticsearch.common.jackson.impl.JsonGeneratorBase._reportError(
at org.elasticsearch.common.jackson.impl.Utf8Generator.writeFieldName(
at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(
at org.elasticsearch.common.xcontent.XContentBuilder.field(
at org.elasticsearch.common.xcontent.XContentBuilder.startObject(

I tried both versions 0.17.4 and 0.17.7 with pretty consistent results (StackTrace is for 0.17.7)

I fired up a debugger and stepped through the code and there is nothing that is null or otherwise broken.

(system) #2