diff --git a/dev-tools/create-bwc-index.py b/dev-tools/create-bwc-index.py index 9397ef873ef47..ea1d174612560 100644 --- a/dev-tools/create-bwc-index.py +++ b/dev-tools/create-bwc-index.py @@ -181,7 +181,10 @@ def generate_index(client, version): }, '_routing': { 'path': 'myrouting' - } + }, + '_boost': { + 'null_value': 2.0 + } } mappings['custom_formats'] = { 'properties': { @@ -196,7 +199,6 @@ def generate_index(client, version): } } - client.indices.create(index='test', body={ 'settings': { 'number_of_shards': 1, diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index 3314cbe1da0bb..f6605eefd9f81 100644 --- a/docs/reference/migration/migrate_2_0.asciidoc +++ b/docs/reference/migration/migrate_2_0.asciidoc @@ -247,7 +247,7 @@ curl -XGET 'localhost:9200/index/type/_search' } --------------- -==== Meta fields have limited confiugration +==== Meta fields have limited configuration Meta fields (those beginning with underscore) are fields used by elasticsearch to provide special features. They now have limited configuration options. @@ -255,6 +255,7 @@ to provide special features. They now have limited configuration options. * `_type` configuration can no longer be changed. * `_index` configuration is limited to enabling the field. * `_routing` configuration is limited to requiring the field. +* `_boost` has been removed. === Codecs diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java index 7783e8100dbd5..7920faa67b2fd 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -53,7 +53,7 @@ public class PutMappingRequest extends AcknowledgedRequest implements IndicesRequest.Replaceable { private static ObjectOpenHashSet RESERVED_FIELDS = ObjectOpenHashSet.from( - "_uid", "_id", "_type", "_source", "_all", "_analyzer", "_boost", "_parent", "_routing", "_index", + "_uid", "_id", "_type", "_source", "_all", "_analyzer", "_parent", "_routing", "_index", "_size", "_timestamp", "_ttl" ); diff --git a/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java b/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java index 63e9a64f573e1..b3b9de5198599 100644 --- a/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java @@ -22,9 +22,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Field; -import org.apache.lucene.document.FieldType; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.LeafReaderContext; @@ -33,7 +31,6 @@ import org.apache.lucene.util.CloseableThreadLocal; import org.elasticsearch.ElasticsearchGenerationException; import org.elasticsearch.ElasticsearchIllegalArgumentException; -import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Preconditions; import org.elasticsearch.common.bytes.BytesReference; @@ -50,10 +47,8 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.cache.bitset.BitsetFilterCache; import org.elasticsearch.index.mapper.internal.AllFieldMapper; -import org.elasticsearch.index.mapper.internal.BoostFieldMapper; import org.elasticsearch.index.mapper.internal.FieldNamesFieldMapper; import org.elasticsearch.index.mapper.internal.IdFieldMapper; import org.elasticsearch.index.mapper.internal.IndexFieldMapper; @@ -194,7 +189,6 @@ public Builder(String index, Settings indexSettings, RootObjectMapper.Builder bu this.rootMappers.put(SourceFieldMapper.class, new SourceFieldMapper(indexSettings)); this.rootMappers.put(TypeFieldMapper.class, new TypeFieldMapper(indexSettings)); this.rootMappers.put(AllFieldMapper.class, new AllFieldMapper(indexSettings)); - this.rootMappers.put(BoostFieldMapper.class, new BoostFieldMapper(indexSettings)); this.rootMappers.put(TimestampFieldMapper.class, new TimestampFieldMapper(indexSettings)); this.rootMappers.put(TTLFieldMapper.class, new TTLFieldMapper(indexSettings)); this.rootMappers.put(VersionFieldMapper.class, new VersionFieldMapper(indexSettings)); @@ -411,10 +405,6 @@ public SizeFieldMapper SizeFieldMapper() { return rootMapper(SizeFieldMapper.class); } - public BoostFieldMapper boostFieldMapper() { - return rootMapper(BoostFieldMapper.class); - } - public Filter typeFilter() { return this.typeFilter; } diff --git a/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java b/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java index 5fecf3d3dd85d..8653366788d52 100644 --- a/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java +++ b/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java @@ -54,7 +54,6 @@ import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper; import org.elasticsearch.index.mapper.geo.GeoShapeFieldMapper; import org.elasticsearch.index.mapper.internal.AllFieldMapper; -import org.elasticsearch.index.mapper.internal.BoostFieldMapper; import org.elasticsearch.index.mapper.internal.FieldNamesFieldMapper; import org.elasticsearch.index.mapper.internal.IdFieldMapper; import org.elasticsearch.index.mapper.internal.IndexFieldMapper; @@ -139,7 +138,6 @@ public DocumentMapperParser(Index index, @IndexSettings Settings indexSettings, .put(SourceFieldMapper.NAME, new SourceFieldMapper.TypeParser()) .put(TypeFieldMapper.NAME, new TypeFieldMapper.TypeParser()) .put(AllFieldMapper.NAME, new AllFieldMapper.TypeParser()) - .put(BoostFieldMapper.NAME, new BoostFieldMapper.TypeParser()) .put(ParentFieldMapper.NAME, new ParentFieldMapper.TypeParser()) .put(RoutingFieldMapper.NAME, new RoutingFieldMapper.TypeParser()) .put(TimestampFieldMapper.NAME, new TimestampFieldMapper.TypeParser()) diff --git a/src/main/java/org/elasticsearch/index/mapper/MapperBuilders.java b/src/main/java/org/elasticsearch/index/mapper/MapperBuilders.java index 7402acfb69f39..51845fdf838f5 100644 --- a/src/main/java/org/elasticsearch/index/mapper/MapperBuilders.java +++ b/src/main/java/org/elasticsearch/index/mapper/MapperBuilders.java @@ -89,10 +89,6 @@ public static ParentFieldMapper.Builder parent() { return new ParentFieldMapper.Builder(); } - public static BoostFieldMapper.Builder boost(String name) { - return new BoostFieldMapper.Builder(name); - } - public static AllFieldMapper.Builder all() { return new AllFieldMapper.Builder(); } diff --git a/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 02bb00d95359e..182f5764d99b0 100755 --- a/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -90,7 +90,7 @@ public class MapperService extends AbstractIndexComponent { public static final String DEFAULT_MAPPING = "_default_"; private static ObjectOpenHashSet META_FIELDS = ObjectOpenHashSet.from( - "_uid", "_id", "_type", "_all", "_analyzer", "_boost", "_parent", "_routing", "_index", + "_uid", "_id", "_type", "_all", "_analyzer", "_parent", "_routing", "_index", "_size", "_timestamp", "_ttl" ); private final AnalysisService analysisService; diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java deleted file mode 100644 index 4e5200edc1489..0000000000000 --- a/src/main/java/org/elasticsearch/index/mapper/internal/BoostFieldMapper.java +++ /dev/null @@ -1,336 +0,0 @@ -/* - * 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. - */ - -package org.elasticsearch.index.mapper.internal; - -import org.apache.lucene.document.Field; -import org.apache.lucene.document.FieldType; -import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.NumericRangeFilter; -import org.apache.lucene.search.NumericRangeQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.NumericUtils; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.Numbers; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.Fuzziness; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.analysis.NumericFloatAnalyzer; -import org.elasticsearch.index.fielddata.FieldDataType; -import org.elasticsearch.index.fielddata.IndexNumericFieldData; -import org.elasticsearch.index.mapper.InternalMapper; -import org.elasticsearch.index.mapper.Mapper; -import org.elasticsearch.index.mapper.MapperBuilders; -import org.elasticsearch.index.mapper.MapperParsingException; -import org.elasticsearch.index.mapper.MergeContext; -import org.elasticsearch.index.mapper.MergeMappingException; -import org.elasticsearch.index.mapper.ParseContext; -import org.elasticsearch.index.mapper.RootMapper; -import org.elasticsearch.index.mapper.core.FloatFieldMapper; -import org.elasticsearch.index.mapper.core.NumberFieldMapper; -import org.elasticsearch.index.query.QueryParseContext; -import org.elasticsearch.index.search.NumericRangeFieldDataFilter; - -import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeFloatValue; -import static org.elasticsearch.index.mapper.core.TypeParsers.parseNumberField; - -/** - * - */ -public class BoostFieldMapper extends NumberFieldMapper implements InternalMapper, RootMapper { - - public static final String CONTENT_TYPE = "_boost"; - public static final String NAME = "_boost"; - - public static class Defaults extends NumberFieldMapper.Defaults { - public static final String NAME = "_boost"; - public static final Float NULL_VALUE = null; - - public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE); - - static { - FIELD_TYPE.setStored(false); - FIELD_TYPE.setIndexOptions(IndexOptions.NONE); // not indexed - } - } - - public static class Builder extends NumberFieldMapper.Builder { - - protected Float nullValue = Defaults.NULL_VALUE; - - public Builder(String name) { - super(name, new FieldType(Defaults.FIELD_TYPE), Defaults.PRECISION_STEP_32_BIT); - builder = this; - } - - public Builder nullValue(float nullValue) { - this.nullValue = nullValue; - return this; - } - - // if we are indexed we use DOCS_ONLY - @Override - protected IndexOptions getDefaultIndexOption() { - return IndexOptions.DOCS; - } - - @Override - public BoostFieldMapper build(BuilderContext context) { - return new BoostFieldMapper(name, buildIndexName(context), - fieldType.numericPrecisionStep(), boost, fieldType, docValues, nullValue, fieldDataSettings, context.indexSettings()); - } - } - - public static class TypeParser implements Mapper.TypeParser { - @Override - public Mapper.Builder parse(String fieldName, Map node, ParserContext parserContext) throws MapperParsingException { - String name = node.get("name") == null ? BoostFieldMapper.Defaults.NAME : node.remove("name").toString(); - BoostFieldMapper.Builder builder = MapperBuilders.boost(name); - parseNumberField(builder, name, node, parserContext); - for (Iterator> iterator = node.entrySet().iterator(); iterator.hasNext();) { - Map.Entry entry = iterator.next(); - String propName = Strings.toUnderscoreCase(entry.getKey()); - Object propNode = entry.getValue(); - if (propName.equals("null_value")) { - builder.nullValue(nodeFloatValue(propNode)); - iterator.remove(); - } - } - return builder; - } - } - - private final Float nullValue; - - public BoostFieldMapper(Settings indexSettings) { - this(Defaults.NAME, Defaults.NAME, indexSettings); - } - - protected BoostFieldMapper(String name, String indexName, Settings indexSettings) { - this(name, indexName, Defaults.PRECISION_STEP_32_BIT, Defaults.BOOST, new FieldType(Defaults.FIELD_TYPE), null, - Defaults.NULL_VALUE, null, indexSettings); - } - - protected BoostFieldMapper(String name, String indexName, int precisionStep, float boost, FieldType fieldType, Boolean docValues, Float nullValue, - @Nullable Settings fieldDataSettings, Settings indexSettings) { - super(new Names(name, indexName, indexName, name), precisionStep, boost, fieldType, docValues, Defaults.IGNORE_MALFORMED, Defaults.COERCE, - NumericFloatAnalyzer.buildNamedAnalyzer(precisionStep), NumericFloatAnalyzer.buildNamedAnalyzer(Integer.MAX_VALUE), - null, null, fieldDataSettings, indexSettings, MultiFields.empty(), null); - this.nullValue = nullValue; - } - - @Override - public FieldType defaultFieldType() { - return Defaults.FIELD_TYPE; - } - - @Override - public FieldDataType defaultFieldDataType() { - return new FieldDataType("float"); - } - - @Override - public boolean hasDocValues() { - return false; - } - - @Override - protected int maxPrecisionStep() { - return 32; - } - - @Override - public Float value(Object value) { - if (value == null) { - return null; - } - if (value instanceof Number) { - return ((Number) value).floatValue(); - } - if (value instanceof BytesRef) { - return Numbers.bytesToFloat((BytesRef) value); - } - return Float.parseFloat(value.toString()); - } - - @Override - public BytesRef indexedValueForSearch(Object value) { - int intValue = NumericUtils.floatToSortableInt(parseValue(value)); - BytesRefBuilder bytesRef = new BytesRefBuilder(); - NumericUtils.intToPrefixCoded(intValue, precisionStep(), bytesRef); - return bytesRef.get(); - } - - private float parseValue(Object value) { - if (value instanceof Number) { - return ((Number) value).floatValue(); - } - if (value instanceof BytesRef) { - return Float.parseFloat(((BytesRef) value).utf8ToString()); - } - return Float.parseFloat(value.toString()); - } - - @Override - public Query fuzzyQuery(String value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) { - float iValue = Float.parseFloat(value); - float iSim = fuzziness.asFloat(); - return NumericRangeQuery.newFloatRange(names.indexName(), precisionStep, - iValue - iSim, - iValue + iSim, - true, true); - } - - @Override - public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, @Nullable QueryParseContext context) { - return NumericRangeQuery.newFloatRange(names.indexName(), precisionStep, - lowerTerm == null ? null : parseValue(lowerTerm), - upperTerm == null ? null : parseValue(upperTerm), - includeLower, includeUpper); - } - - @Override - public Filter rangeFilter(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, @Nullable QueryParseContext context) { - return NumericRangeFilter.newFloatRange(names.indexName(), precisionStep, - lowerTerm == null ? null : parseValue(lowerTerm), - upperTerm == null ? null : parseValue(upperTerm), - includeLower, includeUpper); - } - - @Override - public Filter rangeFilter(QueryParseContext parseContext, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, @Nullable QueryParseContext context) { - return NumericRangeFieldDataFilter.newFloatRange((IndexNumericFieldData) parseContext.getForField(this), - lowerTerm == null ? null : parseValue(lowerTerm), - upperTerm == null ? null : parseValue(upperTerm), - includeLower, includeUpper); - } - - @Override - public Filter nullValueFilter() { - if (nullValue == null) { - return null; - } - return NumericRangeFilter.newFloatRange(names.indexName(), precisionStep, - nullValue, - nullValue, - true, true); - } - - @Override - public void preParse(ParseContext context) throws IOException { - } - - @Override - public void postParse(ParseContext context) throws IOException { - } - - @Override - public boolean includeInObject() { - return true; - } - - @Override - public void parse(ParseContext context) throws IOException { - // we override parse since we want to handle cases where it is not indexed and not stored (the default) - float value = parseFloatValue(context); - if (!Float.isNaN(value)) { - context.docBoost(value); - } - super.parse(context); - } - - @Override - protected void innerParseCreateField(ParseContext context, List fields) throws IOException { - final float value = parseFloatValue(context); - if (Float.isNaN(value)) { - return; - } - context.docBoost(value); - fields.add(new FloatFieldMapper.CustomFloatNumericField(this, value, fieldType)); - } - - private float parseFloatValue(ParseContext context) throws IOException { - float value; - if (context.parser().currentToken() == XContentParser.Token.VALUE_NULL) { - if (nullValue == null) { - return Float.NaN; - } - value = nullValue; - } else { - value = context.parser().floatValue(coerce.value()); - } - return value; - } - - @Override - protected String contentType() { - return CONTENT_TYPE; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - boolean includeDefaults = params.paramAsBoolean("include_defaults", false); - boolean indexed = fieldType.indexOptions() != IndexOptions.NONE; - boolean indexedDefault = Defaults.FIELD_TYPE.indexOptions() != IndexOptions.NONE; - - // all are defaults, don't write it at all - if (!includeDefaults && name().equals(Defaults.NAME) && nullValue == null && - indexed == indexedDefault && - fieldType.stored() == Defaults.FIELD_TYPE.stored() && - customFieldDataSettings == null) { - return builder; - } - builder.startObject(contentType()); - if (includeDefaults || !name().equals(Defaults.NAME)) { - builder.field("name", name()); - } - if (includeDefaults || nullValue != null) { - builder.field("null_value", nullValue); - } - if (includeDefaults || indexed != indexedDefault) { - builder.field("index", indexTokenizeOptionToString(indexed, fieldType.tokenized())); - } - if (includeDefaults || fieldType.stored() != Defaults.FIELD_TYPE.stored()) { - builder.field("store", fieldType.stored()); - } - if (customFieldDataSettings != null) { - builder.field("fielddata", (Map) customFieldDataSettings.getAsMap()); - } else if (includeDefaults) { - builder.field("fielddata", (Map) fieldDataType.getSettings().getAsMap()); - - } - builder.endObject(); - return builder; - } - - @Override - public void merge(Mapper mergeWith, MergeContext mergeContext) throws MergeMappingException { - // do nothing here, no merging, but also no exception - } -} diff --git a/src/test/java/org/elasticsearch/get/GetActionTests.java b/src/test/java/org/elasticsearch/get/GetActionTests.java index 2b45217ab6f68..bb2b52c9ee660 100644 --- a/src/test/java/org/elasticsearch/get/GetActionTests.java +++ b/src/test/java/org/elasticsearch/get/GetActionTests.java @@ -1008,7 +1008,7 @@ public void testUngeneratedFieldsThatAreAlwaysStored() throws IOException { @Test public void testUngeneratedFieldsPartOfSourceUnstoredSourceDisabled() throws IOException { indexSingleDocumentWithUngeneratedFieldsThatArePartOf_source(false, false); - String[] fieldsList = {"my_boost"}; + String[] fieldsList = {}; // before refresh - document is only in translog assertGetFieldsAlwaysNull(indexOrAlias(), "doc", "1", fieldsList); refresh(); @@ -1027,7 +1027,7 @@ public void testUngeneratedFieldsPartOfSourceEitherStoredOrSourceEnabled() throw sourceEnabled = randomBoolean(); } indexSingleDocumentWithUngeneratedFieldsThatArePartOf_source(stored, sourceEnabled); - String[] fieldsList = {"my_boost"}; + String[] fieldsList = {}; // before refresh - document is only in translog assertGetFieldsAlwaysWorks(indexOrAlias(), "doc", "1", fieldsList); refresh(); @@ -1049,11 +1049,6 @@ void indexSingleDocumentWithUngeneratedFieldsThatArePartOf_source(boolean stored " \"doc\": {\n" + " \"_source\": {\n" + " \"enabled\": " + sourceEnabled + "\n" + - " },\n" + - " \"_boost\": {\n" + - " \"name\": \"my_boost\",\n" + - " \"null_value\": 1,\n" + - " \"store\": \"" + storedString + "\"\n" + " }\n" + " }\n" + " }\n" + diff --git a/src/test/java/org/elasticsearch/index/mapper/all/test1.json b/src/test/java/org/elasticsearch/index/mapper/all/test1.json index 834400a48cbe8..9e1d8784f8ea5 100644 --- a/src/test/java/org/elasticsearch/index/mapper/all/test1.json +++ b/src/test/java/org/elasticsearch/index/mapper/all/test1.json @@ -1,5 +1,4 @@ { - "_boost":3.7, "_id":"1", "name":{ "first":"shay", diff --git a/src/test/java/org/elasticsearch/index/mapper/boost/BoostMappingIntegrationTests.java b/src/test/java/org/elasticsearch/index/mapper/boost/BoostMappingIntegrationTests.java deleted file mode 100644 index 826fa48144955..0000000000000 --- a/src/test/java/org/elasticsearch/index/mapper/boost/BoostMappingIntegrationTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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. - */ - -package org.elasticsearch.index.mapper.boost; - -import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.test.ElasticsearchIntegrationTest; -import org.junit.Test; - -import java.util.LinkedHashMap; -import java.util.Map; - -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.equalTo; - - -public class BoostMappingIntegrationTests extends ElasticsearchIntegrationTest { - - @Test - public void testSetValues() throws Exception { - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") - .startObject("_boost") - .field("store", "yes").field("index", "not_analyzed") - .endObject() - .endObject().endObject().string(); - assertAcked(prepareCreate("test").addMapping("type", mapping)); - ensureYellow(); - GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings().addIndices("test").addTypes("type").setFields("_boost").get(); - assertTrue(response.mappings().containsKey("test")); - assertNotNull(response.fieldMappings("test", "type", "_boost")); - Map boostSource = response.fieldMappings("test", "type", "_boost").sourceAsMap(); - assertThat((Boolean)((LinkedHashMap)(boostSource.get("_boost"))).get("store"), equalTo(true)); - assertThat((String)((LinkedHashMap)(boostSource.get("_boost"))).get("index"), equalTo("not_analyzed")); - } -} diff --git a/src/test/java/org/elasticsearch/index/mapper/boost/BoostMappingTests.java b/src/test/java/org/elasticsearch/index/mapper/boost/BoostMappingTests.java deleted file mode 100644 index e1f159fa5bd49..0000000000000 --- a/src/test/java/org/elasticsearch/index/mapper/boost/BoostMappingTests.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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. - */ - -package org.elasticsearch.index.mapper.boost; - -import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexableField; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.index.mapper.DocumentMapper; -import org.elasticsearch.index.mapper.ParsedDocument; -import org.elasticsearch.index.mapper.internal.BoostFieldMapper; -import org.elasticsearch.index.IndexService; -import org.elasticsearch.test.ElasticsearchSingleNodeTest; -import org.junit.Test; - -import static org.hamcrest.Matchers.equalTo; - -/** - */ -public class BoostMappingTests extends ElasticsearchSingleNodeTest { - - @Test - public void testDefaultMapping() throws Exception { - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(); - - DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping); - - ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder().startObject() - .field("_boost", 2.0f) - .field("field", "a") - .field("field", "b") - .endObject().bytes()); - - // one fo the same named field will have the proper boost, the others will have 1 - IndexableField[] fields = doc.rootDoc().getFields("field"); - assertThat(fields[0].boost(), equalTo(2.0f)); - assertThat(fields[1].boost(), equalTo(1.0f)); - } - - @Test - public void testCustomName() throws Exception { - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") - .startObject("_boost").field("name", "custom_boost").endObject() - .endObject().endObject().string(); - - DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse(mapping); - - ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder().startObject() - .field("field", "a") - .field("_boost", 2.0f) - .endObject().bytes()); - assertThat(doc.rootDoc().getField("field").boost(), equalTo(1.0f)); - - doc = mapper.parse("type", "1", XContentFactory.jsonBuilder().startObject() - .field("field", "a") - .field("custom_boost", 2.0f) - .endObject().bytes()); - assertThat(doc.rootDoc().getField("field").boost(), equalTo(2.0f)); - } - - @Test - public void testDefaultValues() throws Exception { - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string(); - DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping); - assertThat(docMapper.boostFieldMapper().fieldType().stored(), equalTo(BoostFieldMapper.Defaults.FIELD_TYPE.stored())); - assertThat(docMapper.boostFieldMapper().fieldType().indexOptions(), equalTo(BoostFieldMapper.Defaults.FIELD_TYPE.indexOptions())); - } - - @Test - public void testSetValues() throws Exception { - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") - .startObject("_boost") - .field("store", "yes").field("index", "not_analyzed") - .endObject() - .endObject().endObject().string(); - IndexService indexServices = createIndex("test"); - DocumentMapper docMapper = indexServices.mapperService().documentMapperParser().parse("type", mapping); - assertThat(docMapper.boostFieldMapper().fieldType().stored(), equalTo(true)); - assertEquals(IndexOptions.DOCS, docMapper.boostFieldMapper().fieldType().indexOptions()); - docMapper.refreshSource(); - docMapper = indexServices.mapperService().documentMapperParser().parse("type", docMapper.mappingSource().string()); - assertThat(docMapper.boostFieldMapper().fieldType().stored(), equalTo(true)); - assertEquals(IndexOptions.DOCS, docMapper.boostFieldMapper().fieldType().indexOptions()); - } -} diff --git a/src/test/java/org/elasticsearch/index/mapper/simple/test-mapping.json b/src/test/java/org/elasticsearch/index/mapper/simple/test-mapping.json index ce2805cabc41f..e001673758a66 100644 --- a/src/test/java/org/elasticsearch/index/mapper/simple/test-mapping.json +++ b/src/test/java/org/elasticsearch/index/mapper/simple/test-mapping.json @@ -8,9 +8,6 @@ enabled:true, _source:{ }, - _boost:{ - null_value:2.0 - }, properties:{ name:{ type:"object", diff --git a/src/test/java/org/elasticsearch/index/mapper/simple/test1-notype-noid.json b/src/test/java/org/elasticsearch/index/mapper/simple/test1-notype-noid.json index 745617a500039..eb71b7a82048c 100644 --- a/src/test/java/org/elasticsearch/index/mapper/simple/test1-notype-noid.json +++ b/src/test/java/org/elasticsearch/index/mapper/simple/test1-notype-noid.json @@ -1,5 +1,4 @@ { - _boost:3.7, name:{ first:"shay", last:"banon" diff --git a/src/test/java/org/elasticsearch/index/mapper/simple/test1-notype.json b/src/test/java/org/elasticsearch/index/mapper/simple/test1-notype.json index 7f38d0d3343cd..e91f2f543d6f4 100644 --- a/src/test/java/org/elasticsearch/index/mapper/simple/test1-notype.json +++ b/src/test/java/org/elasticsearch/index/mapper/simple/test1-notype.json @@ -1,5 +1,4 @@ { - _boost:3.7, _id:"1", name:{ first:"shay", diff --git a/src/test/java/org/elasticsearch/index/mapper/simple/test1-withtype.json b/src/test/java/org/elasticsearch/index/mapper/simple/test1-withtype.json index 096554abb201b..5711d5835b357 100644 --- a/src/test/java/org/elasticsearch/index/mapper/simple/test1-withtype.json +++ b/src/test/java/org/elasticsearch/index/mapper/simple/test1-withtype.json @@ -1,6 +1,5 @@ { person:{ - _boost:3.7, _id:"1", name:{ first:"shay", diff --git a/src/test/java/org/elasticsearch/index/mapper/simple/test1.json b/src/test/java/org/elasticsearch/index/mapper/simple/test1.json index 93507daffefe8..70ba1a5f87d08 100644 --- a/src/test/java/org/elasticsearch/index/mapper/simple/test1.json +++ b/src/test/java/org/elasticsearch/index/mapper/simple/test1.json @@ -1,5 +1,4 @@ { - _boost:3.7, _id:"1", name:{ first:"shay", diff --git a/src/test/java/org/elasticsearch/search/basic/TransportSearchFailuresTests.java b/src/test/java/org/elasticsearch/search/basic/TransportSearchFailuresTests.java index 2585da605daaa..2336dcc60faad 100644 --- a/src/test/java/org/elasticsearch/search/basic/TransportSearchFailuresTests.java +++ b/src/test/java/org/elasticsearch/search/basic/TransportSearchFailuresTests.java @@ -123,7 +123,6 @@ private XContentBuilder source(String id, String nameValue, int age) throws IOEx .field("name", nameValue + id) .field("age", age) .field("multi", multi.toString()) - .field("_boost", age * 10) .endObject(); } } diff --git a/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchTests.java b/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchTests.java index 3738e81d905fe..aa242bd8128f7 100644 --- a/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchTests.java +++ b/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchTests.java @@ -60,9 +60,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.hamcrest.Matchers.*; -/** - * - */ public class TransportTwoNodesSearchTests extends ElasticsearchIntegrationTest { @Override @@ -113,13 +110,27 @@ private XContentBuilder source(String id, String nameValue, int age) throws IOEx .field("name", nameValue + id) .field("age", age) .field("multi", multi.toString()) - .field("_boost", age * 10) .endObject(); } @Test public void testDfsQueryThenFetch() throws Exception { - prepareData(); + ImmutableSettings.Builder settingsBuilder = settingsBuilder() + .put(indexSettings()) + .put("routing.hash.type", "simple"); + client().admin().indices().create(createIndexRequest("test") + .settings(settingsBuilder)) + .actionGet(); + ensureGreen(); + + // we need to have age (ie number of repeats of "test" term) high enough + // to produce the same 8-bit norm for all docs here, so that + // the tf is basically the entire score (assuming idf is fixed, which + // it should be if dfs is working correctly) + for (int i = 1024; i < 1124; i++) { + index(Integer.toString(i - 1024), "test", i); + } + refresh(); int total = 0; SearchResponse searchResponse = client().prepareSearch("test").setSearchType(DFS_QUERY_THEN_FETCH).setQuery(termQuery("multi", "test")).setSize(60).setExplain(true).setScroll(TimeValue.timeValueSeconds(30)).get(); @@ -133,7 +144,7 @@ public void testDfsQueryThenFetch() throws Exception { for (int i = 0; i < hits.length; ++i) { SearchHit hit = hits[i]; assertThat(hit.explanation(), notNullValue()); - assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - total - i - 1))); + assertThat("id[" + hit.id() + "] -> " + hit.explanation().toString(), hit.id(), equalTo(Integer.toString(100 - total - i - 1))); } total += hits.length; searchResponse = client().prepareSearchScroll(searchResponse.getScrollId()).setScroll(TimeValue.timeValueSeconds(30)).get(); diff --git a/src/test/java/org/elasticsearch/search/sort/SimpleSortTests.java b/src/test/java/org/elasticsearch/search/sort/SimpleSortTests.java index 52f4bd4f2af85..24b5403ac0038 100644 --- a/src/test/java/org/elasticsearch/search/sort/SimpleSortTests.java +++ b/src/test/java/org/elasticsearch/search/sort/SimpleSortTests.java @@ -155,7 +155,7 @@ public void testIssue6614() throws ExecutionException, InterruptedException { public void testIssue6639() throws ExecutionException, InterruptedException { assertAcked(prepareCreate("$index") - .addMapping("$type","{\"$type\": {\"_boost\": {\"name\": \"boost\", \"null_value\": 1.0}, \"properties\": {\"grantee\": {\"index\": \"not_analyzed\", \"term_vector\": \"with_positions_offsets\", \"type\": \"string\", \"analyzer\": \"snowball\", \"boost\": 1.0, \"store\": \"yes\"}}}}")); + .addMapping("$type","{\"$type\": {\"properties\": {\"grantee\": {\"index\": \"not_analyzed\", \"term_vector\": \"with_positions_offsets\", \"type\": \"string\", \"analyzer\": \"snowball\", \"boost\": 1.0, \"store\": \"yes\"}}}}")); indexRandom(true, client().prepareIndex("$index", "$type", "data.activity.5").setSource("{\"django_ct\": \"data.activity\", \"grantee\": \"Grantee 1\"}"), client().prepareIndex("$index", "$type", "data.activity.6").setSource("{\"django_ct\": \"data.activity\", \"grantee\": \"Grantee 2\"}")); diff --git a/src/test/resources/org/elasticsearch/bwcompat/index-1.4.2.zip b/src/test/resources/org/elasticsearch/bwcompat/index-1.4.2.zip index 6b601dd4adfcd..6602a1dd6ad24 100644 Binary files a/src/test/resources/org/elasticsearch/bwcompat/index-1.4.2.zip and b/src/test/resources/org/elasticsearch/bwcompat/index-1.4.2.zip differ diff --git a/src/test/resources/org/elasticsearch/bwcompat/repo-1.4.2.zip b/src/test/resources/org/elasticsearch/bwcompat/repo-1.4.2.zip index 7e85abbf2e9ec..01a874201497a 100644 Binary files a/src/test/resources/org/elasticsearch/bwcompat/repo-1.4.2.zip and b/src/test/resources/org/elasticsearch/bwcompat/repo-1.4.2.zip differ