Search in sources :

Example 1 with ElasticsearchGenerationException

use of org.elasticsearch.ElasticsearchGenerationException in project elasticsearch by elastic.

the class MapperService method internalMerge.

private synchronized Map<String, DocumentMapper> internalMerge(Map<String, CompressedXContent> mappings, MergeReason reason, boolean updateAllTypes) {
    DocumentMapper defaultMapper = null;
    String defaultMappingSource = null;
    if (mappings.containsKey(DEFAULT_MAPPING)) {
        // NOTE: never apply the default here
        try {
            defaultMapper = documentParser.parse(DEFAULT_MAPPING, mappings.get(DEFAULT_MAPPING));
        } catch (Exception e) {
            throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, DEFAULT_MAPPING, e.getMessage());
        }
        try {
            defaultMappingSource = mappings.get(DEFAULT_MAPPING).string();
        } catch (IOException e) {
            throw new ElasticsearchGenerationException("failed to un-compress", e);
        }
    }
    final String defaultMappingSourceOrLastStored;
    if (defaultMappingSource != null) {
        defaultMappingSourceOrLastStored = defaultMappingSource;
    } else {
        defaultMappingSourceOrLastStored = this.defaultMappingSource;
    }
    List<DocumentMapper> documentMappers = new ArrayList<>();
    for (Map.Entry<String, CompressedXContent> entry : mappings.entrySet()) {
        String type = entry.getKey();
        if (type.equals(DEFAULT_MAPPING)) {
            continue;
        }
        final boolean applyDefault = // the default was already applied if we are recovering
        reason != MergeReason.MAPPING_RECOVERY && // only apply the default mapping if we don't have the type yet
        mappers.containsKey(type) == false;
        try {
            DocumentMapper documentMapper = documentParser.parse(type, entry.getValue(), applyDefault ? defaultMappingSourceOrLastStored : null);
            documentMappers.add(documentMapper);
        } catch (Exception e) {
            throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, entry.getKey(), e.getMessage());
        }
    }
    return internalMerge(defaultMapper, defaultMappingSource, documentMappers, reason, updateAllTypes);
}
Also used : ArrayList(java.util.ArrayList) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) IOException(java.io.IOException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) InvalidTypeNameException(org.elasticsearch.indices.InvalidTypeNameException) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException) IOException(java.io.IOException) TypeMissingException(org.elasticsearch.indices.TypeMissingException) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException)

Example 2 with ElasticsearchGenerationException

use of org.elasticsearch.ElasticsearchGenerationException in project elasticsearch by elastic.

the class CreateIndexRequest method mapping.

/**
     * Adds mapping that will be added when the index gets created.
     *
     * @param type   The mapping type
     * @param source The mapping source
     */
@SuppressWarnings("unchecked")
public CreateIndexRequest mapping(String type, Map source) {
    if (mappings.containsKey(type)) {
        throw new IllegalStateException("mappings for type \"" + type + "\" were already defined");
    }
    // wrap it in a type map if its not
    if (source.size() != 1 || !source.containsKey(type)) {
        source = MapBuilder.<String, Object>newMapBuilder().put(type, source).map();
    }
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        return mapping(type, builder);
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
}
Also used : IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException)

Example 3 with ElasticsearchGenerationException

use of org.elasticsearch.ElasticsearchGenerationException in project elasticsearch by elastic.

the class Alias method filter.

/**
     * Associates a filter to the alias
     */
public Alias 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 = builder.string();
        return this;
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + filter + "]", e);
    }
}
Also used : IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException)

Example 4 with ElasticsearchGenerationException

use of org.elasticsearch.ElasticsearchGenerationException in project elasticsearch by elastic.

the class PutRepositoryRequest method settings.

/**
     * Sets the repository settings.
     *
     * @param source repository settings
     * @return this request
     */
public PutRepositoryRequest settings(Map<String, Object> source) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        settings(builder.string(), builder.contentType());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
    return this;
}
Also used : IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException)

Example 5 with ElasticsearchGenerationException

use of org.elasticsearch.ElasticsearchGenerationException in project elasticsearch by elastic.

the class RestoreSnapshotRequest method indexSettings.

/**
     * 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(builder.string(), builder.contentType());
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
    return this;
}
Also used : IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException)

Aggregations

IOException (java.io.IOException)36 ElasticsearchGenerationException (org.elasticsearch.ElasticsearchGenerationException)36 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)34 UncheckedIOException (java.io.UncheckedIOException)14 BytesReference (org.elasticsearch.common.bytes.BytesReference)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 FileContext (org.apache.hadoop.fs.FileContext)1 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)1 XContentType (org.elasticsearch.common.xcontent.XContentType)1 GetResult (org.elasticsearch.index.get.GetResult)1 InvalidTypeNameException (org.elasticsearch.indices.InvalidTypeNameException)1 TypeMissingException (org.elasticsearch.indices.TypeMissingException)1