use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.
the class Alias method filter.
/**
* Associates a filter to the alias
*/
public Alias filter(Map<String, Object> filter) {
if (filter == null || filter.isEmpty()) {
this.filter = null;
return this;
}
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(filter);
this.filter = builder.string();
return this;
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + filter + "]", e);
}
}
use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.
the class NodesStatsResponse method toString.
@Override
public String toString() {
try {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
toXContent(builder, EMPTY_PARAMS);
builder.endObject();
return builder.string();
} catch (IOException e) {
return "{ \"error\" : \"" + e.getMessage() + "\"}";
}
}
use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.
the class PutRepositoryRequest method settings.
/**
* Sets the repository settings.
*
* @param source repository settings
* @return this request
*/
public PutRepositoryRequest settings(Map<String, Object> source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
settings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
return this;
}
use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.
the class RestoreSnapshotRequest method indexSettings.
/**
* Sets settings that should be added/changed in all restored indices
*/
public RestoreSnapshotRequest indexSettings(Map<String, Object> source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
indexSettings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
return this;
}
use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.
the class DecayFunctionParser method fromXContent.
/**
* Parses bodies of the kind
*
* <pre>
* <code>
* {
* "fieldname1" : {
* "origin" : "someValue",
* "scale" : "someValue"
* },
* "multi_value_mode" : "min"
* }
* </code>
* </pre>
*/
@Override
public DFB fromXContent(QueryParseContext context) throws IOException, ParsingException {
XContentParser parser = context.parser();
String currentFieldName;
XContentParser.Token token;
MultiValueMode multiValueMode = DecayFunctionBuilder.DEFAULT_MULTI_VALUE_MODE;
String fieldName = null;
BytesReference functionBytes = null;
while ((token = parser.nextToken()) == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
token = parser.nextToken();
if (token == XContentParser.Token.START_OBJECT) {
fieldName = currentFieldName;
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.copyCurrentStructure(parser);
functionBytes = builder.bytes();
} else if (MULTI_VALUE_MODE.match(currentFieldName)) {
multiValueMode = MultiValueMode.fromString(parser.text());
} else {
throw new ParsingException(parser.getTokenLocation(), "malformed score function score parameters.");
}
}
if (fieldName == null || functionBytes == null) {
throw new ParsingException(parser.getTokenLocation(), "malformed score function score parameters.");
}
DFB functionBuilder = createFromBytes.apply(fieldName, functionBytes);
functionBuilder.setMultiValueMode(multiValueMode);
return functionBuilder;
}
Aggregations