diff --git a/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java b/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java index 85300b437d9..7808b60e08c 100644 --- a/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java @@ -29,12 +29,15 @@ import org.apache.lucene.document.FieldType; import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.Filter; import org.apache.lucene.util.CloseableThreadLocal; +import org.elasticsearch.ElasticSearchGenerationException; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Preconditions; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.compress.CompressedString; +import org.elasticsearch.common.compress.CompressorFactory; +import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.text.StringAndBytesText; import org.elasticsearch.common.text.Text; @@ -655,15 +658,17 @@ public class DocumentMapper implements ToXContent { return new MergeResult(mergeContext.buildConflicts()); } - public CompressedString refreshSource() throws FailedToGenerateSourceMapperException { + public CompressedString refreshSource() throws ElasticSearchGenerationException { try { - XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); + BytesStreamOutput bStream = new BytesStreamOutput(); + XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON, CompressorFactory.defaultCompressor().streamOutput(bStream)); builder.startObject(); toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); - return mappingSource = new CompressedString(builder.bytes()); + builder.close(); + return mappingSource = new CompressedString(bStream.bytes()); } catch (Exception e) { - throw new FailedToGenerateSourceMapperException(e.getMessage(), e); + throw new ElasticSearchGenerationException("failed to serialize source for type [" + type + "]", e); } } diff --git a/src/main/java/org/elasticsearch/index/mapper/FailedToGenerateSourceMapperException.java b/src/main/java/org/elasticsearch/index/mapper/FailedToGenerateSourceMapperException.java deleted file mode 100644 index 11521150757..00000000000 --- a/src/main/java/org/elasticsearch/index/mapper/FailedToGenerateSourceMapperException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.mapper; - -/** - * - */ -public class FailedToGenerateSourceMapperException extends MapperException { - - public FailedToGenerateSourceMapperException(String message) { - super(message); - } - - public FailedToGenerateSourceMapperException(String message, Throwable cause) { - super(message, cause); - } -}