private void writeMappings(ImmutableOpenMap<String, MappingMetaData> mappings, XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(Fields.MAPPINGS); if (mappings != null) { for (ObjectObjectCursor<String, MappingMetaData> typeEntry : mappings) { builder.field(typeEntry.key); builder.map(typeEntry.value.sourceAsMap()); } } builder.endObject(); }
private XContentBuilder build(final DBObject data, final String objectId) throws IOException { if (data instanceof GridFSDBFile) { logger.info("Add Attachment: {} to index {} / type {}", objectId, definition.getIndexName(), definition.getTypeName()); return MongoDBHelper.serialize((GridFSDBFile) data); } else { Map<String, Object> mapData = this.createObjectMap(data); return XContentFactory.jsonBuilder().map(mapData); } }
public void merge(Map<String, Map<String, Object>> mappings, MergeReason reason, boolean updateAllTypes) { Map<String, CompressedXContent> mappingSourcesCompressed = new LinkedHashMap<>(mappings.size()); for (Map.Entry<String, Map<String, Object>> entry : mappings.entrySet()) { try { mappingSourcesCompressed.put(entry.getKey(), new CompressedXContent(Strings.toString( XContentFactory.jsonBuilder().map(entry.getValue())))); } catch (Exception e) { throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, entry.getKey(), e.getMessage()); } } internalMerge(mappingSourcesCompressed, reason, updateAllTypes); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("since", sinceTime); if (restUsage != null) { builder.field("rest_actions"); builder.map(restUsage); } return builder; }
@Override public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { // Concatenates the type and the name of the aggregation (ex: top_hits#foo) builder.startObject(String.join(InternalAggregation.TYPED_KEYS_DELIMITER, getType(), name)); if (this.metadata != null) { builder.field(InternalAggregation.CommonFields.META.getPreferredName()); builder.map(this.metadata); } doXContentBody(builder, params); builder.endObject(); return builder; }
public MappingMetaData(String type, Map<String, Object> mapping) throws IOException { this.type = type; XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().map(mapping); this.source = new CompressedXContent(BytesReference.bytes(mappingBuilder)); Map<String, Object> withoutType = mapping; if (mapping.size() == 1 && mapping.containsKey(type)) { withoutType = (Map<String, Object>) mapping.get(type); } initMappers(withoutType); }
public AliasActions 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 = Strings.toString(builder); return this; } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + filter + "]", e); } }
public Builder filter(Map<String, Object> filter) { if (filter == null || filter.isEmpty()) { this.filter = null; return this; } try { XContentBuilder builder = XContentFactory.jsonBuilder().map(filter); this.filter = new CompressedXContent(BytesReference.bytes(builder)); return this; } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to build json for alias request", e); } }
/** * Index the Map as the provided content type. * * @param source The map to index */ public IndexRequest source(Map source, XContentType contentType) throws ElasticsearchGenerationException { try { XContentBuilder builder = XContentFactory.contentBuilder(contentType); builder.map(source); return source(builder); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } }
NameOrDefinition(Map<String, ?> definition) { this.name = null; Objects.requireNonNull(definition); try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(definition); this.definition = Settings.builder().loadFromSource(Strings.toString(builder), builder.contentType()).build(); } catch (IOException e) { throw new IllegalArgumentException("Failed to parse [" + definition + "]", e); } }
/** * The mapping source definition. */ @SuppressWarnings("unchecked") public PutMappingRequest source(Map mappingSource) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(mappingSource); return source(Strings.toString(builder), XContentType.JSON); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + mappingSource + "]", e); } }
/** * The settings to create the index template with (either json or yaml format). */ public PutIndexTemplateRequest settings(Map<String, Object> source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); settings(Strings.toString(builder), XContentType.JSON); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
/** * Sets the aliases that will be associated with the index when it gets created */ @SuppressWarnings("unchecked") public CreateIndexRequest aliases(Map source) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); return aliases(BytesReference.bytes(builder)); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } }
/** * Sets the aliases that will be associated with the index when it gets created */ @SuppressWarnings("unchecked") public PutIndexTemplateRequest aliases(Map source) { try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); return aliases(BytesReference.bytes(builder)); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } }
/** * The settings to create the index with (either json/yaml/properties format) */ @SuppressWarnings("unchecked") public CreateIndexRequest settings(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); settings(Strings.toString(builder), XContentType.JSON); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
private static Script extractConditional(Map<String, Object> config) throws IOException { Object scriptSource = config.remove("if"); if (scriptSource != null) { try (XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent) .map(normalizeScript(scriptSource)); InputStream stream = BytesReference.bytes(builder).streamInput(); XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream)) { return Script.parse(parser); } } return null; }
/** * 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(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
/** * Sets the transient settings to be updated. They will not survive a full cluster restart */ @SuppressWarnings({"unchecked", "rawtypes"}) public ClusterUpdateSettingsRequest transientSettings(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); transientSettings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
/** * Sets the settings to be updated (either json or yaml format) */ @SuppressWarnings("unchecked") public UpdateSettingsRequest settings(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); settings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
/** * Sets the persistent settings to be updated. They will get applied cross restarts */ @SuppressWarnings({"unchecked", "rawtypes"}) public ClusterUpdateSettingsRequest persistentSettings(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); persistentSettings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }