Skip to content

Commit 31d2261

Browse files
committed
REST API: Allow to provide case parameter, with camelCase to return results in CamelCasing, closes #162.
1 parent e222d38 commit 31d2261

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.util.xcontent.XContentFactory;
2424
import org.elasticsearch.util.xcontent.XContentType;
2525
import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder;
26+
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
2627

2728
import java.io.IOException;
2829

@@ -47,6 +48,14 @@ public static BinaryXContentBuilder restContentBuilder(RestRequest request) thro
4748
if (request.paramAsBoolean("pretty", false)) {
4849
builder.prettyPrint();
4950
}
51+
String casing = request.param("case");
52+
if (casing != null && "camelCase".equals(casing)) {
53+
builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE);
54+
} else {
55+
// we expect all REST interfaces to write results in underscore casing, so
56+
// no need for double casing
57+
builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE);
58+
}
5059
return builder;
5160
}
5261
}

0 commit comments

Comments
 (0)