Java Code Examples for org.elasticsearch.common.xcontent.XContentBuilder#field()
The following examples show how to use
org.elasticsearch.common.xcontent.XContentBuilder#field() .
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: CompletionFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(simpleName()) .field(Fields.TYPE, CONTENT_TYPE); builder.field(Fields.ANALYZER, fieldType().indexAnalyzer().name()); if (fieldType().indexAnalyzer().name().equals(fieldType().searchAnalyzer().name()) == false) { builder.field(Fields.SEARCH_ANALYZER.getPreferredName(), fieldType().searchAnalyzer().name()); } builder.field(Fields.PAYLOADS, fieldType().analyzingSuggestLookupProvider.hasPayloads()); builder.field(Fields.PRESERVE_SEPARATORS.getPreferredName(), fieldType().analyzingSuggestLookupProvider.getPreserveSep()); builder.field(Fields.PRESERVE_POSITION_INCREMENTS.getPreferredName(), fieldType().analyzingSuggestLookupProvider.getPreservePositionsIncrements()); builder.field(Fields.MAX_INPUT_LENGTH.getPreferredName(), this.maxInputLength); multiFields.toXContent(builder, params); if (fieldType().requiresContext()) { builder.startObject(Fields.CONTEXT); for (ContextMapping mapping : fieldType().getContextMapping().values()) { builder.value(mapping); } builder.endObject(); } return builder.endObject(); }
Example 2
Source File: SearchIntoResponse.java From elasticsearch-inout-plugin with Apache License 2.0 | 6 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.startArray("writes"); for (ShardSearchIntoResponse r : this.responses) { r.toXContent(builder, params); } builder.endArray(); builder.field("total", totalWrites); builder.field("succeeded", succeededWrites); builder.field("failed", failedWrites); buildBroadcastShardsHeader(builder, this); builder.endObject(); return builder; }
Example 3
Source File: InternalRange.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (keyed) { builder.startObject(key); } else { builder.startObject(); builder.field(CommonFields.KEY, key); } if (!Double.isInfinite(from)) { builder.field(CommonFields.FROM, from); if (formatter != null) { builder.field(CommonFields.FROM_AS_STRING, formatter.format(from)); } } if (!Double.isInfinite(to)) { builder.field(CommonFields.TO, to); if (formatter != null) { builder.field(CommonFields.TO_AS_STRING, formatter.format(to)); } } builder.field(CommonFields.DOC_COUNT, docCount); aggregations.toXContentInternal(builder, params); builder.endObject(); return builder; }
Example 4
Source File: ElasticSearchJsonBoltTest.java From cognition with Apache License 2.0 | 5 votes |
@Test public void testAddFieldByTypeMicroseconds(@Injectable XContentBuilder source, @Injectable String key, @Injectable Map<String, String> fieldTypeMapping) throws IOException, ParseException { new Expectations() {{ fieldTypeMapping.get(ElasticSearchJsonBolt.FIELD_TYPE); result = "microseconds"; source.field(key, new Date(1420082040000L)); }}; bolt.addFieldByType(source, key, "1420082040", fieldTypeMapping); }
Example 5
Source File: GetStats.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.GET); builder.field(Fields.TOTAL, getCount()); builder.timeValueField(Fields.TIME_IN_MILLIS, Fields.TIME, getTimeInMillis()); builder.field(Fields.EXISTS_TOTAL, existsCount); builder.timeValueField(Fields.EXISTS_TIME_IN_MILLIS, Fields.EXISTS_TIME, existsTimeInMillis); builder.field(Fields.MISSING_TOTAL, missingCount); builder.timeValueField(Fields.MISSING_TIME_IN_MILLIS, Fields.MISSING_TIME, missingTimeInMillis); builder.field(Fields.CURRENT, current); builder.endObject(); return builder; }
Example 6
Source File: RCFResultResponse.java From anomaly-detection with Apache License 2.0 | 5 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(RCF_SCORE_JSON_KEY, rcfScore); builder.field(CONFIDENCE_JSON_KEY, confidence); builder.field(FOREST_SIZE_JSON_KEY, forestSize); builder.endObject(); return builder; }
Example 7
Source File: RecoveryState.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.NAME, name); builder.byteSizeField(Fields.LENGTH_IN_BYTES, Fields.LENGTH, length); builder.field(Fields.REUSED, reused); builder.byteSizeField(Fields.RECOVERED_IN_BYTES, Fields.RECOVERED, recovered); builder.endObject(); return builder; }
Example 8
Source File: GND.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(STREAM.getName()); builder.field(BACKGROUND_IS_SUPERSET.getPreferredName(), backgroundIsSuperset); builder.endObject(); return builder; }
Example 9
Source File: SnapshotIndexShardStatus.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Integer.toString(getShardId())); builder.field(Fields.STAGE, getStage()); stats.toXContent(builder, params); if (getNodeId() != null) { builder.field(Fields.NODE, getNodeId()); } if (getFailure() != null) { builder.field(Fields.REASON, getFailure()); } builder.endObject(); return builder; }
Example 10
Source File: InternalCardinality.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { final long cardinality = getValue(); builder.field(CommonFields.VALUE, cardinality); if (!(valueFormatter instanceof ValueFormatter.Raw)) { builder.field(CommonFields.VALUE_AS_STRING, valueFormatter.format(cardinality)); } return builder; }
Example 11
Source File: StoredFeatureNormalizers.java From elasticsearch-learning-to-rank with Apache License 2.0 | 5 votes |
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(); // begin feature norms for (Map.Entry<String, FeatureNormDefinition> ftrNormDefEntry: featureNormalizers.entrySet()) { builder.field(ftrNormDefEntry.getKey()); ftrNormDefEntry.getValue().toXContent(builder, params); } builder.endObject(); // feature norms return builder; }
Example 12
Source File: FieldStats.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.MAX_DOC, maxDoc); builder.field(Fields.DOC_COUNT, docCount); builder.field(Fields.DENSITY, getDensity()); builder.field(Fields.SUM_DOC_FREQ, sumDocFreq); builder.field(Fields.SUM_TOTAL_TERM_FREQ, sumTotalTermFreq); toInnerXContent(builder); builder.endObject(); return builder; }
Example 13
Source File: NotQueryBuilder.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NotQueryParser.NAME); builder.field("query"); filter.toXContent(builder, params); if (queryName != null) { builder.field("_name", queryName); } builder.endObject(); }
Example 14
Source File: ProfileNodeResponse.java From anomaly-detection with Apache License 2.0 | 5 votes |
/** * Converts profile to xContent * * @param builder XContentBuilder * @param params Params * @return XContentBuilder * @throws IOException thrown by builder for invalid field */ @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(MODEL_SIZE_IN_BYTES); for (Map.Entry<String, Long> entry : modelSize.entrySet()) { builder.field(entry.getKey(), entry.getValue()); } builder.endObject(); builder.field(SHINGLE_SIZE, shingleSize); return builder; }
Example 15
Source File: TokenCountFieldMapper.java From elasticsearch-mapper with Apache License 2.0 | 5 votes |
public static void mapDataType(XContentBuilder mappingBuilder, TokenCountField tokenCountField) throws IOException { mappingBuilder.field("type", "token_count"); mappingBuilder.field("analyzer", tokenCountField.analyzer()); if (!tokenCountField.enable_position_increments()) { mappingBuilder.field("enable_position_increments", tokenCountField.enable_position_increments()); } if (tokenCountField.boost() != 1.0f) { mappingBuilder.field("boost", tokenCountField.boost()); } if (!tokenCountField.doc_values()) { mappingBuilder.field("doc_values", tokenCountField.doc_values()); } if (!tokenCountField.include_in_all()) { mappingBuilder.field("include_in_all", tokenCountField.include_in_all()); } else if (!tokenCountField.index()) { mappingBuilder.field("include_in_all", false); } if (!tokenCountField.index()) { mappingBuilder.field("index", tokenCountField.index()); } if (StringUtils.isNotBlank(tokenCountField.null_value())) { mappingBuilder.field("null_value", tokenCountField.null_value()); } if (tokenCountField.store()) { mappingBuilder.field("store", tokenCountField.store()); } }
Example 16
Source File: FieldStats.java From Elasticsearch with Apache License 2.0 | 4 votes |
protected void toInnerXContent(XContentBuilder builder) throws IOException { builder.field(Fields.MIN_VALUE, getMinValue()); builder.field(Fields.MIN_VALUE_AS_STRING, getMinValueAsString()); builder.field(Fields.MAX_VALUE, getMaxValue()); builder.field(Fields.MAX_VALUE_AS_STRING, getMaxValueAsString()); }
Example 17
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; }
Example 18
Source File: DiskUsage.java From crate with Apache License 2.0 | 4 votes |
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("node_id", this.nodeId); builder.field("node_name", this.nodeName); builder = toShortXContent(builder); return builder; }
Example 19
Source File: Elasticsearch5SearchIndex.java From vertexium with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void updateMetadata(Graph graph, IndexInfo indexInfo) { try { indexRefreshTracker.refresh(client, indexInfo.getIndexName()); XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() .startObject(getIdStrategy().getType()); GetMappingsResponse existingMapping = getClient() .admin() .indices() .prepareGetMappings(indexInfo.getIndexName()) .execute() .actionGet(); Map<String, Object> existingElementData = existingMapping.mappings() .get(indexInfo.getIndexName()) .get(getIdStrategy().getType()) .getSourceAsMap(); mapping = mapping.startObject("_meta") .startObject("vertexium"); Map<String, Object> properties = (Map<String, Object>) existingElementData.get("properties"); for (String propertyName : properties.keySet()) { ElasticsearchPropertyNameInfo p = ElasticsearchPropertyNameInfo.parse(graph, propertyNameVisibilitiesStore, propertyName); if (p == null || p.getPropertyVisibility() == null) { continue; } mapping.field(replaceFieldnameDots(propertyName), p.getPropertyVisibility()); } mapping.endObject() .endObject() .endObject() .endObject(); getClient() .admin() .indices() .preparePutMapping(indexInfo.getIndexName()) .setType(getIdStrategy().getType()) .setSource(mapping) .execute() .actionGet(); } catch (IOException ex) { throw new VertexiumException("Could not update mapping", ex); } }
Example 20
Source File: NodeMetaData.java From crate with Apache License 2.0 | 4 votes |
@Override public void toXContent(XContentBuilder builder, NodeMetaData nodeMetaData) throws IOException { builder.field(NODE_ID_KEY, nodeMetaData.nodeId); }