[Remove] various builder and mapping deprecations (#1752)
This commit removes the following deprecations and invalid tests: * LegacyUpdateMappingIntegrationIT * ShapeBuilder new z axis checks * MatchPhrase new zeroTermsQuery checks * TypeQuery utf8 * CompositeValuesSource format checks * LegacyESVersionTests bumped to 6.8.15 * LegacyDynamicMapping, LegacySimilarity, LegacyMapperService tests Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
This commit is contained in:
parent
8c2d8f5431
commit
6cc462b92d
|
@ -1,239 +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.indices.mapping;
|
|
||||||
|
|
||||||
import org.opensearch.LegacyESVersion;
|
|
||||||
import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
|
||||||
import org.opensearch.action.support.master.AcknowledgedResponse;
|
|
||||||
import org.opensearch.cluster.metadata.IndexMetadata;
|
|
||||||
import org.opensearch.common.settings.Settings;
|
|
||||||
import org.opensearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.opensearch.common.xcontent.json.JsonXContent;
|
|
||||||
import org.opensearch.index.mapper.MapperParsingException;
|
|
||||||
import org.opensearch.index.mapper.MapperService;
|
|
||||||
import org.opensearch.test.OpenSearchIntegTestCase;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
|
||||||
import static org.hamcrest.Matchers.hasEntry;
|
|
||||||
import static org.hamcrest.Matchers.hasKey;
|
|
||||||
import static org.hamcrest.Matchers.not;
|
|
||||||
|
|
||||||
public class LegacyUpdateMappingIntegrationIT extends OpenSearchIntegTestCase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean forbidPrivateIndexSettings() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void testUpdateDefaultMappingSettings() throws Exception {
|
|
||||||
logger.info("Creating index with _default_ mappings");
|
|
||||||
try (XContentBuilder defaultMapping = JsonXContent.contentBuilder()) {
|
|
||||||
defaultMapping.startObject();
|
|
||||||
{
|
|
||||||
defaultMapping.startObject(MapperService.DEFAULT_MAPPING);
|
|
||||||
{
|
|
||||||
defaultMapping.field("date_detection", false);
|
|
||||||
}
|
|
||||||
defaultMapping.endObject();
|
|
||||||
}
|
|
||||||
defaultMapping.endObject();
|
|
||||||
client().admin()
|
|
||||||
.indices()
|
|
||||||
.prepareCreate("test")
|
|
||||||
.setSettings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, LegacyESVersion.V_6_3_0).build())
|
|
||||||
.addMapping(MapperService.DEFAULT_MAPPING, defaultMapping)
|
|
||||||
.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
final GetMappingsResponse getResponse = client().admin()
|
|
||||||
.indices()
|
|
||||||
.prepareGetMappings("test")
|
|
||||||
.addTypes(MapperService.DEFAULT_MAPPING)
|
|
||||||
.get();
|
|
||||||
final Map<String, Object> defaultMapping = getResponse.getMappings()
|
|
||||||
.get("test")
|
|
||||||
.get(MapperService.DEFAULT_MAPPING)
|
|
||||||
.sourceAsMap();
|
|
||||||
assertThat(defaultMapping, hasKey("date_detection"));
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Emptying _default_ mappings");
|
|
||||||
// now remove it
|
|
||||||
try (
|
|
||||||
XContentBuilder mappingBuilder = JsonXContent.contentBuilder()
|
|
||||||
.startObject()
|
|
||||||
.startObject(MapperService.DEFAULT_MAPPING)
|
|
||||||
.endObject()
|
|
||||||
.endObject()
|
|
||||||
) {
|
|
||||||
final AcknowledgedResponse putResponse = client().admin()
|
|
||||||
.indices()
|
|
||||||
.preparePutMapping("test")
|
|
||||||
.setType(MapperService.DEFAULT_MAPPING)
|
|
||||||
.setSource(mappingBuilder)
|
|
||||||
.get();
|
|
||||||
assertThat(putResponse.isAcknowledged(), equalTo(true));
|
|
||||||
}
|
|
||||||
logger.info("Done Emptying _default_ mappings");
|
|
||||||
|
|
||||||
{
|
|
||||||
final GetMappingsResponse getResponse = client().admin()
|
|
||||||
.indices()
|
|
||||||
.prepareGetMappings("test")
|
|
||||||
.addTypes(MapperService.DEFAULT_MAPPING)
|
|
||||||
.get();
|
|
||||||
final Map<String, Object> defaultMapping = getResponse.getMappings()
|
|
||||||
.get("test")
|
|
||||||
.get(MapperService.DEFAULT_MAPPING)
|
|
||||||
.sourceAsMap();
|
|
||||||
assertThat(defaultMapping, not(hasKey("date_detection")));
|
|
||||||
}
|
|
||||||
|
|
||||||
// now test you can change stuff that are normally unchangeable
|
|
||||||
logger.info("Creating _default_ mappings with an analyzed field");
|
|
||||||
try (XContentBuilder defaultMapping = JsonXContent.contentBuilder()) {
|
|
||||||
|
|
||||||
defaultMapping.startObject();
|
|
||||||
{
|
|
||||||
defaultMapping.startObject(MapperService.DEFAULT_MAPPING);
|
|
||||||
{
|
|
||||||
defaultMapping.startObject("properties");
|
|
||||||
{
|
|
||||||
defaultMapping.startObject("f");
|
|
||||||
{
|
|
||||||
defaultMapping.field("type", "text");
|
|
||||||
defaultMapping.field("index", true);
|
|
||||||
}
|
|
||||||
defaultMapping.endObject();
|
|
||||||
}
|
|
||||||
defaultMapping.endObject();
|
|
||||||
}
|
|
||||||
defaultMapping.endObject();
|
|
||||||
}
|
|
||||||
defaultMapping.endObject();
|
|
||||||
|
|
||||||
final AcknowledgedResponse putResponse = client().admin()
|
|
||||||
.indices()
|
|
||||||
.preparePutMapping("test")
|
|
||||||
.setType(MapperService.DEFAULT_MAPPING)
|
|
||||||
.setSource(defaultMapping)
|
|
||||||
.get();
|
|
||||||
assertThat(putResponse.isAcknowledged(), equalTo(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Changing _default_ mappings field from analyzed to non-analyzed");
|
|
||||||
{
|
|
||||||
try (XContentBuilder mappingBuilder = JsonXContent.contentBuilder()) {
|
|
||||||
mappingBuilder.startObject();
|
|
||||||
{
|
|
||||||
mappingBuilder.startObject(MapperService.DEFAULT_MAPPING);
|
|
||||||
{
|
|
||||||
mappingBuilder.startObject("properties");
|
|
||||||
{
|
|
||||||
mappingBuilder.startObject("f");
|
|
||||||
{
|
|
||||||
mappingBuilder.field("type", "keyword");
|
|
||||||
}
|
|
||||||
mappingBuilder.endObject();
|
|
||||||
}
|
|
||||||
mappingBuilder.endObject();
|
|
||||||
}
|
|
||||||
mappingBuilder.endObject();
|
|
||||||
}
|
|
||||||
mappingBuilder.endObject();
|
|
||||||
|
|
||||||
final AcknowledgedResponse putResponse = client().admin()
|
|
||||||
.indices()
|
|
||||||
.preparePutMapping("test")
|
|
||||||
.setType(MapperService.DEFAULT_MAPPING)
|
|
||||||
.setSource(mappingBuilder)
|
|
||||||
.get();
|
|
||||||
assertThat(putResponse.isAcknowledged(), equalTo(true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logger.info("Done changing _default_ mappings field from analyzed to non-analyzed");
|
|
||||||
|
|
||||||
{
|
|
||||||
final GetMappingsResponse getResponse = client().admin()
|
|
||||||
.indices()
|
|
||||||
.prepareGetMappings("test")
|
|
||||||
.addTypes(MapperService.DEFAULT_MAPPING)
|
|
||||||
.get();
|
|
||||||
final Map<String, Object> defaultMapping = getResponse.getMappings()
|
|
||||||
.get("test")
|
|
||||||
.get(MapperService.DEFAULT_MAPPING)
|
|
||||||
.sourceAsMap();
|
|
||||||
final Map<String, Object> fieldSettings = (Map<String, Object>) ((Map) defaultMapping.get("properties")).get("f");
|
|
||||||
assertThat(fieldSettings, hasEntry("type", "keyword"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// but we still validate the _default_ type
|
|
||||||
logger.info("Confirming _default_ mappings validation");
|
|
||||||
try (XContentBuilder mappingBuilder = JsonXContent.contentBuilder()) {
|
|
||||||
|
|
||||||
mappingBuilder.startObject();
|
|
||||||
{
|
|
||||||
mappingBuilder.startObject(MapperService.DEFAULT_MAPPING);
|
|
||||||
{
|
|
||||||
mappingBuilder.startObject("properites");
|
|
||||||
{
|
|
||||||
mappingBuilder.startObject("f");
|
|
||||||
{
|
|
||||||
mappingBuilder.field("type", "non-existent");
|
|
||||||
}
|
|
||||||
mappingBuilder.endObject();
|
|
||||||
}
|
|
||||||
mappingBuilder.endObject();
|
|
||||||
}
|
|
||||||
mappingBuilder.endObject();
|
|
||||||
}
|
|
||||||
mappingBuilder.endObject();
|
|
||||||
|
|
||||||
expectThrows(
|
|
||||||
MapperParsingException.class,
|
|
||||||
() -> client().admin()
|
|
||||||
.indices()
|
|
||||||
.preparePutMapping("test")
|
|
||||||
.setType(MapperService.DEFAULT_MAPPING)
|
|
||||||
.setSource(mappingBuilder)
|
|
||||||
.get()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -39,7 +39,6 @@ import org.locationtech.jts.geom.GeometryFactory;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.opensearch.Assertions;
|
import org.opensearch.Assertions;
|
||||||
import org.opensearch.LegacyESVersion;
|
|
||||||
import org.opensearch.common.Strings;
|
import org.opensearch.common.Strings;
|
||||||
import org.opensearch.common.geo.GeoShapeType;
|
import org.opensearch.common.geo.GeoShapeType;
|
||||||
import org.opensearch.common.geo.parsers.GeoWKTParser;
|
import org.opensearch.common.geo.parsers.GeoWKTParser;
|
||||||
|
@ -128,10 +127,7 @@ public abstract class ShapeBuilder<T extends Shape, G extends org.opensearch.geo
|
||||||
protected static Coordinate readFromStream(StreamInput in) throws IOException {
|
protected static Coordinate readFromStream(StreamInput in) throws IOException {
|
||||||
double x = in.readDouble();
|
double x = in.readDouble();
|
||||||
double y = in.readDouble();
|
double y = in.readDouble();
|
||||||
Double z = null;
|
Double z = in.readOptionalDouble();
|
||||||
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
z = in.readOptionalDouble();
|
|
||||||
}
|
|
||||||
return z == null ? new Coordinate(x, y) : new Coordinate(x, y, z);
|
return z == null ? new Coordinate(x, y) : new Coordinate(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,10 +142,8 @@ public abstract class ShapeBuilder<T extends Shape, G extends org.opensearch.geo
|
||||||
protected static void writeCoordinateTo(Coordinate coordinate, StreamOutput out) throws IOException {
|
protected static void writeCoordinateTo(Coordinate coordinate, StreamOutput out) throws IOException {
|
||||||
out.writeDouble(coordinate.x);
|
out.writeDouble(coordinate.x);
|
||||||
out.writeDouble(coordinate.y);
|
out.writeDouble(coordinate.y);
|
||||||
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
out.writeOptionalDouble(Double.isNaN(coordinate.z) ? null : coordinate.z);
|
out.writeOptionalDouble(Double.isNaN(coordinate.z) ? null : coordinate.z);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private E thisRef() {
|
private E thisRef() {
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
package org.opensearch.index.query;
|
package org.opensearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.opensearch.LegacyESVersion;
|
|
||||||
import org.opensearch.common.ParseField;
|
import org.opensearch.common.ParseField;
|
||||||
import org.opensearch.common.ParsingException;
|
import org.opensearch.common.ParsingException;
|
||||||
import org.opensearch.common.Strings;
|
import org.opensearch.common.Strings;
|
||||||
|
@ -85,9 +84,7 @@ public class MatchPhraseQueryBuilder extends AbstractQueryBuilder<MatchPhraseQue
|
||||||
fieldName = in.readString();
|
fieldName = in.readString();
|
||||||
value = in.readGenericValue();
|
value = in.readGenericValue();
|
||||||
slop = in.readVInt();
|
slop = in.readVInt();
|
||||||
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
zeroTermsQuery = ZeroTermsQuery.readFromStream(in);
|
zeroTermsQuery = ZeroTermsQuery.readFromStream(in);
|
||||||
}
|
|
||||||
analyzer = in.readOptionalString();
|
analyzer = in.readOptionalString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,9 +93,7 @@ public class MatchPhraseQueryBuilder extends AbstractQueryBuilder<MatchPhraseQue
|
||||||
out.writeString(fieldName);
|
out.writeString(fieldName);
|
||||||
out.writeGenericValue(value);
|
out.writeGenericValue(value);
|
||||||
out.writeVInt(slop);
|
out.writeVInt(slop);
|
||||||
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
zeroTermsQuery.writeTo(out);
|
zeroTermsQuery.writeTo(out);
|
||||||
}
|
|
||||||
out.writeOptionalString(analyzer);
|
out.writeOptionalString(analyzer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,6 @@ package org.opensearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.MatchNoDocsQuery;
|
import org.apache.lucene.search.MatchNoDocsQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.util.BytesRef;
|
|
||||||
import org.opensearch.LegacyESVersion;
|
|
||||||
import org.opensearch.common.ParseField;
|
import org.opensearch.common.ParseField;
|
||||||
import org.opensearch.common.ParsingException;
|
import org.opensearch.common.ParsingException;
|
||||||
import org.opensearch.common.io.stream.StreamInput;
|
import org.opensearch.common.io.stream.StreamInput;
|
||||||
|
@ -71,20 +69,12 @@ public class TypeQueryBuilder extends AbstractQueryBuilder<TypeQueryBuilder> {
|
||||||
*/
|
*/
|
||||||
public TypeQueryBuilder(StreamInput in) throws IOException {
|
public TypeQueryBuilder(StreamInput in) throws IOException {
|
||||||
super(in);
|
super(in);
|
||||||
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
type = in.readString();
|
type = in.readString();
|
||||||
} else {
|
|
||||||
type = in.readBytesRef().utf8ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
out.writeString(type);
|
out.writeString(type);
|
||||||
} else {
|
|
||||||
out.writeBytesRef(new BytesRef(type));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String type() {
|
public String type() {
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
package org.opensearch.search.aggregations.bucket.composite;
|
package org.opensearch.search.aggregations.bucket.composite;
|
||||||
|
|
||||||
import org.opensearch.LegacyESVersion;
|
|
||||||
import org.opensearch.common.io.stream.StreamInput;
|
import org.opensearch.common.io.stream.StreamInput;
|
||||||
import org.opensearch.common.io.stream.StreamOutput;
|
import org.opensearch.common.io.stream.StreamOutput;
|
||||||
import org.opensearch.common.io.stream.Writeable;
|
import org.opensearch.common.io.stream.Writeable;
|
||||||
|
@ -76,21 +75,9 @@ public abstract class CompositeValuesSourceBuilder<AB extends CompositeValuesSou
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.userValueTypeHint = ValueType.readFromStream(in);
|
this.userValueTypeHint = ValueType.readFromStream(in);
|
||||||
}
|
}
|
||||||
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) {
|
|
||||||
this.missingBucket = in.readBoolean();
|
this.missingBucket = in.readBoolean();
|
||||||
} else {
|
|
||||||
this.missingBucket = false;
|
|
||||||
}
|
|
||||||
if (in.getVersion().before(LegacyESVersion.V_7_0_0)) {
|
|
||||||
// skip missing value for BWC
|
|
||||||
in.readGenericValue();
|
|
||||||
}
|
|
||||||
this.order = SortOrder.readFromStream(in);
|
this.order = SortOrder.readFromStream(in);
|
||||||
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
this.format = in.readOptionalString();
|
this.format = in.readOptionalString();
|
||||||
} else {
|
|
||||||
this.format = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -107,17 +94,9 @@ public abstract class CompositeValuesSourceBuilder<AB extends CompositeValuesSou
|
||||||
if (hasValueType) {
|
if (hasValueType) {
|
||||||
userValueTypeHint.writeTo(out);
|
userValueTypeHint.writeTo(out);
|
||||||
}
|
}
|
||||||
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_4_0)) {
|
|
||||||
out.writeBoolean(missingBucket);
|
out.writeBoolean(missingBucket);
|
||||||
}
|
|
||||||
if (out.getVersion().before(LegacyESVersion.V_7_0_0)) {
|
|
||||||
// write missing value for BWC
|
|
||||||
out.writeGenericValue(null);
|
|
||||||
}
|
|
||||||
order.writeTo(out);
|
order.writeTo(out);
|
||||||
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
out.writeOptionalString(format);
|
out.writeOptionalString(format);
|
||||||
}
|
|
||||||
innerWriteTo(out);
|
innerWriteTo(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,19 +96,11 @@ public class InternalComposite extends InternalMultiBucketAggregation<InternalCo
|
||||||
this.sourceNames = in.readStringList();
|
this.sourceNames = in.readStringList();
|
||||||
this.formats = new ArrayList<>(sourceNames.size());
|
this.formats = new ArrayList<>(sourceNames.size());
|
||||||
for (int i = 0; i < sourceNames.size(); i++) {
|
for (int i = 0; i < sourceNames.size(); i++) {
|
||||||
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
formats.add(in.readNamedWriteable(DocValueFormat.class));
|
formats.add(in.readNamedWriteable(DocValueFormat.class));
|
||||||
} else {
|
|
||||||
formats.add(DocValueFormat.RAW);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.reverseMuls = in.readIntArray();
|
this.reverseMuls = in.readIntArray();
|
||||||
this.buckets = in.readList((input) -> new InternalBucket(input, sourceNames, formats, reverseMuls));
|
this.buckets = in.readList((input) -> new InternalBucket(input, sourceNames, formats, reverseMuls));
|
||||||
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
this.afterKey = in.readBoolean() ? new CompositeKey(in) : null;
|
this.afterKey = in.readBoolean() ? new CompositeKey(in) : null;
|
||||||
} else {
|
|
||||||
this.afterKey = buckets.size() > 0 ? buckets.get(buckets.size() - 1).key : null;
|
|
||||||
}
|
|
||||||
this.earlyTerminated = in.getVersion().onOrAfter(LegacyESVersion.V_7_6_0) ? in.readBoolean() : false;
|
this.earlyTerminated = in.getVersion().onOrAfter(LegacyESVersion.V_7_6_0) ? in.readBoolean() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,19 +108,15 @@ public class InternalComposite extends InternalMultiBucketAggregation<InternalCo
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(size);
|
out.writeVInt(size);
|
||||||
out.writeStringCollection(sourceNames);
|
out.writeStringCollection(sourceNames);
|
||||||
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
for (DocValueFormat format : formats) {
|
for (DocValueFormat format : formats) {
|
||||||
out.writeNamedWriteable(format);
|
out.writeNamedWriteable(format);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
out.writeIntArray(reverseMuls);
|
out.writeIntArray(reverseMuls);
|
||||||
out.writeList(buckets);
|
out.writeList(buckets);
|
||||||
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_3_0)) {
|
|
||||||
out.writeBoolean(afterKey != null);
|
out.writeBoolean(afterKey != null);
|
||||||
if (afterKey != null) {
|
if (afterKey != null) {
|
||||||
afterKey.writeTo(out);
|
afterKey.writeTo(out);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_6_0)) {
|
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_6_0)) {
|
||||||
out.writeBoolean(earlyTerminated);
|
out.writeBoolean(earlyTerminated);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import static org.hamcrest.Matchers.greaterThan;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.lessThan;
|
import static org.hamcrest.Matchers.lessThan;
|
||||||
import static org.hamcrest.Matchers.sameInstance;
|
import static org.hamcrest.Matchers.sameInstance;
|
||||||
import static org.opensearch.LegacyESVersion.V_6_3_0;
|
import static org.opensearch.LegacyESVersion.V_6_8_15;
|
||||||
import static org.opensearch.LegacyESVersion.V_7_0_0;
|
import static org.opensearch.LegacyESVersion.V_7_0_0;
|
||||||
import static org.opensearch.test.VersionUtils.randomLegacyVersion;
|
import static org.opensearch.test.VersionUtils.randomLegacyVersion;
|
||||||
import static org.opensearch.VersionTests.isCompatible;
|
import static org.opensearch.VersionTests.isCompatible;
|
||||||
|
@ -37,30 +37,30 @@ import static org.opensearch.VersionTests.isCompatible;
|
||||||
public class LegacyESVersionTests extends OpenSearchTestCase {
|
public class LegacyESVersionTests extends OpenSearchTestCase {
|
||||||
|
|
||||||
public void testVersionComparison() {
|
public void testVersionComparison() {
|
||||||
assertThat(V_6_3_0.before(V_7_0_0), is(true));
|
assertThat(V_6_8_15.before(V_7_0_0), is(true));
|
||||||
assertThat(V_6_3_0.before(V_6_3_0), is(false));
|
assertThat(V_6_8_15.before(V_6_8_15), is(false));
|
||||||
assertThat(V_7_0_0.before(V_6_3_0), is(false));
|
assertThat(V_7_0_0.before(V_6_8_15), is(false));
|
||||||
|
|
||||||
assertThat(V_6_3_0.onOrBefore(V_7_0_0), is(true));
|
assertThat(V_6_8_15.onOrBefore(V_7_0_0), is(true));
|
||||||
assertThat(V_6_3_0.onOrBefore(V_6_3_0), is(true));
|
assertThat(V_6_8_15.onOrBefore(V_6_8_15), is(true));
|
||||||
assertThat(V_7_0_0.onOrBefore(V_6_3_0), is(false));
|
assertThat(V_7_0_0.onOrBefore(V_6_8_15), is(false));
|
||||||
|
|
||||||
assertThat(V_6_3_0.after(V_7_0_0), is(false));
|
assertThat(V_6_8_15.after(V_7_0_0), is(false));
|
||||||
assertThat(V_6_3_0.after(V_6_3_0), is(false));
|
assertThat(V_6_8_15.after(V_6_8_15), is(false));
|
||||||
assertThat(V_7_0_0.after(V_6_3_0), is(true));
|
assertThat(V_7_0_0.after(V_6_8_15), is(true));
|
||||||
|
|
||||||
assertThat(V_6_3_0.onOrAfter(V_7_0_0), is(false));
|
assertThat(V_6_8_15.onOrAfter(V_7_0_0), is(false));
|
||||||
assertThat(V_6_3_0.onOrAfter(V_6_3_0), is(true));
|
assertThat(V_6_8_15.onOrAfter(V_6_8_15), is(true));
|
||||||
assertThat(V_7_0_0.onOrAfter(V_6_3_0), is(true));
|
assertThat(V_7_0_0.onOrAfter(V_6_8_15), is(true));
|
||||||
|
|
||||||
assertTrue(LegacyESVersion.fromString("5.0.0-alpha2").onOrAfter(LegacyESVersion.fromString("5.0.0-alpha1")));
|
assertTrue(LegacyESVersion.fromString("5.0.0-alpha2").onOrAfter(LegacyESVersion.fromString("5.0.0-alpha1")));
|
||||||
assertTrue(LegacyESVersion.fromString("5.0.0").onOrAfter(LegacyESVersion.fromString("5.0.0-beta2")));
|
assertTrue(LegacyESVersion.fromString("5.0.0").onOrAfter(LegacyESVersion.fromString("5.0.0-beta2")));
|
||||||
assertTrue(LegacyESVersion.fromString("5.0.0-rc1").onOrAfter(LegacyESVersion.fromString("5.0.0-beta24")));
|
assertTrue(LegacyESVersion.fromString("5.0.0-rc1").onOrAfter(LegacyESVersion.fromString("5.0.0-beta24")));
|
||||||
assertTrue(LegacyESVersion.fromString("5.0.0-alpha24").before(LegacyESVersion.fromString("5.0.0-beta0")));
|
assertTrue(LegacyESVersion.fromString("5.0.0-alpha24").before(LegacyESVersion.fromString("5.0.0-beta0")));
|
||||||
|
|
||||||
assertThat(V_6_3_0, is(lessThan(V_7_0_0)));
|
assertThat(V_6_8_15, is(lessThan(V_7_0_0)));
|
||||||
assertThat(V_6_3_0.compareTo(V_6_3_0), is(0));
|
assertThat(V_6_8_15.compareTo(V_6_8_15), is(0));
|
||||||
assertThat(V_7_0_0, is(greaterThan(V_6_3_0)));
|
assertThat(V_7_0_0, is(greaterThan(V_6_8_15)));
|
||||||
|
|
||||||
// compare opensearch version to LegacyESVersion
|
// compare opensearch version to LegacyESVersion
|
||||||
assertThat(Version.V_1_0_0.compareMajor(LegacyESVersion.V_7_0_0), is(0));
|
assertThat(Version.V_1_0_0.compareMajor(LegacyESVersion.V_7_0_0), is(0));
|
||||||
|
|
|
@ -32,9 +32,9 @@
|
||||||
package org.opensearch.common.geo;
|
package org.opensearch.common.geo;
|
||||||
|
|
||||||
import org.apache.lucene.geo.GeoTestUtil;
|
import org.apache.lucene.geo.GeoTestUtil;
|
||||||
import org.opensearch.LegacyESVersion;
|
|
||||||
import org.opensearch.OpenSearchException;
|
import org.opensearch.OpenSearchException;
|
||||||
import org.opensearch.OpenSearchParseException;
|
import org.opensearch.OpenSearchParseException;
|
||||||
|
import org.opensearch.Version;
|
||||||
import org.opensearch.cluster.metadata.IndexMetadata;
|
import org.opensearch.cluster.metadata.IndexMetadata;
|
||||||
import org.opensearch.common.UUIDs;
|
import org.opensearch.common.UUIDs;
|
||||||
import org.opensearch.common.geo.builders.CoordinatesBuilder;
|
import org.opensearch.common.geo.builders.CoordinatesBuilder;
|
||||||
|
@ -320,7 +320,7 @@ public class GeoWKTShapeParserTests extends BaseGeoParsingTestCase {
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
|
|
||||||
Settings indexSettings = Settings.builder()
|
Settings indexSettings = Settings.builder()
|
||||||
.put(IndexMetadata.SETTING_VERSION_CREATED, LegacyESVersion.V_7_0_0)
|
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
|
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
||||||
.put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
.put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
||||||
|
@ -359,7 +359,7 @@ public class GeoWKTShapeParserTests extends BaseGeoParsingTestCase {
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
|
|
||||||
Settings indexSettings = Settings.builder()
|
Settings indexSettings = Settings.builder()
|
||||||
.put(IndexMetadata.SETTING_VERSION_CREATED, LegacyESVersion.V_6_3_0)
|
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
|
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
||||||
.put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
.put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
||||||
|
@ -390,7 +390,7 @@ public class GeoWKTShapeParserTests extends BaseGeoParsingTestCase {
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
|
|
||||||
Settings indexSettings = Settings.builder()
|
Settings indexSettings = Settings.builder()
|
||||||
.put(IndexMetadata.SETTING_VERSION_CREATED, LegacyESVersion.V_6_3_0)
|
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
|
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
||||||
.put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
.put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
||||||
|
@ -413,7 +413,7 @@ public class GeoWKTShapeParserTests extends BaseGeoParsingTestCase {
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
|
|
||||||
Settings indexSettings = Settings.builder()
|
Settings indexSettings = Settings.builder()
|
||||||
.put(IndexMetadata.SETTING_VERSION_CREATED, LegacyESVersion.V_6_3_0)
|
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
|
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
||||||
.put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
.put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
||||||
|
|
|
@ -1,80 +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.LegacyESVersion;
|
|
||||||
import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
|
||||||
import org.opensearch.cluster.metadata.IndexMetadata;
|
|
||||||
import org.opensearch.common.settings.Settings;
|
|
||||||
import org.opensearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.opensearch.test.OpenSearchSingleNodeTestCase;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
||||||
|
|
||||||
public class LegacyDynamicMappingTests extends OpenSearchSingleNodeTestCase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean forbidPrivateIndexSettings() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testTypeNotCreatedOnIndexFailure() throws IOException {
|
|
||||||
final Settings settings = Settings.builder()
|
|
||||||
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), LegacyESVersion.V_6_3_0)
|
|
||||||
.build();
|
|
||||||
try (XContentBuilder mapping = jsonBuilder()) {
|
|
||||||
mapping.startObject();
|
|
||||||
{
|
|
||||||
mapping.startObject("_default_");
|
|
||||||
{
|
|
||||||
mapping.field("dynamic", "strict");
|
|
||||||
}
|
|
||||||
mapping.endObject();
|
|
||||||
}
|
|
||||||
mapping.endObject();
|
|
||||||
createIndex("test", settings, "_default_", mapping);
|
|
||||||
}
|
|
||||||
try (XContentBuilder sourceBuilder = jsonBuilder().startObject().field("test", "test").endObject()) {
|
|
||||||
expectThrows(
|
|
||||||
StrictDynamicMappingException.class,
|
|
||||||
() -> client().prepareIndex().setIndex("test").setType("type").setSource(sourceBuilder).get()
|
|
||||||
);
|
|
||||||
|
|
||||||
GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").get();
|
|
||||||
assertNull(getMappingsResponse.getMappings().get("test").get("type"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,107 +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.LegacyESVersion;
|
|
||||||
import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest;
|
|
||||||
import org.opensearch.cluster.metadata.IndexMetadata;
|
|
||||||
import org.opensearch.common.Strings;
|
|
||||||
import org.opensearch.common.compress.CompressedXContent;
|
|
||||||
import org.opensearch.common.settings.Settings;
|
|
||||||
import org.opensearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.opensearch.common.xcontent.XContentFactory;
|
|
||||||
import org.opensearch.common.xcontent.json.JsonXContent;
|
|
||||||
import org.opensearch.index.IndexService;
|
|
||||||
import org.opensearch.test.OpenSearchSingleNodeTestCase;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class LegacyMapperServiceTests extends OpenSearchSingleNodeTestCase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean forbidPrivateIndexSettings() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testIndexMetadataUpdateDoesNotLoseDefaultMapper() throws IOException {
|
|
||||||
final IndexService indexService = createIndex(
|
|
||||||
"test",
|
|
||||||
Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, LegacyESVersion.V_6_3_0).build()
|
|
||||||
);
|
|
||||||
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
|
|
||||||
builder.startObject();
|
|
||||||
{
|
|
||||||
builder.startObject(MapperService.DEFAULT_MAPPING);
|
|
||||||
{
|
|
||||||
builder.field("date_detection", false);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
|
||||||
}
|
|
||||||
builder.endObject();
|
|
||||||
final PutMappingRequest putMappingRequest = new PutMappingRequest();
|
|
||||||
putMappingRequest.indices("test");
|
|
||||||
putMappingRequest.type(MapperService.DEFAULT_MAPPING);
|
|
||||||
putMappingRequest.source(builder);
|
|
||||||
client().admin().indices().preparePutMapping("test").setType(MapperService.DEFAULT_MAPPING).setSource(builder).get();
|
|
||||||
}
|
|
||||||
assertNotNull(indexService.mapperService().documentMapper(MapperService.DEFAULT_MAPPING));
|
|
||||||
final Settings zeroReplicasSettings = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build();
|
|
||||||
client().admin().indices().prepareUpdateSettings("test").setSettings(zeroReplicasSettings).get();
|
|
||||||
/*
|
|
||||||
* This assertion is a guard against a previous bug that would lose the default mapper when applying a metadata update that did not
|
|
||||||
* update the default mapping.
|
|
||||||
*/
|
|
||||||
assertNotNull(indexService.mapperService().documentMapper(MapperService.DEFAULT_MAPPING));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDefaultMappingIsDeprecatedOn6() throws IOException {
|
|
||||||
final Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, LegacyESVersion.V_6_3_0).build();
|
|
||||||
final String mapping;
|
|
||||||
try (XContentBuilder defaultMapping = XContentFactory.jsonBuilder()) {
|
|
||||||
defaultMapping.startObject();
|
|
||||||
{
|
|
||||||
defaultMapping.startObject("_default_");
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
defaultMapping.endObject();
|
|
||||||
}
|
|
||||||
defaultMapping.endObject();
|
|
||||||
mapping = Strings.toString(defaultMapping);
|
|
||||||
}
|
|
||||||
final MapperService mapperService = createIndex("test", settings).mapperService();
|
|
||||||
mapperService.merge("_default_", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE);
|
|
||||||
assertWarnings(MapperService.DEFAULT_MAPPING_ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,111 +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.similarity;
|
|
||||||
|
|
||||||
import org.apache.lucene.search.similarities.BooleanSimilarity;
|
|
||||||
import org.apache.lucene.search.similarities.ClassicSimilarity;
|
|
||||||
import org.apache.lucene.search.similarity.LegacyBM25Similarity;
|
|
||||||
import org.opensearch.LegacyESVersion;
|
|
||||||
import org.opensearch.cluster.metadata.IndexMetadata;
|
|
||||||
import org.opensearch.common.settings.Settings;
|
|
||||||
import org.opensearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.opensearch.common.xcontent.XContentFactory;
|
|
||||||
import org.opensearch.index.mapper.MapperService;
|
|
||||||
import org.opensearch.test.OpenSearchSingleNodeTestCase;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
|
||||||
|
|
||||||
public class LegacySimilarityTests extends OpenSearchSingleNodeTestCase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean forbidPrivateIndexSettings() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testResolveDefaultSimilaritiesOn6xIndex() {
|
|
||||||
final Settings indexSettings = Settings.builder()
|
|
||||||
.put(IndexMetadata.SETTING_VERSION_CREATED, LegacyESVersion.V_6_3_0) // otherwise classic is forbidden
|
|
||||||
.build();
|
|
||||||
final SimilarityService similarityService = createIndex("foo", indexSettings).similarityService();
|
|
||||||
assertThat(similarityService.getSimilarity("classic").get(), instanceOf(ClassicSimilarity.class));
|
|
||||||
assertWarnings(
|
|
||||||
"The [classic] similarity is now deprecated in favour of BM25, which is generally "
|
|
||||||
+ "accepted as a better alternative. Use the [BM25] similarity or build a custom [scripted] similarity "
|
|
||||||
+ "instead."
|
|
||||||
);
|
|
||||||
assertThat(similarityService.getSimilarity("BM25").get(), instanceOf(LegacyBM25Similarity.class));
|
|
||||||
assertThat(similarityService.getSimilarity("boolean").get(), instanceOf(BooleanSimilarity.class));
|
|
||||||
assertThat(similarityService.getSimilarity("default"), equalTo(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testResolveSimilaritiesFromMappingClassic() throws IOException {
|
|
||||||
try (XContentBuilder mapping = XContentFactory.jsonBuilder()) {
|
|
||||||
mapping.startObject();
|
|
||||||
{
|
|
||||||
mapping.startObject("type");
|
|
||||||
{
|
|
||||||
mapping.startObject("properties");
|
|
||||||
{
|
|
||||||
mapping.startObject("field1");
|
|
||||||
{
|
|
||||||
mapping.field("type", "text");
|
|
||||||
mapping.field("similarity", "my_similarity");
|
|
||||||
}
|
|
||||||
mapping.endObject();
|
|
||||||
}
|
|
||||||
mapping.endObject();
|
|
||||||
}
|
|
||||||
mapping.endObject();
|
|
||||||
}
|
|
||||||
mapping.endObject();
|
|
||||||
|
|
||||||
final Settings indexSettings = Settings.builder()
|
|
||||||
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), LegacyESVersion.V_6_3_0) // otherwise classic is forbidden
|
|
||||||
.put("index.similarity.my_similarity.type", "classic")
|
|
||||||
.put("index.similarity.my_similarity.discount_overlaps", false)
|
|
||||||
.build();
|
|
||||||
final MapperService mapperService = createIndex("foo", indexSettings, "type", mapping).mapperService();
|
|
||||||
assertThat(mapperService.fieldType("field1").getTextSearchInfo().getSimilarity().get(), instanceOf(ClassicSimilarity.class));
|
|
||||||
|
|
||||||
final ClassicSimilarity similarity = (ClassicSimilarity) mapperService.fieldType("field1")
|
|
||||||
.getTextSearchInfo()
|
|
||||||
.getSimilarity()
|
|
||||||
.get();
|
|
||||||
assertThat(similarity.getDiscountOverlaps(), equalTo(false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue