clean builder code when dealing with maps
This commit is contained in:
parent
4a9c7d672e
commit
75ee01a6b4
|
@ -82,11 +82,6 @@ public abstract class XContentBuilder<T extends XContentBuilder> {
|
|||
return builder;
|
||||
}
|
||||
|
||||
public T map(Map<String, Object> map) throws IOException {
|
||||
XContentMapConverter.writeMap(generator, map);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public T startObject(String name) throws IOException {
|
||||
field(name);
|
||||
startObject();
|
||||
|
@ -208,6 +203,12 @@ public abstract class XContentBuilder<T extends XContentBuilder> {
|
|||
return builder;
|
||||
}
|
||||
|
||||
public T field(String name, Map<String, Object> value) throws IOException {
|
||||
field(name);
|
||||
value(value);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public T field(String name, Object value) throws IOException {
|
||||
if (value == null) {
|
||||
nullField(name);
|
||||
|
@ -232,6 +233,8 @@ public abstract class XContentBuilder<T extends XContentBuilder> {
|
|||
field(name, (byte[]) value);
|
||||
} else if (value instanceof ReadableInstant) {
|
||||
field(name, (ReadableInstant) value);
|
||||
} else if (value instanceof Map) {
|
||||
field(name, (Map<String, Object>) value);
|
||||
} else {
|
||||
field(name, value.toString());
|
||||
}
|
||||
|
@ -358,6 +361,16 @@ public abstract class XContentBuilder<T extends XContentBuilder> {
|
|||
return builder;
|
||||
}
|
||||
|
||||
public T map(Map<String, Object> map) throws IOException {
|
||||
XContentMapConverter.writeMap(generator, map);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public T value(Map<String, Object> map) throws IOException {
|
||||
XContentMapConverter.writeMap(generator, map);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public T value(Object value) throws IOException {
|
||||
Class type = value.getClass();
|
||||
if (type == String.class) {
|
||||
|
@ -378,6 +391,8 @@ public abstract class XContentBuilder<T extends XContentBuilder> {
|
|||
value((Date) value);
|
||||
} else if (value instanceof ReadableInstant) {
|
||||
value((ReadableInstant) value);
|
||||
} else if (value instanceof Map) {
|
||||
value((Map<String, Object>) value);
|
||||
} else {
|
||||
throw new IOException("Type not allowed [" + type + "]");
|
||||
}
|
||||
|
|
|
@ -95,8 +95,7 @@ public class CustomScoreQueryBuilder extends BaseQueryBuilder {
|
|||
queryBuilder.toXContent(builder, params);
|
||||
builder.field("script", script);
|
||||
if (this.params != null) {
|
||||
builder.field("params");
|
||||
builder.map(this.params);
|
||||
builder.field("params", this.params);
|
||||
}
|
||||
if (boost != -1) {
|
||||
builder.field("boost", boost);
|
||||
|
|
|
@ -60,8 +60,7 @@ public class ScriptFilterBuilder extends BaseFilterBuilder {
|
|||
builder.startObject(ScriptFilterParser.NAME);
|
||||
builder.field("script", script);
|
||||
if (this.params != null) {
|
||||
builder.field("params");
|
||||
builder.map(this.params);
|
||||
builder.field("params", this.params);
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
|
@ -221,8 +221,7 @@ public class GeoDistanceFacetBuilder extends AbstractFacetBuilder {
|
|||
if (valueScript != null) {
|
||||
builder.field("value_script", valueScript);
|
||||
if (this.params != null) {
|
||||
builder.field("params");
|
||||
builder.map(this.params);
|
||||
builder.field("params", this.params);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,8 +96,7 @@ public class HistogramScriptFacetBuilder extends AbstractFacetBuilder {
|
|||
builder.field("interval", interval);
|
||||
}
|
||||
if (this.params != null) {
|
||||
builder.field("params");
|
||||
builder.map(this.params);
|
||||
builder.field("params", this.params);
|
||||
}
|
||||
if (comparatorType != null) {
|
||||
builder.field("comparator", comparatorType.description());
|
||||
|
|
|
@ -136,8 +136,7 @@ public class RangeScriptFacetBuilder extends AbstractFacetBuilder {
|
|||
builder.endArray();
|
||||
|
||||
if (this.params != null) {
|
||||
builder.field("params");
|
||||
builder.map(this.params);
|
||||
builder.field("params", this.params);
|
||||
}
|
||||
builder.endObject();
|
||||
|
||||
|
|
|
@ -71,8 +71,7 @@ public class StatisticalScriptFacetBuilder extends AbstractFacetBuilder {
|
|||
builder.startObject(StatisticalFacetCollectorParser.NAME);
|
||||
builder.field("script", script);
|
||||
if (this.params != null) {
|
||||
builder.field("params");
|
||||
builder.map(this.params);
|
||||
builder.field("params", this.params);
|
||||
}
|
||||
builder.endObject();
|
||||
|
||||
|
|
|
@ -128,8 +128,7 @@ public class TermsFacetBuilder extends AbstractFacetBuilder {
|
|||
if (script != null) {
|
||||
builder.field("script", script);
|
||||
if (this.params != null) {
|
||||
builder.field("params");
|
||||
builder.map(this.params);
|
||||
builder.field("params", this.params);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,8 +64,7 @@ public class ScriptSortBuilder extends SortBuilder {
|
|||
builder.field("reverse", true);
|
||||
}
|
||||
if (this.params != null) {
|
||||
builder.field("params");
|
||||
builder.map(this.params);
|
||||
builder.field("params", this.params);
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue