mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-29 01:44:36 -04:00
DocumentMapper to not implement ToXContent (#68653)
DocumentMapper does not need to implement ToXContent, in fact it is its inner Mapping that needs to and already does. Consumers can switch to calling mapping() and toXContent against it.
This commit is contained in:
parent
8d975d2ae6
commit
0ca6819882
6 changed files with 13 additions and 22 deletions
|
@ -434,7 +434,7 @@ public class AnnotatedTextFieldMapperTests extends MapperTestCase {
|
||||||
|
|
||||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
mapper.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true")));
|
mapper.mapping().toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true")));
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
String mappingString = Strings.toString(builder);
|
String mappingString = Strings.toString(builder);
|
||||||
|
|
|
@ -14,21 +14,18 @@ import org.elasticsearch.ElasticsearchGenerationException;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.compress.CompressedXContent;
|
import org.elasticsearch.common.compress.CompressedXContent;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.ToXContentFragment;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.index.IndexSettings;
|
import org.elasticsearch.index.IndexSettings;
|
||||||
import org.elasticsearch.index.analysis.IndexAnalyzers;
|
import org.elasticsearch.index.analysis.IndexAnalyzers;
|
||||||
import org.elasticsearch.index.mapper.MapperService.MergeReason;
|
import org.elasticsearch.index.mapper.MapperService.MergeReason;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class DocumentMapper implements ToXContentFragment {
|
public class DocumentMapper {
|
||||||
private final String type;
|
private final String type;
|
||||||
private final CompressedXContent mappingSource;
|
private final CompressedXContent mappingSource;
|
||||||
private final DocumentParser documentParser;
|
private final DocumentParser documentParser;
|
||||||
|
@ -56,7 +53,7 @@ public class DocumentMapper implements ToXContentFragment {
|
||||||
this.mappingLookup = MappingLookup.fromMapping(mapping, documentParser, indexSettings, indexAnalyzers);
|
this.mappingLookup = MappingLookup.fromMapping(mapping, documentParser, indexSettings, indexAnalyzers);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mappingSource = new CompressedXContent(this, XContentType.JSON, ToXContent.EMPTY_PARAMS);
|
mappingSource = new CompressedXContent(mapping, XContentType.JSON, ToXContent.EMPTY_PARAMS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ElasticsearchGenerationException("failed to serialize source for type [" + type + "]", e);
|
throw new ElasticsearchGenerationException("failed to serialize source for type [" + type + "]", e);
|
||||||
}
|
}
|
||||||
|
@ -155,9 +152,4 @@ public class DocumentMapper implements ToXContentFragment {
|
||||||
this.mappingLookup.checkLimits(settings);
|
this.mappingLookup.checkLimits(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
||||||
return mapping().toXContent(builder, params);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,10 +235,9 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
|
||||||
assert currentSource.equals(newSource) :
|
assert currentSource.equals(newSource) :
|
||||||
"expected current mapping [" + currentSource + "] for type [" + mapping.type() + "] "
|
"expected current mapping [" + currentSource + "] for type [" + mapping.type() + "] "
|
||||||
+ "to be the same as new mapping [" + newSource + "]";
|
+ "to be the same as new mapping [" + newSource + "]";
|
||||||
final CompressedXContent mapperSource = new CompressedXContent(Strings.toString(mapper));
|
assert currentSource.equals(mapper.mappingSource()) :
|
||||||
assert currentSource.equals(mapperSource) :
|
|
||||||
"expected current mapping [" + currentSource + "] for type [" + mapping.type() + "] "
|
"expected current mapping [" + currentSource + "] for type [" + mapping.type() + "] "
|
||||||
+ "to be the same as new mapping [" + mapperSource + "]";
|
+ "to be the same as new mapping [" + mapper.mappingSource() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -336,10 +336,10 @@ public class ParametrizedMapperTests extends MapperServiceTestCase {
|
||||||
"\"is_interim\":{\"type\":\"boolean\"}}}}}}";
|
"\"is_interim\":{\"type\":\"boolean\"}}}}}}";
|
||||||
|
|
||||||
MapperService mapperService = createMapperService(mapping);
|
MapperService mapperService = createMapperService(mapping);
|
||||||
assertEquals(mapping, Strings.toString(mapperService.documentMapper()));
|
assertEquals(mapping, Strings.toString(mapperService.documentMapper().mapping()));
|
||||||
|
|
||||||
mapperService.merge("_doc", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
|
mapperService.merge("_doc", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
|
||||||
assertEquals(mapping, Strings.toString(mapperService.documentMapper()));
|
assertEquals(mapping, Strings.toString(mapperService.documentMapper().mapping()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// test custom serializer
|
// test custom serializer
|
||||||
|
|
|
@ -255,7 +255,7 @@ public class TextFieldMapperTests extends MapperTestCase {
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"_doc\":{\"properties\":{\"field\":{\"type\":\"text\",\"fields\":{\"subfield\":{\"type\":\"long\"}},\"fielddata\":true}}}}",
|
"{\"_doc\":{\"properties\":{\"field\":{\"type\":\"text\",\"fields\":{\"subfield\":{\"type\":\"long\"}},\"fielddata\":true}}}}",
|
||||||
Strings.toString(mapperService.documentMapper()));
|
Strings.toString(mapperService.documentMapper().mapping()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEnableStore() throws IOException {
|
public void testEnableStore() throws IOException {
|
||||||
|
@ -295,7 +295,7 @@ public class TextFieldMapperTests extends MapperTestCase {
|
||||||
mapping.endObject().endObject().endObject();
|
mapping.endObject().endObject().endObject();
|
||||||
|
|
||||||
DocumentMapper mapper = createDocumentMapper(mapping);
|
DocumentMapper mapper = createDocumentMapper(mapping);
|
||||||
String serialized = Strings.toString(mapper);
|
String serialized = Strings.toString(mapper.mapping());
|
||||||
assertThat(serialized, containsString("\"offsets\":{\"type\":\"text\",\"index_options\":\"offsets\"}"));
|
assertThat(serialized, containsString("\"offsets\":{\"type\":\"text\",\"index_options\":\"offsets\"}"));
|
||||||
assertThat(serialized, containsString("\"freqs\":{\"type\":\"text\",\"index_options\":\"freqs\"}"));
|
assertThat(serialized, containsString("\"freqs\":{\"type\":\"text\",\"index_options\":\"freqs\"}"));
|
||||||
assertThat(serialized, containsString("\"docs\":{\"type\":\"text\",\"index_options\":\"docs\"}"));
|
assertThat(serialized, containsString("\"docs\":{\"type\":\"text\",\"index_options\":\"docs\"}"));
|
||||||
|
@ -370,7 +370,7 @@ public class TextFieldMapperTests extends MapperTestCase {
|
||||||
|
|
||||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
createDocumentMapper(fieldMapping(this::minimalMapping)).toXContent(
|
createDocumentMapper(fieldMapping(this::minimalMapping)).mapping().toXContent(
|
||||||
builder,
|
builder,
|
||||||
new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true"))
|
new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true"))
|
||||||
);
|
);
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class DateScriptFieldTypeTests extends AbstractNonTextScriptFieldTypeTest
|
||||||
MapperService mapperService = createMapperService(mapping.get());
|
MapperService mapperService = createMapperService(mapping.get());
|
||||||
MappedFieldType fieldType = mapperService.fieldType("field");
|
MappedFieldType fieldType = mapperService.fieldType("field");
|
||||||
assertThat(fieldType, instanceOf(DateScriptFieldType.class));
|
assertThat(fieldType, instanceOf(DateScriptFieldType.class));
|
||||||
assertEquals(Strings.toString(mapping.get()), Strings.toString(mapperService.documentMapper()));
|
assertEquals(Strings.toString(mapping.get()), Strings.toString(mapperService.documentMapper().mapping()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDateWithLocale() throws IOException {
|
public void testDateWithLocale() throws IOException {
|
||||||
|
@ -105,7 +105,7 @@ public class DateScriptFieldTypeTests extends AbstractNonTextScriptFieldTypeTest
|
||||||
MapperService mapperService = createMapperService(mapping.get());
|
MapperService mapperService = createMapperService(mapping.get());
|
||||||
MappedFieldType fieldType = mapperService.fieldType("field");
|
MappedFieldType fieldType = mapperService.fieldType("field");
|
||||||
assertThat(fieldType, instanceOf(DateScriptFieldType.class));
|
assertThat(fieldType, instanceOf(DateScriptFieldType.class));
|
||||||
assertEquals(Strings.toString(mapping.get()), Strings.toString(mapperService.documentMapper()));
|
assertEquals(Strings.toString(mapping.get()), Strings.toString(mapperService.documentMapper().mapping()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDateWithLocaleAndFormat() throws IOException {
|
public void testDateWithLocaleAndFormat() throws IOException {
|
||||||
|
@ -116,7 +116,7 @@ public class DateScriptFieldTypeTests extends AbstractNonTextScriptFieldTypeTest
|
||||||
MapperService mapperService = createMapperService(mapping.get());
|
MapperService mapperService = createMapperService(mapping.get());
|
||||||
MappedFieldType fieldType = mapperService.fieldType("field");
|
MappedFieldType fieldType = mapperService.fieldType("field");
|
||||||
assertThat(fieldType, instanceOf(DateScriptFieldType.class));
|
assertThat(fieldType, instanceOf(DateScriptFieldType.class));
|
||||||
assertEquals(Strings.toString(mapping.get()), Strings.toString(mapperService.documentMapper()));
|
assertEquals(Strings.toString(mapping.get()), Strings.toString(mapperService.documentMapper().mapping()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFormat() throws IOException {
|
public void testFormat() throws IOException {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue