Merge pull request #15684 from jpountz/deprecate/field_boost
Remove object notation for core types.
This commit is contained in:
commit
a7e1eeb13d
|
@ -28,6 +28,7 @@ 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.Version;
|
||||
import org.elasticsearch.action.fieldstats.FieldStats;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -251,7 +252,8 @@ public class ByteFieldMapper extends NumberFieldMapper {
|
|||
if (fieldType().nullValueAsString() != null && (context.includeInAll(includeInAll, this))) {
|
||||
context.allEntries().addText(fieldType().name(), fieldType().nullValueAsString(), boost);
|
||||
}
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT
|
||||
&& Version.indexCreated(context.indexSettings()).before(Version.V_3_0_0)) {
|
||||
XContentParser.Token token;
|
||||
String currentFieldName = null;
|
||||
Byte objValue = fieldType().nullValue();
|
||||
|
|
|
@ -489,7 +489,8 @@ public class DateFieldMapper extends NumberFieldMapper {
|
|||
dateAsString = fieldType().nullValueAsString();
|
||||
} else if (token == XContentParser.Token.VALUE_NUMBER) {
|
||||
dateAsString = parser.text();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
} else if (token == XContentParser.Token.START_OBJECT
|
||||
&& Version.indexCreated(context.indexSettings()).before(Version.V_3_0_0)) {
|
||||
String currentFieldName = null;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
|
|
|
@ -29,6 +29,7 @@ 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.Version;
|
||||
import org.elasticsearch.action.fieldstats.FieldStats;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
|
@ -243,7 +244,8 @@ public class DoubleFieldMapper extends NumberFieldMapper {
|
|||
if (fieldType().nullValueAsString() != null && (context.includeInAll(includeInAll, this))) {
|
||||
context.allEntries().addText(fieldType().name(), fieldType().nullValueAsString(), boost);
|
||||
}
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT
|
||||
&& Version.indexCreated(context.indexSettings()).before(Version.V_3_0_0)) {
|
||||
XContentParser.Token token;
|
||||
String currentFieldName = null;
|
||||
Double objValue = fieldType().nullValue();
|
||||
|
|
|
@ -29,6 +29,7 @@ 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.Version;
|
||||
import org.elasticsearch.action.fieldstats.FieldStats;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
|
@ -255,7 +256,8 @@ public class FloatFieldMapper extends NumberFieldMapper {
|
|||
if (fieldType().nullValueAsString() != null && (context.includeInAll(includeInAll, this))) {
|
||||
context.allEntries().addText(fieldType().name(), fieldType().nullValueAsString(), boost);
|
||||
}
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT
|
||||
&& Version.indexCreated(context.indexSettings()).before(Version.V_3_0_0)) {
|
||||
XContentParser.Token token;
|
||||
String currentFieldName = null;
|
||||
Float objValue = fieldType().nullValue();
|
||||
|
|
|
@ -29,6 +29,7 @@ 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.Version;
|
||||
import org.elasticsearch.action.fieldstats.FieldStats;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
|
@ -260,7 +261,8 @@ public class IntegerFieldMapper extends NumberFieldMapper {
|
|||
if (fieldType().nullValueAsString() != null && (context.includeInAll(includeInAll, this))) {
|
||||
context.allEntries().addText(fieldType().name(), fieldType().nullValueAsString(), boost);
|
||||
}
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT
|
||||
&& Version.indexCreated(context.indexSettings()).before(Version.V_3_0_0)) {
|
||||
XContentParser.Token token;
|
||||
String currentFieldName = null;
|
||||
Integer objValue = fieldType().nullValue();
|
||||
|
|
|
@ -29,6 +29,7 @@ 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.Version;
|
||||
import org.elasticsearch.action.fieldstats.FieldStats;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
|
@ -248,7 +249,8 @@ public class LongFieldMapper extends NumberFieldMapper {
|
|||
if (fieldType().nullValueAsString() != null && (context.includeInAll(includeInAll, this))) {
|
||||
context.allEntries().addText(fieldType().name(), fieldType().nullValueAsString(), boost);
|
||||
}
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT
|
||||
&& Version.indexCreated(context.indexSettings()).before(Version.V_3_0_0)) {
|
||||
XContentParser.Token token;
|
||||
String currentFieldName = null;
|
||||
Long objValue = fieldType().nullValue();
|
||||
|
|
|
@ -29,6 +29,7 @@ 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.Version;
|
||||
import org.elasticsearch.action.fieldstats.FieldStats;
|
||||
import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
|
@ -256,7 +257,8 @@ public class ShortFieldMapper extends NumberFieldMapper {
|
|||
if (fieldType().nullValueAsString() != null && (context.includeInAll(includeInAll, this))) {
|
||||
context.allEntries().addText(fieldType().name(), fieldType().nullValueAsString(), boost);
|
||||
}
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
||||
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT
|
||||
&& Version.indexCreated(context.indexSettings()).before(Version.V_3_0_0)) {
|
||||
XContentParser.Token token;
|
||||
String currentFieldName = null;
|
||||
Short objValue = fieldType().nullValue();
|
||||
|
|
|
@ -344,7 +344,8 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
|||
if (parser.currentToken() == XContentParser.Token.VALUE_NULL) {
|
||||
return new ValueAndBoost(nullValue, defaultBoost);
|
||||
}
|
||||
if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
||||
if (parser.currentToken() == XContentParser.Token.START_OBJECT
|
||||
&& Version.indexCreated(context.indexSettings()).before(Version.V_3_0_0)) {
|
||||
XContentParser.Token token;
|
||||
String currentFieldName = null;
|
||||
String value = nullValue;
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
|
||||
package org.elasticsearch.index.mapper.boost;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||
|
@ -28,7 +31,10 @@ import org.elasticsearch.test.ESSingleNodeTestCase;
|
|||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class CustomBoostMappingTests extends ESSingleNodeTestCase {
|
||||
public void testCustomBoostValues() throws Exception {
|
||||
|
||||
private static final Settings BW_SETTINGS = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_0_0).build();
|
||||
|
||||
public void testBackCompatCustomBoostValues() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
.startObject("s_field").field("type", "string").endObject()
|
||||
.startObject("l_field").field("type", "long").startObject("norms").field("enabled", true).endObject().endObject()
|
||||
|
@ -40,7 +46,7 @@ public class CustomBoostMappingTests extends ESSingleNodeTestCase {
|
|||
.startObject("date_field").field("type", "date").startObject("norms").field("enabled", true).endObject().endObject()
|
||||
.endObject().endObject().endObject().string();
|
||||
|
||||
DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
DocumentMapper mapper = createIndex("test", BW_SETTINGS).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject()
|
||||
.startObject("s_field").field("value", "s_value").field("boost", 2.0f).endObject()
|
||||
|
|
|
@ -20,8 +20,11 @@
|
|||
package org.elasticsearch.index.mapper.boost;
|
||||
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
|
@ -33,7 +36,10 @@ import static org.hamcrest.Matchers.closeTo;
|
|||
/**
|
||||
*/
|
||||
public class FieldLevelBoostTests extends ESSingleNodeTestCase {
|
||||
public void testFieldLevelBoost() throws Exception {
|
||||
|
||||
private static final Settings BW_SETTINGS = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_0_0).build();
|
||||
|
||||
public void testBackCompatFieldLevelBoost() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("person").startObject("properties")
|
||||
.startObject("str_field").field("type", "string").endObject()
|
||||
.startObject("int_field").field("type", "integer").startObject("norms").field("enabled", true).endObject().endObject()
|
||||
|
@ -45,7 +51,7 @@ public class FieldLevelBoostTests extends ESSingleNodeTestCase {
|
|||
.startObject("short_field").field("type", "short").startObject("norms").field("enabled", true).endObject().endObject()
|
||||
.string();
|
||||
|
||||
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping));
|
||||
DocumentMapper docMapper = createIndex("test", BW_SETTINGS).mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping));
|
||||
BytesReference json = XContentFactory.jsonBuilder().startObject()
|
||||
.startObject("str_field").field("boost", 2.0).field("value", "some name").endObject()
|
||||
.startObject("int_field").field("boost", 3.0).field("value", 10).endObject()
|
||||
|
@ -83,7 +89,7 @@ public class FieldLevelBoostTests extends ESSingleNodeTestCase {
|
|||
assertThat((double) f.boost(), closeTo(9.0, 0.001));
|
||||
}
|
||||
|
||||
public void testInvalidFieldLevelBoost() throws Exception {
|
||||
public void testBackCompatInvalidFieldLevelBoost() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("person").startObject("properties")
|
||||
.startObject("str_field").field("type", "string").endObject()
|
||||
.startObject("int_field").field("type", "integer").startObject("norms").field("enabled", true).endObject().endObject()
|
||||
|
@ -95,7 +101,7 @@ public class FieldLevelBoostTests extends ESSingleNodeTestCase {
|
|||
.startObject("short_field").field("type", "short").startObject("norms").field("enabled", true).endObject().endObject()
|
||||
.string();
|
||||
|
||||
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping));
|
||||
DocumentMapper docMapper = createIndex("test", BW_SETTINGS).mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping));
|
||||
try {
|
||||
docMapper.parse("test", "person", "1", XContentFactory.jsonBuilder().startObject()
|
||||
.startObject("str_field").field("foo", "bar")
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
|
||||
package org.elasticsearch.index.mapper.compound;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||
|
@ -29,14 +32,17 @@ import static org.hamcrest.Matchers.closeTo;
|
|||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class CompoundTypesTests extends ESSingleNodeTestCase {
|
||||
public void testStringType() throws Exception {
|
||||
|
||||
private static final Settings BW_SETTINGS = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_0_0).build();
|
||||
|
||||
public void testBackCompatStringType() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||
.startObject("properties")
|
||||
.startObject("field1").field("type", "string").endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
DocumentMapper defaultMapper = createIndex("test", BW_SETTINGS).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
|
|
|
@ -245,6 +245,20 @@ will still be accepted for indices created before the upgrade to 3.0 for backwar
|
|||
compatibility, but it will have no effect. Indices created on or after 3.0 will
|
||||
reject this option.
|
||||
|
||||
==== Object notation
|
||||
|
||||
Core types don't support the object notation anymore, which allowed to provide
|
||||
values as follows:
|
||||
|
||||
[source,json]
|
||||
-----
|
||||
{
|
||||
"value": "field_value",
|
||||
"boost": 42
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
[[breaking_30_plugins]]
|
||||
=== Plugin changes
|
||||
|
||||
|
|
Loading…
Reference in New Issue