Java Code Examples for org.elasticsearch.common.xcontent.XContentBuilder#endArray()
The following examples show how to use
org.elasticsearch.common.xcontent.XContentBuilder#endArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShapeBuilder.java From crate with Apache License 2.0 | 6 votes |
/** * 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 coord : coordinates) { toXContent(builder, coord); } if (closed) { Coordinate start = coordinates.get(0); Coordinate end = coordinates.get(coordinates.size() - 1); if (start.x != end.x || start.y != end.y) { toXContent(builder, coordinates.get(0)); } } builder.endArray(); return builder; }
Example 2
Source File: PipelineAggregatorBuilder.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public final XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(getName()); if (this.metaData != null) { builder.field("meta", this.metaData); } builder.startObject(type); if (bucketsPaths != null) { builder.startArray(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName()); for (String path : bucketsPaths) { builder.value(path); } builder.endArray(); } internalXContent(builder, params); builder.endObject(); return builder.endObject(); }
Example 3
Source File: InternalHistogram.java From Elasticsearch with Apache License 2.0 | 6 votes |
@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; }
Example 4
Source File: ClusterStatsNodes.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field(Fields.AVAILABLE_PROCESSORS, availableProcessors); builder.field(Fields.ALLOCATED_PROCESSORS, allocatedProcessors); builder.startObject(Fields.MEM); builder.byteSizeField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, availableMemory); builder.endObject(); builder.startArray(Fields.NAMES); for (ObjectIntCursor<String> name : names) { builder.startObject(); builder.field(Fields.NAME, name.key); builder.field(Fields.COUNT, name.value); builder.endObject(); } builder.endArray(); return builder; }
Example 5
Source File: SQLBaseResponse.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected void writeSharedAttributes(XContentBuilder builder) throws IOException { builder.array(Fields.COLS, cols); if (includeTypes) { builder.startArray(Fields.COLUMNTYPES); if (colTypes != null) { for (DataType colType : colTypes) { toXContentNestedDataType(builder, colType); } } builder.endArray(); } builder.field(Fields.DURATION, duration()); }
Example 6
Source File: Setting.java From crate with Apache License 2.0 | 5 votes |
private static String arrayToParsableString(List<String> array) { try { XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent()); builder.startArray(); for (String element : array) { builder.value(element); } builder.endArray(); return Strings.toString(builder); } catch (IOException ex) { throw new ElasticsearchException(ex); } }
Example 7
Source File: Suggest.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(Fields.TEXT, text); builder.field(Fields.OFFSET, offset); builder.field(Fields.LENGTH, length); builder.startArray(Fields.OPTIONS); for (Option option : options) { option.toXContent(builder, params); } builder.endArray(); builder.endObject(); return builder; }
Example 8
Source File: CompletionFieldMapper.java From elasticsearch-mapper with Apache License 2.0 | 5 votes |
public static void mapDataType(XContentBuilder mappingBuilder, CompletionField completionField) throws IOException { mappingBuilder.field("type", "completion"); if (!"simple".equalsIgnoreCase(completionField.analyzer())) { mappingBuilder.field("analyzer", completionField.analyzer()); } if (!"simple".equalsIgnoreCase(completionField.search_analyzer())) { mappingBuilder.field("search_analyzer", completionField.search_analyzer()); } if (!completionField.preserve_separators()) { mappingBuilder.field("preserve_separators", completionField.preserve_separators()); } if (!completionField.preserve_position_increments()) { mappingBuilder.field("preserve_position_increments", completionField.preserve_position_increments()); } if (completionField.max_input_length() != 50) { mappingBuilder.field("max_input_length", completionField.max_input_length()); } if (completionField.contexts().length > 0) { mappingBuilder.startArray("contexts"); for (CompletionContext completionContext : completionField.contexts()) { mappingBuilder.field("name", completionContext.name()); mappingBuilder.field("type", completionContext.type()); if (StringUtils.isNotBlank(completionContext.path())) { mappingBuilder.field("path", completionContext.path()); } } mappingBuilder.endArray(); } }
Example 9
Source File: BasePolygonBuilder.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(FIELD_TYPE, TYPE.shapename); builder.startArray(FIELD_COORDINATES); coordinatesArray(builder, params); builder.endArray(); builder.endObject(); return builder; }
Example 10
Source File: ElasticsearchException.java From Elasticsearch with Apache License 2.0 | 5 votes |
private void xContentHeader(XContentBuilder builder, String key, List<String> values) throws IOException { if (values != null && values.isEmpty() == false) { if(values.size() == 1) { builder.field(key, values.get(0)); } else { builder.startArray(key); for (String value : values) { builder.value(value); } builder.endArray(); } } }
Example 11
Source File: RecoveryState.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public synchronized XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { // stream size first, as it matters more and the files section can be long builder.startObject(Fields.SIZE); builder.byteSizeField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, totalBytes()); builder.byteSizeField(Fields.REUSED_IN_BYTES, Fields.REUSED, reusedBytes()); builder.byteSizeField(Fields.RECOVERED_IN_BYTES, Fields.RECOVERED, recoveredBytes()); builder.field(Fields.PERCENT, String.format(Locale.ROOT, "%1.1f%%", recoveredBytesPercent())); builder.endObject(); builder.startObject(Fields.FILES); builder.field(Fields.TOTAL, totalFileCount()); builder.field(Fields.REUSED, reusedFileCount()); builder.field(Fields.RECOVERED, recoveredFileCount()); builder.field(Fields.PERCENT, String.format(Locale.ROOT, "%1.1f%%", recoveredFilesPercent())); if (params.paramAsBoolean("details", false)) { builder.startArray(Fields.DETAILS); for (File file : fileDetails.values()) { file.toXContent(builder, params); } builder.endArray(); } builder.endObject(); builder.timeValueField(Fields.TOTAL_TIME_IN_MILLIS, Fields.TOTAL_TIME, time()); builder.timeValueField(Fields.SOURCE_THROTTLE_TIME_IN_MILLIS, Fields.SOURCE_THROTTLE_TIME, sourceThrottling()); builder.timeValueField(Fields.TARGET_THROTTLE_TIME_IN_MILLIS, Fields.TARGET_THROTTLE_TIME, targetThrottling()); return builder; }
Example 12
Source File: CategoryContextMapping.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected XContentBuilder toInnerXContent(XContentBuilder builder, Params params) throws IOException { if (fieldName != null) { builder.field(FIELD_FIELDNAME, fieldName); } builder.startArray(FIELD_MISSING); for (CharSequence value : defaultValues) { builder.value(value); } builder.endArray(); return builder; }
Example 13
Source File: AllocationCommands.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Writes {@link AllocationCommands} to a {@link XContentBuilder} * * @param commands {@link AllocationCommands} to write * @param builder {@link XContentBuilder} to use * @param params Parameters to use for building * @throws IOException if something bad happens while building the content */ public static void toXContent(AllocationCommands commands, XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startArray("commands"); for (AllocationCommand command : commands.commands) { builder.startObject(); builder.field(command.name()); AllocationCommands.lookupFactorySafe(command.name()).toXContent(command, builder, params, null); builder.endObject(); } builder.endArray(); }
Example 14
Source File: SpanNearQueryBuilder.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { if (clauses.isEmpty()) { throw new IllegalArgumentException("Must have at least one clause when building a spanNear query"); } if (slop == null) { throw new IllegalArgumentException("Must set the slop when building a spanNear query"); } builder.startObject(SpanNearQueryParser.NAME); builder.startArray("clauses"); for (SpanQueryBuilder clause : clauses) { clause.toXContent(builder, params); } builder.endArray(); builder.field("slop", slop.intValue()); if (inOrder != null) { builder.field("in_order", inOrder); } if (collectPayloads != null) { builder.field("collect_payloads", collectPayloads); } if (boost != -1) { builder.field("boost", boost); } if (queryName != null) { builder.field("_name", queryName); } builder.endObject(); }
Example 15
Source File: ElasticsearchException.java From crate with Apache License 2.0 | 5 votes |
private static void headerToXContent(XContentBuilder builder, String key, List<String> values) throws IOException { if (values != null && values.isEmpty() == false) { if (values.size() == 1) { builder.field(key, values.get(0)); } else { builder.startArray(key); for (String value : values) { builder.value(value); } builder.endArray(); } } }
Example 16
Source File: RestoreInProgress.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startArray("snapshots"); for (Entry entry : entries) { toXContent(entry, builder, params); } builder.endArray(); return builder; }
Example 17
Source File: FsInfo.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.FS); builder.field(Fields.TIMESTAMP, timestamp); builder.field(Fields.TOTAL); total().toXContent(builder, params); builder.startArray(Fields.DATA); for (Path path : paths) { path.toXContent(builder, params); } builder.endArray(); builder.endObject(); return builder; }
Example 18
Source File: IndicesStatsResponse.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { String level = params.param("level", "indices"); boolean isLevelValid = "indices".equalsIgnoreCase(level) || "shards".equalsIgnoreCase(level) || "cluster".equalsIgnoreCase(level); if (!isLevelValid) { return builder; } builder.startObject("_all"); builder.startObject("primaries"); getPrimaries().toXContent(builder, params); builder.endObject(); builder.startObject("total"); getTotal().toXContent(builder, params); builder.endObject(); builder.endObject(); if ("indices".equalsIgnoreCase(level) || "shards".equalsIgnoreCase(level)) { builder.startObject(Fields.INDICES); for (IndexStats indexStats : getIndices().values()) { builder.startObject(indexStats.getIndex(), XContentBuilder.FieldCaseConversion.NONE); builder.startObject("primaries"); indexStats.getPrimaries().toXContent(builder, params); builder.endObject(); builder.startObject("total"); indexStats.getTotal().toXContent(builder, params); builder.endObject(); if ("shards".equalsIgnoreCase(level)) { builder.startObject(Fields.SHARDS); for (IndexShardStats indexShardStats : indexStats) { builder.startArray(Integer.toString(indexShardStats.getShardId().id())); for (ShardStats shardStats : indexShardStats) { builder.startObject(); shardStats.toXContent(builder, params); builder.endObject(); } builder.endArray(); } builder.endObject(); } builder.endObject(); } builder.endObject(); } return builder; }
Example 19
Source File: IndicesSegmentResponse.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.INDICES); for (IndexSegments indexSegments : getIndices().values()) { builder.startObject(indexSegments.getIndex(), XContentBuilder.FieldCaseConversion.NONE); builder.startObject(Fields.SHARDS); for (IndexShardSegments indexSegment : indexSegments) { builder.startArray(Integer.toString(indexSegment.getShardId().id())); for (ShardSegments shardSegments : indexSegment) { builder.startObject(); builder.startObject(Fields.ROUTING); builder.field(Fields.STATE, shardSegments.getShardRouting().state()); builder.field(Fields.PRIMARY, shardSegments.getShardRouting().primary()); builder.field(Fields.NODE, shardSegments.getShardRouting().currentNodeId()); if (shardSegments.getShardRouting().relocatingNodeId() != null) { builder.field(Fields.RELOCATING_NODE, shardSegments.getShardRouting().relocatingNodeId()); } builder.endObject(); builder.field(Fields.NUM_COMMITTED_SEGMENTS, shardSegments.getNumberOfCommitted()); builder.field(Fields.NUM_SEARCH_SEGMENTS, shardSegments.getNumberOfSearch()); builder.startObject(Fields.SEGMENTS); for (Segment segment : shardSegments) { builder.startObject(segment.getName()); builder.field(Fields.GENERATION, segment.getGeneration()); builder.field(Fields.NUM_DOCS, segment.getNumDocs()); builder.field(Fields.DELETED_DOCS, segment.getDeletedDocs()); builder.byteSizeField(Fields.SIZE_IN_BYTES, Fields.SIZE, segment.getSizeInBytes()); builder.byteSizeField(Fields.MEMORY_IN_BYTES, Fields.MEMORY, segment.getMemoryInBytes()); builder.field(Fields.COMMITTED, segment.isCommitted()); builder.field(Fields.SEARCH, segment.isSearch()); if (segment.getVersion() != null) { builder.field(Fields.VERSION, segment.getVersion()); } if (segment.isCompound() != null) { builder.field(Fields.COMPOUND, segment.isCompound()); } if (segment.getMergeId() != null) { builder.field(Fields.MERGE_ID, segment.getMergeId()); } if (segment.ramTree != null) { builder.startArray(Fields.RAM_TREE); for (Accountable child : segment.ramTree.getChildResources()) { toXContent(builder, child); } builder.endArray(); } builder.endObject(); } builder.endObject(); builder.endObject(); } builder.endArray(); } builder.endObject(); builder.endObject(); } builder.endObject(); return builder; }
Example 20
Source File: GeoDistanceSortBuilder.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("_geo_distance"); if (geohashes.size() == 0 && points.size() == 0) { throw new ElasticsearchParseException("No points provided for _geo_distance sort."); } builder.startArray(fieldName); for (GeoPoint point : points) { builder.value(point); } for (String geohash : geohashes) { builder.value(geohash); } builder.endArray(); if (unit != null) { builder.field("unit", unit); } if (geoDistance != null) { builder.field("distance_type", geoDistance.name().toLowerCase(Locale.ROOT)); } if (order == SortOrder.DESC) { builder.field("order", "desc"); } if (sortMode != null) { builder.field("mode", sortMode); } if (nestedPath != null) { builder.field("nested_path", nestedPath); } if (nestedFilter != null) { builder.field("nested_filter", nestedFilter, params); } if (coerce != null) { builder.field("coerce", coerce); } if (ignoreMalformed != null) { builder.field("ignore_malformed", ignoreMalformed); } builder.endObject(); return builder; }