[Remove] remaining AllFieldMapper references (#3007)

AllFieldMapper was deprecated in legacy 6x. The remaining references are
removed, along with the field mapper and corresponding tests.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
This commit is contained in:
Nick Knize 2022-04-20 15:05:13 -05:00 committed by GitHub
parent b45bfc9afc
commit 6915df94c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 220 deletions

View File

@ -1,134 +0,0 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/*
* Licensed to Elasticsearch 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.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.index.mapper;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.opensearch.common.Explicit;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.search.lookup.SearchLookup;
import java.util.Collections;
import java.util.List;
/**
* Noop mapper that ensures that mappings created in 6x that explicitly disable the _all field
* can be restored in this version.
*
* TODO: Remove in 8
*/
public class AllFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_all";
public static final String CONTENT_TYPE = "_all";
public static class Defaults {
public static final FieldType FIELD_TYPE = new FieldType();
static {
FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
FIELD_TYPE.setTokenized(true);
FIELD_TYPE.freeze();
}
}
private static AllFieldMapper toType(FieldMapper in) {
return (AllFieldMapper) in;
}
public static class Builder extends MetadataFieldMapper.Builder {
private final Parameter<Explicit<Boolean>> enabled = updateableBoolParam("enabled", m -> toType(m).enabled, false);
public Builder() {
super(NAME);
}
@Override
protected List<Parameter<?>> getParameters() {
return Collections.singletonList(enabled);
}
@Override
public AllFieldMapper build(BuilderContext context) {
if (enabled.getValue().value()) {
throw new IllegalArgumentException("[_all] is disabled in this version.");
}
return new AllFieldMapper(enabled.getValue());
}
}
public static final TypeParser PARSER = new ConfigurableTypeParser(
c -> new AllFieldMapper(new Explicit<>(false, false)),
c -> new Builder()
);
static final class AllFieldType extends StringFieldType {
AllFieldType() {
super(NAME, false, false, false, TextSearchInfo.NONE, Collections.emptyMap());
}
@Override
public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchLookup, String format) {
throw new UnsupportedOperationException();
}
@Override
public String typeName() {
return CONTENT_TYPE;
}
@Override
public Query existsQuery(QueryShardContext context) {
return new MatchNoDocsQuery();
}
}
private final Explicit<Boolean> enabled;
private AllFieldMapper(Explicit<Boolean> enabled) {
super(new AllFieldType());
this.enabled = enabled;
}
@Override
protected String contentType() {
return CONTENT_TYPE;
}
@Override
public ParametrizedFieldMapper.Builder getMergeBuilder() {
return new Builder().init(this);
}
}

View File

@ -32,9 +32,7 @@
package org.opensearch.indices.mapper;
import org.opensearch.LegacyESVersion;
import org.opensearch.Version;
import org.opensearch.index.mapper.AllFieldMapper;
import org.opensearch.index.mapper.Mapper;
import org.opensearch.index.mapper.MetadataFieldMapper;
import org.opensearch.plugins.MapperPlugin;
@ -52,7 +50,6 @@ public final class MapperRegistry {
private final Map<String, Mapper.TypeParser> mapperParsers;
private final Map<String, MetadataFieldMapper.TypeParser> metadataMapperParsers;
private final Map<String, MetadataFieldMapper.TypeParser> metadataMapperParsers6x;
private final Function<String, Predicate<String>> fieldFilter;
public MapperRegistry(
@ -62,11 +59,6 @@ public final class MapperRegistry {
) {
this.mapperParsers = Collections.unmodifiableMap(new LinkedHashMap<>(mapperParsers));
this.metadataMapperParsers = Collections.unmodifiableMap(new LinkedHashMap<>(metadataMapperParsers));
// add the _all field mapper for indices created in 6x
Map<String, MetadataFieldMapper.TypeParser> metadata6x = new LinkedHashMap<>();
metadata6x.put(AllFieldMapper.NAME, AllFieldMapper.PARSER);
metadata6x.putAll(metadataMapperParsers);
this.metadataMapperParsers6x = Collections.unmodifiableMap(metadata6x);
this.fieldFilter = fieldFilter;
}
@ -83,7 +75,7 @@ public final class MapperRegistry {
* returned map uses the name of the field as a key.
*/
public Map<String, MetadataFieldMapper.TypeParser> getMetadataMapperParsers(Version indexCreatedVersion) {
return indexCreatedVersion.onOrAfter(LegacyESVersion.V_7_0_0) ? metadataMapperParsers : metadataMapperParsers6x;
return metadataMapperParsers;
}
/**

View File

@ -1,63 +0,0 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/*
* Licensed to Elasticsearch 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.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.index.mapper;
import org.opensearch.common.Strings;
import org.opensearch.common.compress.CompressedXContent;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.index.IndexService;
import org.opensearch.index.mapper.MapperService.MergeReason;
import org.opensearch.test.OpenSearchSingleNodeTestCase;
public class AllFieldMapperTests extends OpenSearchSingleNodeTestCase {
@Override
protected boolean forbidPrivateIndexSettings() {
return false;
}
public void testUpdateDefaultSearchAnalyzer() throws Exception {
IndexService indexService = createIndex(
"test",
Settings.builder()
.put("index.analysis.analyzer.default_search.type", "custom")
.put("index.analysis.analyzer.default_search.tokenizer", "standard")
.build()
);
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").endObject().endObject());
indexService.mapperService().merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE);
assertEquals(mapping, indexService.mapperService().documentMapper().mapping().toString());
}
}

View File

@ -33,7 +33,6 @@
package org.opensearch.indices;
import org.opensearch.Version;
import org.opensearch.index.mapper.AllFieldMapper;
import org.opensearch.index.mapper.DataStreamFieldMapper;
import org.opensearch.index.mapper.FieldNamesFieldMapper;
import org.opensearch.index.mapper.IdFieldMapper;
@ -101,19 +100,6 @@ public class IndicesModuleTests extends OpenSearchTestCase {
SeqNoFieldMapper.NAME,
FieldNamesFieldMapper.NAME };
private static String[] EXPECTED_METADATA_FIELDS_6x = new String[] {
AllFieldMapper.NAME,
IgnoredFieldMapper.NAME,
IdFieldMapper.NAME,
RoutingFieldMapper.NAME,
IndexFieldMapper.NAME,
DataStreamFieldMapper.NAME,
SourceFieldMapper.NAME,
TypeFieldMapper.NAME,
VersionFieldMapper.NAME,
SeqNoFieldMapper.NAME,
FieldNamesFieldMapper.NAME };
public void testBuiltinMappers() {
IndicesModule module = new IndicesModule(Collections.emptyList());
{