Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.IndexAnalyzers;

import java.util.Collections;

public class DocumentMapper {
private final String type;
private final CompressedXContent mappingSource;
Expand All @@ -28,7 +26,7 @@ public class DocumentMapper {
public static DocumentMapper createEmpty(MapperService mapperService) {
RootObjectMapper root = new RootObjectMapper.Builder(MapperService.SINGLE_MAPPING_NAME, Version.CURRENT).build(new ContentPath(1));
MetadataFieldMapper[] metadata = mapperService.getMetadataMappers().values().toArray(new MetadataFieldMapper[0]);
Mapping mapping = new Mapping(root, metadata, Collections.emptyMap());
Mapping mapping = new Mapping(root, metadata, null);
return new DocumentMapper(
mapperService.getIndexSettings(), mapperService.getIndexAnalyzers(), mapperService.documentParser(), mapping);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -37,9 +36,7 @@
public final class Mapping implements ToXContentFragment {

public static final Mapping EMPTY = new Mapping(
new RootObjectMapper.Builder("_doc", Version.CURRENT).build(new ContentPath()),
new MetadataFieldMapper[0],
Collections.emptyMap());
new RootObjectMapper.Builder("_doc", Version.CURRENT).build(new ContentPath()), new MetadataFieldMapper[0], null);

private final RootObjectMapper root;
private final Map<String, Object> meta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexSettings;
Expand Down Expand Up @@ -276,4 +277,16 @@ public void testMergeMetaForIndexTemplate() throws IOException {
"object", Map.of("field1", "value1", "field2", "new_value", "field3", "value3"));
assertThat(merged.getMeta(), equalTo(expected));
}

public void testEmptyDocumentMapper() {
MapperService mapperService = createMapperService(Version.CURRENT, Settings.EMPTY, () -> false);
DocumentMapper documentMapper = DocumentMapper.createEmpty(mapperService);
assertEquals("{\"_doc\":{}}", Strings.toString(documentMapper.mapping()));
assertTrue(documentMapper.mappers().hasMappings());
assertNotNull(documentMapper.idFieldMapper());
assertNotNull(documentMapper.sourceMapper());
assertNotNull(documentMapper.IndexFieldMapper());
assertEquals(10, documentMapper.mappers().getMapping().getMetadataMappersMap().size());
assertEquals(10, documentMapper.mappers().fieldTypes().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.elasticsearch.Version;
import org.elasticsearch.common.Explicit;
import org.elasticsearch.common.Strings;
import org.elasticsearch.index.analysis.AnalyzerScope;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.query.SearchExecutionContext;
Expand Down Expand Up @@ -97,6 +98,16 @@ public void testAnalyzers() throws IOException {
}).tokenStream("field3", "blah"));
}

public void testEmptyMappingLookup() {
MappingLookup mappingLookup = MappingLookup.EMPTY;
assertEquals("{\"_doc\":{}}", Strings.toString(mappingLookup.getMapping()));
assertFalse(mappingLookup.hasMappings());
assertNull(mappingLookup.getMapping().getMeta());
assertEquals(0, mappingLookup.getMapping().getMetadataMappersMap().size());
assertFalse(mappingLookup.fieldMappers().iterator().hasNext());
assertEquals(0, mappingLookup.fieldTypes().size());
}

private void assertAnalyzes(Analyzer analyzer, String field, String output) throws IOException {
try (TokenStream tok = analyzer.tokenStream(field, new StringReader(""))) {
CharTermAttribute term = tok.addAttribute(CharTermAttribute.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public List<Setting<?>> getSettings() {
}
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/72695")
public void testSnapshotAndRestore() throws Exception {
final String sourceIdx = "test-idx";
boolean requireRouting = randomBoolean();
Expand Down Expand Up @@ -129,7 +128,6 @@ public void testSnapshotAndRestore() throws Exception {
assertHits(sourceIdx, builders.length, sourceHadDeletions);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/72695")
public void testSnapshotAndRestoreWithNested() throws Exception {
final String sourceIdx = "test-idx";
boolean requireRouting = randomBoolean();
Expand Down Expand Up @@ -187,7 +185,7 @@ public void testSnapshotWithDanglingLocalSegment() throws Exception {
assertSuccessful(startFullSnapshot(repo, "snapshot-3"));
}

private void assertMappings(String sourceIdx, boolean requireRouting, boolean useNested) {
private static void assertMappings(String sourceIdx, boolean requireRouting, boolean useNested) {
GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings(sourceIdx).get();
MappingMetadata mapping = getMappingsResponse.getMappings().get(sourceIdx);
String nested = useNested ?
Expand Down