本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentBuilder类的典型用法代码示例。如果您正苦于以下问题:Java XContentBuilder类的具体用法?Java XContentBuilder怎么用?Java XContentBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XContentBuilder类属于org.elasticsearch.common.xcontent包,在下文中一共展示了XContentBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doXContentBody
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
if (keyed) {
builder.startObject(CommonFields.BUCKETS);
} else {
builder.startArray(CommonFields.BUCKETS);
}
for (B bucket : buckets) {
bucket.toXContent(builder, params);
}
if (keyed) {
builder.endObject();
} else {
builder.endArray();
}
return builder;
}
示例2: toXContent
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
if (tokens != null) {
builder.startArray(Fields.TOKENS);
for (AnalyzeToken token : tokens) {
token.toXContent(builder, params);
}
builder.endArray();
}
if (detail != null) {
builder.startObject(Fields.DETAIL);
detail.toXContent(builder, params);
builder.endObject();
}
builder.endObject();
return builder;
}
示例3: createMappinmgWithCopyToInMultiField
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
private static XContentBuilder createMappinmgWithCopyToInMultiField() throws IOException {
XContentBuilder mapping = jsonBuilder();
mapping.startObject()
.startObject("type")
.startObject("properties")
.startObject("a")
.field("type", "text")
.endObject()
.startObject("b")
.field("type", "text")
.startObject("fields")
.startObject("c")
.field("type", "text")
.field("copy_to", "a")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.endObject();
return mapping;
}
示例4: toXContent
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.ROUTING)
.field(Fields.STATE, shardRouting.state())
.field(Fields.PRIMARY, shardRouting.primary())
.field(Fields.NODE, shardRouting.currentNodeId())
.field(Fields.RELOCATING_NODE, shardRouting.relocatingNodeId())
.endObject();
commonStats.toXContent(builder, params);
if (commitStats != null) {
commitStats.toXContent(builder, params);
}
builder.startObject(Fields.SHARD_PATH);
builder.field(Fields.STATE_PATH, statePath);
builder.field(Fields.DATA_PATH, dataPath);
builder.field(Fields.IS_CUSTOM_DATA_PATH, isCustomDataPath);
builder.endObject();
return builder;
}
示例5: testSerializeDefaults
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
public void testSerializeDefaults() throws Exception {
for (String type : TYPES) {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", type).endObject().endObject()
.endObject().endObject().string();
DocumentMapper docMapper = parser.parse("type", new CompressedXContent(mapping));
RangeFieldMapper mapper = (RangeFieldMapper) docMapper.root().getMapper("field");
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
mapper.doXContentBody(builder, true, ToXContent.EMPTY_PARAMS);
String got = builder.endObject().string();
// if type is date_range we check that the mapper contains the default format and locale
// otherwise it should not contain a locale or format
assertTrue(got, got.contains("\"format\":\"strict_date_optional_time||epoch_millis\"") == type.equals("date_range"));
assertTrue(got, got.contains("\"locale\":" + "\"" + Locale.ROOT + "\"") == type.equals("date_range"));
}
}
示例6: doInternalXContent
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
@Override
protected XContentBuilder doInternalXContent(XContentBuilder builder, Params params) throws IOException {
// builder.startObject();
if (shardSize != SamplerParser.DEFAULT_SHARD_SAMPLE_SIZE) {
builder.field(SamplerParser.SHARD_SIZE_FIELD.getPreferredName(), shardSize);
}
if (maxDocsPerValue != SamplerParser.MAX_DOCS_PER_VALUE_DEFAULT) {
builder.field(SamplerParser.MAX_DOCS_PER_VALUE_FIELD.getPreferredName(), maxDocsPerValue);
}
if (executionHint != null) {
builder.field(SamplerParser.EXECUTION_HINT_FIELD.getPreferredName(), executionHint);
}
return builder;
}
示例7: toXContent
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject(Fields.INDEXING);
totalStats.toXContent(builder, params);
if (typeStats != null && !typeStats.isEmpty()) {
builder.startObject(Fields.TYPES);
for (Map.Entry<String, Stats> entry : typeStats.entrySet()) {
builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
entry.getValue().toXContent(builder, params);
builder.endObject();
}
builder.endObject();
}
builder.endObject();
return builder;
}
示例8: toXContent
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field("name", nodeName);
builder.field("cluster_name", clusterName.value());
builder.field("cluster_uuid", clusterUuid);
builder.startObject("version")
.field("number", version.toString())
.field("build_hash", build.shortHash())
.field("build_date", build.date())
.field("build_snapshot", build.isSnapshot())
.field("lucene_version", version.luceneVersion.toString())
.endObject();
builder.field("tagline", "You Know, for Search");
builder.endObject();
return builder;
}
示例9: testTwoAggs
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
public void testTwoAggs() throws Exception {
assumeFalse("Test only makes sense if XContent parser doesn't have strict duplicate checks enabled",
XContent.isStrictDuplicateDetectionEnabled());
XContentBuilder source = JsonXContent.contentBuilder()
.startObject()
.startObject("by_date")
.startObject("date_histogram")
.field("field", "timestamp")
.field("interval", "month")
.endObject()
.startObject("aggs")
.startObject("tag_count")
.startObject("cardinality")
.field("field", "tag")
.endObject()
.endObject()
.endObject()
.startObject("aggs") // 2nd "aggs": illegal
.startObject("tag_count2")
.startObject("cardinality")
.field("field", "tag")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject();
XContentParser parser = createParser(source);
QueryParseContext parseContext = new QueryParseContext(parser);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
Exception e = expectThrows(ParsingException.class, () -> AggregatorFactories.parseAggregators(parseContext));
assertThat(e.toString(), containsString("Found two sub aggregation definitions under [by_date]"));
}
示例10: toXContent
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.startArray(Fields.DOCS);
for (MultiTermVectorsItemResponse response : responses) {
if (response.isFailed()) {
builder.startObject();
Failure failure = response.getFailure();
builder.field(Fields._INDEX, failure.getIndex());
builder.field(Fields._TYPE, failure.getType());
builder.field(Fields._ID, failure.getId());
ElasticsearchException.generateFailureXContent(builder, params, failure.getCause(), true);
builder.endObject();
} else {
TermVectorsResponse getResponse = response.getResponse();
getResponse.toXContent(builder, params);
}
}
builder.endArray();
builder.endObject();
return builder;
}
示例11: coordinatesToXcontent
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
/**
* builds an array of coordinates to a {@link XContentBuilder}
*
* @param builder builder to use
* @param closed repeat the first point at the end of the array if it's not already defines as last element of the array
* @return the builder
*/
protected XContentBuilder coordinatesToXcontent(XContentBuilder builder, boolean closed) throws IOException {
builder.startArray();
for(Coordinate point : points) {
toXContent(builder, point);
}
if(closed) {
Coordinate start = points.get(0);
Coordinate end = points.get(points.size()-1);
if(start.x != end.x || start.y != end.y) {
toXContent(builder, points.get(0));
}
}
builder.endArray();
return builder;
}
示例12: createIndexMapping
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
public XContentBuilder createIndexMapping() {
try {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject(CITY_TYPE)
.startObject("properties")
// city
.startObject("name")
.field("type", "string")
.endObject()
// country
.startObject("country")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.endObject()
.endObject().endObject();
return mapping;
}
catch(IOException ioe) {
throw new TechnicalException(String.format("Error while getting mapping for index [%s/%s]: %s", INDEX, CITY_TYPE, ioe.getMessage()), ioe);
}
}
示例13: testPipelineQueryParameterIsError
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
public void testPipelineQueryParameterIsError() throws IOException {
RestReindexAction action = new RestReindexAction(Settings.EMPTY, mock(RestController.class));
FakeRestRequest.Builder request = new FakeRestRequest.Builder(xContentRegistry());
try (XContentBuilder body = JsonXContent.contentBuilder().prettyPrint()) {
body.startObject(); {
body.startObject("source"); {
body.field("index", "source");
}
body.endObject();
body.startObject("dest"); {
body.field("index", "dest");
}
body.endObject();
}
body.endObject();
request.withContent(body.bytes(), body.contentType());
}
request.withParams(singletonMap("pipeline", "doesn't matter"));
Exception e = expectThrows(IllegalArgumentException.class, () -> action.buildRequest(request.build()));
assertEquals("_reindex doesn't support [pipeline] as a query parmaeter. Specify it in the [dest] object instead.", e.getMessage());
}
示例14: prepareRequest
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));
mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions()));
mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments()));
mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes()));
mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush()));
return channel -> client.admin().indices().forceMerge(mergeRequest, new RestBuilderListener<ForceMergeResponse>(channel) {
@Override
public RestResponse buildResponse(ForceMergeResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
buildBroadcastShardsHeader(builder, request, response);
builder.endObject();
return new BytesRestResponse(OK, builder);
}
});
}
示例15: testConditionsParsing
import org.elasticsearch.common.xcontent.XContentBuilder; //导入依赖的package包/类
public void testConditionsParsing() throws Exception {
final RolloverRequest request = new RolloverRequest(randomAsciiOfLength(10), randomAsciiOfLength(10));
final XContentBuilder builder = XContentFactory.jsonBuilder()
.startObject()
.startObject("conditions")
.field("max_age", "10d")
.field("max_docs", 100)
.endObject()
.endObject();
RolloverRequest.PARSER.parse(createParser(builder), request, null);
Set<Condition> conditions = request.getConditions();
assertThat(conditions.size(), equalTo(2));
for (Condition condition : conditions) {
if (condition instanceof MaxAgeCondition) {
MaxAgeCondition maxAgeCondition = (MaxAgeCondition) condition;
assertThat(maxAgeCondition.value.getMillis(), equalTo(TimeValue.timeValueHours(24 * 10).getMillis()));
} else if (condition instanceof MaxDocsCondition) {
MaxDocsCondition maxDocsCondition = (MaxDocsCondition) condition;
assertThat(maxDocsCondition.value, equalTo(100L));
} else {
fail("unexpected condition " + condition);
}
}
}