Java Code Examples for org.elasticsearch.common.xcontent.XContentBuilder#value()
The following examples show how to use
org.elasticsearch.common.xcontent.XContentBuilder#value() .
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: Script.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public final XContentBuilder toXContent(XContentBuilder builder, Params builderParams) throws IOException { if (type == null) { return builder.value(script); } builder.startObject(); scriptFieldToXContent(script, type, builder, builderParams); if (lang != null) { builder.field(ScriptField.LANG.getPreferredName(), lang); } if (params != null) { builder.field(ScriptField.PARAMS.getPreferredName(), params); } builder.endObject(); return builder; }
Example 2
Source File: HasParentQueryBuilder.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(HasParentQueryParser.NAME); builder.field("query"); queryBuilder.toXContent(builder, params); builder.field("parent_type", parentType); if (scoreMode != null) { builder.field("score_mode", scoreMode); } if (boost != 1.0f) { builder.field("boost", boost); } if (queryName != null) { builder.field("_name", queryName); } if (innerHit != null) { builder.startObject("inner_hits"); builder.value(innerHit); builder.endObject(); } builder.endObject(); }
Example 3
Source File: UpdateRequestBuilder.java From elasticshell with Apache License 2.0 | 6 votes |
@Override protected XContentBuilder toXContent(UpdateRequest request, UpdateResponse response, XContentBuilder builder) throws IOException { builder.startObject() .field(Fields.OK, true) .field(Fields._INDEX, response.getIndex()) .field(Fields._TYPE, response.getType()) .field(Fields._ID, response.getId()) .field(Fields._VERSION, response.getVersion()); if (response.getGetResult() != null) { builder.startObject(Fields.GET); response.getGetResult().toXContentEmbedded(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); } if (response.getMatches() != null) { builder.startArray(Fields.MATCHES); for (String match : response.getMatches()) { builder.value(match); } builder.endArray(); } builder.endObject(); return builder; }
Example 4
Source File: NestedQueryBuilder.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NestedQueryParser.NAME); builder.field("query"); queryBuilder.toXContent(builder, params); builder.field("path", path); if (scoreMode != null) { builder.field("score_mode", scoreMode); } if (boost != 1.0f) { builder.field("boost", boost); } if (queryName != null) { builder.field("_name", queryName); } if (innerHit != null) { builder.startObject("inner_hits"); builder.value(innerHit); builder.endObject(); } builder.endObject(); }
Example 5
Source File: PlainIndexableObject.java From elasticsearch-gatherer with Apache License 2.0 | 6 votes |
protected void build(XContentBuilder builder, List list) throws IOException { builder.startArray(); for (Object o : list) { if (o instanceof Values) { Values v = (Values) o; v.build(builder); } else if (o instanceof Map) { build(builder, (Map<String, Object>) o); } else if (o instanceof List) { build(builder, (List) o); } else { try { builder.value(o); } catch (Exception e) { throw new IOException("unknown object class:" + o.getClass().getName()); } } } builder.endArray(); }
Example 6
Source File: CreateSnapshotRequest.java From crate with Apache License 2.0 | 6 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field("repository", repository); builder.field("snapshot", snapshot); builder.startArray("indices"); for (String index : indices) { builder.value(index); } builder.endArray(); builder.field("partial", partial); if (settings != null) { builder.startObject("settings"); if (settings.isEmpty() == false) { settings.toXContent(builder, params); } builder.endObject(); } builder.field("include_global_state", includeGlobalState); if (indicesOptions != null) { indicesOptions.toXContent(builder, params); } builder.endObject(); return builder; }
Example 7
Source File: RestoreInProgress.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Serializes single restore operation * * @param entry restore operation metadata * @param builder XContent builder * @param params serialization parameters */ public void toXContent(Entry entry, XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(); builder.field("snapshot", entry.snapshotId().getSnapshot()); builder.field("repository", entry.snapshotId().getRepository()); builder.field("state", entry.state()); builder.startArray("indices"); { for (String index : entry.indices()) { builder.value(index); } } builder.endArray(); builder.startArray("shards"); { for (Map.Entry<ShardId, ShardRestoreStatus> shardEntry : entry.shards.entrySet()) { ShardId shardId = shardEntry.getKey(); ShardRestoreStatus status = shardEntry.getValue(); builder.startObject(); { builder.field("index", shardId.getIndex()); builder.field("shard", shardId.getId()); builder.field("state", status.state()); } builder.endObject(); } } builder.endArray(); builder.endObject(); }
Example 8
Source File: ResultToXContentBuilder.java From crate with Apache License 2.0 | 5 votes |
private void toXContentNestedDataType(XContentBuilder builder, DataType dataType) throws IOException { if (dataType instanceof ArrayType) { builder.startArray(); builder.value(dataType.id()); toXContentNestedDataType(builder, ((ArrayType) dataType).innerType()); builder.endArray(); } else { builder.value(dataType.id()); } }
Example 9
Source File: FieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (!copyToFields.isEmpty()) { builder.startArray("copy_to"); for (String field : copyToFields) { builder.value(field); } builder.endArray(); } return builder; }
Example 10
Source File: HasChildQueryBuilder.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(HasChildQueryParser.NAME); builder.field("query"); queryBuilder.toXContent(builder, params); builder.field("child_type", childType); if (boost != 1.0f) { builder.field("boost", boost); } if (scoreMode != null) { builder.field("score_mode", scoreMode); } if (minChildren != null) { builder.field("min_children", minChildren); } if (maxChildren != null) { builder.field("max_children", maxChildren); } if (shortCircuitCutoff != null) { builder.field("short_circuit_cutoff", shortCircuitCutoff); } if (queryName != null) { builder.field("_name", queryName); } if (innerHit != null) { builder.startObject("inner_hits"); builder.value(innerHit); builder.endObject(); } builder.endObject(); }
Example 11
Source File: EntityMapper.java From eplmp with Eclipse Public License 1.0 | 5 votes |
private static void addCommonJSONFields(XContentBuilder tmp, User author, Set<Tag> tags, List<InstanceAttribute> instanceAttributes, Map<String, String> contentInputs, Workflow workflow) throws IOException { setField(tmp, IndexerMapping.AUTHOR_LOGIN_KEY, author.getLogin()); setField(tmp, IndexerMapping.AUTHOR_NAME_KEY, author.getName()); if (!tags.isEmpty()) { tmp.startArray(IndexerMapping.TAGS_KEY); for (Tag tag : tags) { tmp.value(tag.getLabel()); } tmp.endArray(); } if (!instanceAttributes.isEmpty()) { tmp.startArray(IndexerMapping.ATTRIBUTES_KEY); for (InstanceAttribute attr : instanceAttributes) { tmp.startObject(); setAttrField(tmp, attr); tmp.endObject(); } tmp.endArray(); } if (!contentInputs.isEmpty()) { tmp.startArray(IndexerMapping.FILES_KEY); for (Map.Entry<String, String> contentInput : contentInputs.entrySet()) { tmp.startObject(); setField(tmp, IndexerMapping.FILE_NAME_KEY, contentInput.getKey()); setField(tmp, IndexerMapping.CONTENT_KEY, contentInput.getValue()); tmp.endObject(); } tmp.endArray(); } if(workflow != null) { setField(tmp, IndexerMapping.WORKFLOW_KEY, workflow.getFinalLifeCycleState()); } }
Example 12
Source File: RootObjectMapper.java From crate with Apache License 2.0 | 5 votes |
@Override protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { final boolean includeDefaults = params.paramAsBoolean("include_defaults", false); if (dynamicDateTimeFormatters.explicit() || includeDefaults) { builder.startArray("dynamic_date_formats"); for (FormatDateTimeFormatter dateTimeFormatter : dynamicDateTimeFormatters.value()) { builder.value(dateTimeFormatter.format()); } builder.endArray(); } if (dynamicTemplates.explicit() || includeDefaults) { builder.startArray("dynamic_templates"); for (DynamicTemplate dynamicTemplate : dynamicTemplates.value()) { builder.startObject(); builder.field(dynamicTemplate.name(), dynamicTemplate); builder.endObject(); } builder.endArray(); } if (dateDetection.explicit() || includeDefaults) { builder.field("date_detection", dateDetection.value()); } if (numericDetection.explicit() || includeDefaults) { builder.field("numeric_detection", numericDetection.value()); } }
Example 13
Source File: IndicesOptions.java From crate with Apache License 2.0 | 5 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startArray("expand_wildcards"); for (WildcardStates expandWildcard : expandWildcards) { builder.value(expandWildcard.toString().toLowerCase(Locale.ROOT)); } builder.endArray(); builder.field("ignore_unavailable", ignoreUnavailable()); builder.field("allow_no_indices", allowNoIndices()); return builder; }
Example 14
Source File: InternalBucketMetricValue.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { boolean hasValue = !Double.isInfinite(value); builder.field(CommonFields.VALUE, hasValue ? value : null); if (hasValue && !(valueFormatter instanceof ValueFormatter.Raw)) { builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(value)); } builder.startArray("keys"); for (String key : keys) { builder.value(key); } builder.endArray(); return builder; }
Example 15
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 16
Source File: ClusterIndexHealth.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field(Fields.STATUS, getStatus().name().toLowerCase(Locale.ROOT)); builder.field(Fields.NUMBER_OF_SHARDS, getNumberOfShards()); builder.field(Fields.NUMBER_OF_REPLICAS, getNumberOfReplicas()); builder.field(Fields.ACTIVE_PRIMARY_SHARDS, getActivePrimaryShards()); builder.field(Fields.ACTIVE_SHARDS, getActiveShards()); builder.field(Fields.RELOCATING_SHARDS, getRelocatingShards()); builder.field(Fields.INITIALIZING_SHARDS, getInitializingShards()); builder.field(Fields.UNASSIGNED_SHARDS, getUnassignedShards()); if (!getValidationFailures().isEmpty()) { builder.startArray(Fields.VALIDATION_FAILURES); for (String validationFailure : getValidationFailures()) { builder.value(validationFailure); } builder.endArray(); } if ("shards".equals(params.param("level", "indices"))) { builder.startObject(Fields.SHARDS); for (ClusterShardHealth shardHealth : shards.values()) { builder.startObject(Integer.toString(shardHealth.getId())); builder.field(Fields.STATUS, shardHealth.getStatus().name().toLowerCase(Locale.ROOT)); builder.field(Fields.PRIMARY_ACTIVE, shardHealth.isPrimaryActive()); builder.field(Fields.ACTIVE_SHARDS, shardHealth.getActiveShards()); builder.field(Fields.RELOCATING_SHARDS, shardHealth.getRelocatingShards()); builder.field(Fields.INITIALIZING_SHARDS, shardHealth.getInitializingShards()); builder.field(Fields.UNASSIGNED_SHARDS, shardHealth.getUnassignedShards()); builder.endObject(); } builder.endObject(); } return builder; }
Example 17
Source File: FieldMapper.java From crate with Apache License 2.0 | 5 votes |
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (!copyToFields.isEmpty()) { builder.startArray("copy_to"); for (String field : copyToFields) { builder.value(field); } builder.endArray(); } return builder; }
Example 18
Source File: TransportAddress.java From crate with Apache License 2.0 | 4 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { return builder.value(toString()); }
Example 19
Source File: Version.java From crate with Apache License 2.0 | 4 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { return builder.value(toString()); }
Example 20
Source File: SnapshotInfo.java From crate with Apache License 2.0 | 4 votes |
@Override public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { // write snapshot info to repository snapshot blob format if (CONTEXT_MODE_SNAPSHOT.equals(params.param(CONTEXT_MODE_PARAM))) { return toXContentInternal(builder, params); } final boolean verbose = params.paramAsBoolean("verbose", GetSnapshotsRequest.DEFAULT_VERBOSE_MODE); // write snapshot info for the API and any other situations builder.startObject(); builder.field(SNAPSHOT, snapshotId.getName()); builder.field(UUID, snapshotId.getUUID()); if (version != null) { builder.field(VERSION_ID, version.internalId); builder.field(VERSION, version.toString()); } builder.startArray(INDICES); for (String index : indices) { builder.value(index); } builder.endArray(); if (includeGlobalState != null) { builder.field(INCLUDE_GLOBAL_STATE, includeGlobalState); } if (verbose || state != null) { builder.field(STATE, state); } if (reason != null) { builder.field(REASON, reason); } if (verbose || startTime != 0) { builder.field(START_TIME, DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(startTime).atZone(ZoneOffset.UTC))); builder.field(START_TIME_IN_MILLIS, startTime); } if (verbose || endTime != 0) { builder.field(END_TIME, DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(endTime).atZone(ZoneOffset.UTC))); builder.field(END_TIME_IN_MILLIS, endTime); builder.humanReadableField(DURATION_IN_MILLIS, DURATION, new TimeValue(endTime - startTime)); } if (verbose || !shardFailures.isEmpty()) { builder.startArray(FAILURES); for (SnapshotShardFailure shardFailure : shardFailures) { builder.startObject(); shardFailure.toXContent(builder, params); builder.endObject(); } builder.endArray(); } if (verbose || totalShards != 0) { builder.startObject(SHARDS); builder.field(TOTAL, totalShards); builder.field(FAILED, failedShards()); builder.field(SUCCESSFUL, successfulShards); builder.endObject(); } builder.endObject(); return builder; }