diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml index bd6d321bb17..f3ac73690a9 100644 --- a/buildSrc/src/main/resources/checkstyle_suppressions.xml +++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml @@ -596,7 +596,6 @@ - diff --git a/core/src/main/java/org/elasticsearch/index/mapper/CustomDocValuesField.java b/core/src/main/java/org/elasticsearch/index/mapper/CustomDocValuesField.java index 60fbfc0698c..f77d480e722 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/CustomDocValuesField.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/CustomDocValuesField.java @@ -28,8 +28,8 @@ import org.apache.lucene.index.IndexableFieldType; import java.io.Reader; -// used for binary and geo fields -abstract class CustomDocValuesField implements IndexableField { +// used for binary, geo and range fields +public abstract class CustomDocValuesField implements IndexableField { public static final FieldType TYPE = new FieldType(); static { @@ -39,7 +39,7 @@ abstract class CustomDocValuesField implements IndexableField { private final String name; - CustomDocValuesField(String name) { + protected CustomDocValuesField(String name) { this.name = name; } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java index 6f5190b6376..83ebd6d9fb5 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java @@ -62,8 +62,7 @@ import java.util.Objects; /** A {@link FieldMapper} for numeric types: byte, short, int, long, float and double. */ public class NumberFieldMapper extends FieldMapper { - // this is private since it has a different default - static final Setting COERCE_SETTING = + public static final Setting COERCE_SETTING = Setting.boolSetting("index.mapping.coerce", true, Property.IndexScope); public static class Defaults { @@ -162,7 +161,7 @@ public class NumberFieldMapper extends FieldMapper { public enum NumberType { HALF_FLOAT("half_float", NumericType.HALF_FLOAT) { @Override - Float parse(Object value, boolean coerce) { + public Float parse(Object value, boolean coerce) { final float result; if (value instanceof Number) { @@ -178,20 +177,20 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Float parse(XContentParser parser, boolean coerce) throws IOException { + public Float parse(XContentParser parser, boolean coerce) throws IOException { float parsed = parser.floatValue(coerce); validateParsed(parsed); return parsed; } @Override - Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value) { float v = parse(value, false); return HalfFloatPoint.newExactQuery(field, v); } @Override - Query termsQuery(String field, List values) { + public Query termsQuery(String field, List values) { float[] v = new float[values.size()]; for (int i = 0; i < values.size(); ++i) { v[i] = parse(values.get(i), false); @@ -200,7 +199,7 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Query rangeQuery(String field, Object lowerTerm, Object upperTerm, + public Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, boolean hasDocValues) { float l = Float.NEGATIVE_INFINITY; @@ -254,7 +253,7 @@ public class NumberFieldMapper extends FieldMapper { }, FLOAT("float", NumericType.FLOAT) { @Override - Float parse(Object value, boolean coerce) { + public Float parse(Object value, boolean coerce) { final float result; if (value instanceof Number) { @@ -270,20 +269,20 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Float parse(XContentParser parser, boolean coerce) throws IOException { + public Float parse(XContentParser parser, boolean coerce) throws IOException { float parsed = parser.floatValue(coerce); validateParsed(parsed); return parsed; } @Override - Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value) { float v = parse(value, false); return FloatPoint.newExactQuery(field, v); } @Override - Query termsQuery(String field, List values) { + public Query termsQuery(String field, List values) { float[] v = new float[values.size()]; for (int i = 0; i < values.size(); ++i) { v[i] = parse(values.get(i), false); @@ -292,7 +291,7 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Query rangeQuery(String field, Object lowerTerm, Object upperTerm, + public Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, boolean hasDocValues) { float l = Float.NEGATIVE_INFINITY; @@ -344,27 +343,27 @@ public class NumberFieldMapper extends FieldMapper { }, DOUBLE("double", NumericType.DOUBLE) { @Override - Double parse(Object value, boolean coerce) { + public Double parse(Object value, boolean coerce) { double parsed = objectToDouble(value); validateParsed(parsed); return parsed; } @Override - Double parse(XContentParser parser, boolean coerce) throws IOException { + public Double parse(XContentParser parser, boolean coerce) throws IOException { double parsed = parser.doubleValue(coerce); validateParsed(parsed); return parsed; } @Override - Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value) { double v = parse(value, false); return DoublePoint.newExactQuery(field, v); } @Override - Query termsQuery(String field, List values) { + public Query termsQuery(String field, List values) { double[] v = new double[values.size()]; for (int i = 0; i < values.size(); ++i) { v[i] = parse(values.get(i), false); @@ -373,7 +372,7 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Query rangeQuery(String field, Object lowerTerm, Object upperTerm, + public Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, boolean hasDocValues) { double l = Double.NEGATIVE_INFINITY; @@ -425,7 +424,7 @@ public class NumberFieldMapper extends FieldMapper { }, BYTE("byte", NumericType.BYTE) { @Override - Byte parse(Object value, boolean coerce) { + public Byte parse(Object value, boolean coerce) { double doubleValue = objectToDouble(value); if (doubleValue < Byte.MIN_VALUE || doubleValue > Byte.MAX_VALUE) { @@ -443,7 +442,7 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Short parse(XContentParser parser, boolean coerce) throws IOException { + public Short parse(XContentParser parser, boolean coerce) throws IOException { int value = parser.intValue(coerce); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { throw new IllegalArgumentException("Value [" + value + "] is out of range for a byte"); @@ -452,17 +451,17 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value) { return INTEGER.termQuery(field, value); } @Override - Query termsQuery(String field, List values) { + public Query termsQuery(String field, List values) { return INTEGER.termsQuery(field, values); } @Override - Query rangeQuery(String field, Object lowerTerm, Object upperTerm, + public Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, boolean hasDocValues) { return INTEGER.rangeQuery(field, lowerTerm, upperTerm, includeLower, includeUpper, hasDocValues); @@ -481,7 +480,7 @@ public class NumberFieldMapper extends FieldMapper { }, SHORT("short", NumericType.SHORT) { @Override - Short parse(Object value, boolean coerce) { + public Short parse(Object value, boolean coerce) { double doubleValue = objectToDouble(value); if (doubleValue < Short.MIN_VALUE || doubleValue > Short.MAX_VALUE) { @@ -499,22 +498,22 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Short parse(XContentParser parser, boolean coerce) throws IOException { + public Short parse(XContentParser parser, boolean coerce) throws IOException { return parser.shortValue(coerce); } @Override - Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value) { return INTEGER.termQuery(field, value); } @Override - Query termsQuery(String field, List values) { + public Query termsQuery(String field, List values) { return INTEGER.termsQuery(field, values); } @Override - Query rangeQuery(String field, Object lowerTerm, Object upperTerm, + public Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, boolean hasDocValues) { return INTEGER.rangeQuery(field, lowerTerm, upperTerm, includeLower, includeUpper, hasDocValues); @@ -533,7 +532,7 @@ public class NumberFieldMapper extends FieldMapper { }, INTEGER("integer", NumericType.INT) { @Override - Integer parse(Object value, boolean coerce) { + public Integer parse(Object value, boolean coerce) { double doubleValue = objectToDouble(value); if (doubleValue < Integer.MIN_VALUE || doubleValue > Integer.MAX_VALUE) { @@ -551,12 +550,12 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Integer parse(XContentParser parser, boolean coerce) throws IOException { + public Integer parse(XContentParser parser, boolean coerce) throws IOException { return parser.intValue(coerce); } @Override - Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value) { if (hasDecimalPart(value)) { return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part"); } @@ -565,7 +564,7 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Query termsQuery(String field, List values) { + public Query termsQuery(String field, List values) { int[] v = new int[values.size()]; int upTo = 0; @@ -586,7 +585,7 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Query rangeQuery(String field, Object lowerTerm, Object upperTerm, + public Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, boolean hasDocValues) { int l = Integer.MIN_VALUE; @@ -644,7 +643,7 @@ public class NumberFieldMapper extends FieldMapper { }, LONG("long", NumericType.LONG) { @Override - Long parse(Object value, boolean coerce) { + public Long parse(Object value, boolean coerce) { if (value instanceof Long) { return (Long)value; } @@ -665,12 +664,12 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Long parse(XContentParser parser, boolean coerce) throws IOException { + public Long parse(XContentParser parser, boolean coerce) throws IOException { return parser.longValue(coerce); } @Override - Query termQuery(String field, Object value) { + public Query termQuery(String field, Object value) { if (hasDecimalPart(value)) { return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part"); } @@ -679,7 +678,7 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Query termsQuery(String field, List values) { + public Query termsQuery(String field, List values) { long[] v = new long[values.size()]; int upTo = 0; @@ -700,7 +699,7 @@ public class NumberFieldMapper extends FieldMapper { } @Override - Query rangeQuery(String field, Object lowerTerm, Object upperTerm, + public Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, boolean hasDocValues) { long l = Long.MIN_VALUE; @@ -773,13 +772,13 @@ public class NumberFieldMapper extends FieldMapper { final NumericType numericType() { return numericType; } - abstract Query termQuery(String field, Object value); - abstract Query termsQuery(String field, List values); - abstract Query rangeQuery(String field, Object lowerTerm, Object upperTerm, + public abstract Query termQuery(String field, Object value); + public abstract Query termsQuery(String field, List values); + public abstract Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, boolean hasDocValues); - abstract Number parse(XContentParser parser, boolean coerce) throws IOException; - abstract Number parse(Object value, boolean coerce); + public abstract Number parse(XContentParser parser, boolean coerce) throws IOException; + public abstract Number parse(Object value, boolean coerce); public abstract List createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored); Number valueForSearch(Number value) { diff --git a/core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java index bdf2b6cf530..0d4ded10d2c 100644 --- a/core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java @@ -39,7 +39,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.mapper.FieldNamesFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.mapper.RangeFieldMapper; import org.joda.time.DateTimeZone; import java.io.IOException; diff --git a/core/src/main/java/org/elasticsearch/index/search/QueryParserHelper.java b/core/src/main/java/org/elasticsearch/index/search/QueryParserHelper.java index e6846543b8c..18a124d86b3 100644 --- a/core/src/main/java/org/elasticsearch/index/search/QueryParserHelper.java +++ b/core/src/main/java/org/elasticsearch/index/search/QueryParserHelper.java @@ -28,7 +28,6 @@ import org.elasticsearch.index.mapper.KeywordFieldMapper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MetadataFieldMapper; import org.elasticsearch.index.mapper.NumberFieldMapper; -import org.elasticsearch.index.mapper.ScaledFloatFieldMapper; import org.elasticsearch.index.mapper.TextFieldMapper; import org.elasticsearch.index.query.QueryShardContext; @@ -44,6 +43,7 @@ import java.util.Set; */ public final class QueryParserHelper { // Mapping types the "all-ish" query can be executed against + // TODO: Fix the API so that we don't need a hardcoded list of types private static final Set ALLOWED_QUERY_MAPPER_TYPES; static { @@ -54,7 +54,7 @@ public final class QueryParserHelper { for (NumberFieldMapper.NumberType nt : NumberFieldMapper.NumberType.values()) { ALLOWED_QUERY_MAPPER_TYPES.add(nt.typeName()); } - ALLOWED_QUERY_MAPPER_TYPES.add(ScaledFloatFieldMapper.CONTENT_TYPE); + ALLOWED_QUERY_MAPPER_TYPES.add("scaled_float"); ALLOWED_QUERY_MAPPER_TYPES.add(TextFieldMapper.CONTENT_TYPE); } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesModule.java b/core/src/main/java/org/elasticsearch/indices/IndicesModule.java index e1d2b169c7f..2751c34a7f3 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesModule.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesModule.java @@ -43,13 +43,10 @@ import org.elasticsearch.index.mapper.MetadataFieldMapper; import org.elasticsearch.index.mapper.NumberFieldMapper; import org.elasticsearch.index.mapper.ObjectMapper; import org.elasticsearch.index.mapper.ParentFieldMapper; -import org.elasticsearch.index.mapper.RangeFieldMapper; import org.elasticsearch.index.mapper.RoutingFieldMapper; -import org.elasticsearch.index.mapper.ScaledFloatFieldMapper; import org.elasticsearch.index.mapper.SeqNoFieldMapper; import org.elasticsearch.index.mapper.SourceFieldMapper; import org.elasticsearch.index.mapper.TextFieldMapper; -import org.elasticsearch.index.mapper.TokenCountFieldMapper; import org.elasticsearch.index.mapper.TypeFieldMapper; import org.elasticsearch.index.mapper.UidFieldMapper; import org.elasticsearch.index.mapper.VersionFieldMapper; @@ -95,17 +92,12 @@ public class IndicesModule extends AbstractModule { for (NumberFieldMapper.NumberType type : NumberFieldMapper.NumberType.values()) { mappers.put(type.typeName(), new NumberFieldMapper.TypeParser(type)); } - for (RangeFieldMapper.RangeType type : RangeFieldMapper.RangeType.values()) { - mappers.put(type.typeName(), new RangeFieldMapper.TypeParser(type)); - } mappers.put(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser()); mappers.put(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser()); mappers.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser()); mappers.put(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.TypeParser()); - mappers.put(ScaledFloatFieldMapper.CONTENT_TYPE, new ScaledFloatFieldMapper.TypeParser()); mappers.put(TextFieldMapper.CONTENT_TYPE, new TextFieldMapper.TypeParser()); mappers.put(KeywordFieldMapper.CONTENT_TYPE, new KeywordFieldMapper.TypeParser()); - mappers.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser()); mappers.put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser()); mappers.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser()); mappers.put(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser()); diff --git a/core/src/test/java/org/elasticsearch/get/GetActionIT.java b/core/src/test/java/org/elasticsearch/get/GetActionIT.java index f9c4b0d9606..1fd6084a231 100644 --- a/core/src/test/java/org/elasticsearch/get/GetActionIT.java +++ b/core/src/test/java/org/elasticsearch/get/GetActionIT.java @@ -19,7 +19,6 @@ package org.elasticsearch.get; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.ShardOperationFailedException; @@ -913,68 +912,6 @@ public class GetActionIT extends ESIntegTestCase { index("test", "doc", "1", doc); } - public void testGeneratedNumberFieldsUnstored() throws IOException { - indexSingleDocumentWithNumericFieldsGeneratedFromText(false, randomBoolean()); - String[] fieldsList = {"token_count", "text.token_count"}; - // before refresh - document is only in translog - assertGetFieldsAlwaysNull(indexOrAlias(), "doc", "1", fieldsList); - refresh(); - //after refresh - document is in translog and also indexed - assertGetFieldsAlwaysNull(indexOrAlias(), "doc", "1", fieldsList); - flush(); - //after flush - document is in not anymore translog - only indexed - assertGetFieldsAlwaysNull(indexOrAlias(), "doc", "1", fieldsList); - } - - public void testGeneratedNumberFieldsStored() throws IOException { - indexSingleDocumentWithNumericFieldsGeneratedFromText(true, randomBoolean()); - String[] fieldsList = {"token_count", "text.token_count"}; - assertGetFieldsAlwaysWorks(indexOrAlias(), "doc", "1", fieldsList); - flush(); - //after flush - document is in not anymore translog - only indexed - assertGetFieldsAlwaysWorks(indexOrAlias(), "doc", "1", fieldsList); - } - - void indexSingleDocumentWithNumericFieldsGeneratedFromText(boolean stored, boolean sourceEnabled) { - String storedString = stored ? "true" : "false"; - String createIndexSource = "{\n" + - " \"settings\": {\n" + - " \"index.translog.flush_threshold_size\": \"1pb\",\n" + - " \"refresh_interval\": \"-1\"\n" + - " },\n" + - " \"mappings\": {\n" + - " \"doc\": {\n" + - " \"_source\" : {\"enabled\" : " + sourceEnabled + "}," + - " \"properties\": {\n" + - " \"token_count\": {\n" + - " \"type\": \"token_count\",\n" + - " \"analyzer\": \"standard\",\n" + - " \"store\": \"" + storedString + "\"" + - " },\n" + - " \"text\": {\n" + - " \"type\": \"text\",\n" + - " \"fields\": {\n" + - " \"token_count\": {\n" + - " \"type\": \"token_count\",\n" + - " \"analyzer\": \"standard\",\n" + - " \"store\": \"" + storedString + "\"" + - " }\n" + - " }\n" + - " }" + - " }\n" + - " }\n" + - " }\n" + - "}"; - - assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource, XContentType.JSON)); - ensureGreen(); - String doc = "{\n" + - " \"token_count\": \"A text with five words.\",\n" + - " \"text\": \"A text with five words.\"\n" + - "}\n"; - index("test", "doc", "1", doc); - } - private void assertGetFieldsAlwaysWorks(String index, String type, String docId, String[] fields) { assertGetFieldsAlwaysWorks(index, type, docId, fields, null); } @@ -997,18 +934,6 @@ public class GetActionIT extends ESIntegTestCase { assertNotNull(response.getField(field)); } - private void assertGetFieldException(String index, String type, String docId, String field) { - try { - client().prepareGet().setIndex(index).setType(type).setId(docId).setStoredFields(field); - fail(); - } catch (ElasticsearchException e) { - assertTrue(e.getMessage().contains("You can only get this field after refresh() has been called.")); - } - MultiGetResponse multiGetResponse = client().prepareMultiGet().add(new MultiGetRequest.Item(index, type, docId).storedFields(field)).get(); - assertNull(multiGetResponse.getResponses()[0].getResponse()); - assertTrue(multiGetResponse.getResponses()[0].getFailure().getMessage().contains("You can only get this field after refresh() has been called.")); - } - protected void assertGetFieldsNull(String index, String type, String docId, String[] fields) { assertGetFieldsNull(index, type, docId, fields, null); } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java b/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java index eb1148e9f45..26fc15bf662 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java @@ -106,14 +106,6 @@ public class MultiFieldTests extends ESSingleNodeTestCase { assertThat(docMapper.mappers().getMapper("name.test1").fieldType().tokenized(), equalTo(true)); assertThat(docMapper.mappers().getMapper("name.test1").fieldType().eagerGlobalOrdinals(), equalTo(true)); - assertThat(docMapper.mappers().getMapper("name.test2"), notNullValue()); - assertThat(docMapper.mappers().getMapper("name.test2"), instanceOf(TokenCountFieldMapper.class)); - assertNotSame(IndexOptions.NONE, docMapper.mappers().getMapper("name.test2").fieldType().indexOptions()); - assertThat(docMapper.mappers().getMapper("name.test2").fieldType().stored(), equalTo(true)); - assertThat(docMapper.mappers().getMapper("name.test2").fieldType().tokenized(), equalTo(false)); - assertThat(((TokenCountFieldMapper) docMapper.mappers().getMapper("name.test2")).analyzer(), equalTo("simple")); - assertThat(((TokenCountFieldMapper) docMapper.mappers().getMapper("name.test2")).analyzer(), equalTo("simple")); - assertThat(docMapper.mappers().getMapper("object1.multi1"), notNullValue()); assertThat(docMapper.mappers().getMapper("object1.multi1"), instanceOf(DateFieldMapper.class)); assertThat(docMapper.mappers().getMapper("object1.multi1.string"), notNullValue()); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java b/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java index ae922e6a731..8dbddcc5daa 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java @@ -130,42 +130,6 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase { assertThat(countResponse.getHits().getTotalHits(), equalTo(1L)); } - public void testTokenCountMultiField() throws Exception { - assertAcked( - client().admin().indices().prepareCreate("my-index") - .addMapping("my-type", XContentFactory.jsonBuilder().startObject().startObject("my-type") - .startObject("properties") - .startObject("a") - .field("type", "token_count") - .field("analyzer", "simple") - .startObject("fields") - .startObject("b") - .field("type", "keyword") - .endObject() - .endObject() - .endObject() - .endObject() - .endObject().endObject()) - ); - - GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); - assertThat(mappingMetaData, not(nullValue())); - Map mappingSource = mappingMetaData.sourceAsMap(); - Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource)); - assertThat(aField.size(), equalTo(3)); - assertThat(aField.get("type").toString(), equalTo("token_count")); - assertThat(aField.get("fields"), notNullValue()); - - Map bField = ((Map) XContentMapValues.extractValue("properties.a.fields.b", mappingSource)); - assertThat(bField.size(), equalTo(1)); - assertThat(bField.get("type").toString(), equalTo("keyword")); - - client().prepareIndex("my-index", "my-type", "1").setSource("a", "my tokens").setRefreshPolicy(IMMEDIATE).get(); - SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "my tokens")).get(); - assertThat(countResponse.getHits().getTotalHits(), equalTo(1L)); - } - public void testCompletionMultiField() throws Exception { assertAcked( client().admin().indices().prepareCreate("my-index") diff --git a/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldTypeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldTypeTests.java index 0066c5a7798..6d5ca1add74 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldTypeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldTypeTests.java @@ -49,9 +49,7 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.function.Supplier; import static org.hamcrest.Matchers.containsString; @@ -500,4 +498,25 @@ public class NumberFieldTypeTests extends FieldTypeTestCase { message = m; } } + + public void testDisplayValue() { + for (NumberFieldMapper.NumberType type : NumberFieldMapper.NumberType.values()) { + NumberFieldMapper.NumberFieldType fieldType = new NumberFieldMapper.NumberFieldType(type); + assertNull(fieldType.valueForDisplay(null)); + } + assertEquals(Byte.valueOf((byte) 3), + new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.BYTE).valueForDisplay(3)); + assertEquals(Short.valueOf((short) 3), + new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.SHORT).valueForDisplay(3)); + assertEquals(Integer.valueOf(3), + new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.INTEGER).valueForDisplay(3)); + assertEquals(Long.valueOf(3), + new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG).valueForDisplay(3L)); + assertEquals(Double.valueOf(1.2), + new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.HALF_FLOAT).valueForDisplay(1.2)); + assertEquals(Double.valueOf(1.2), + new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.FLOAT).valueForDisplay(1.2)); + assertEquals(Double.valueOf(1.2), + new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE).valueForDisplay(1.2)); + } } diff --git a/core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java index b101a681855..a3f90498b52 100644 --- a/core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java @@ -19,8 +19,6 @@ package org.elasticsearch.index.query; -import com.carrotsearch.randomizedtesting.generators.RandomPicks; - import org.apache.lucene.document.IntPoint; import org.apache.lucene.document.LongPoint; import org.apache.lucene.index.Term; @@ -33,7 +31,6 @@ import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermRangeQuery; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParsingException; -import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.index.mapper.FieldNamesFieldMapper; @@ -64,13 +61,13 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase reqs = new ArrayList<>(); reqs.add(client().prepareIndex("test", "doc", "1").setSource("f1", "foo bar baz")); @@ -177,8 +173,6 @@ public class QueryStringIT extends ESIntegTestCase { assertHits(resp.getHits(), "1"); resp = client().prepareSearch("test").setQuery(queryStringQuery("1.5")).get(); assertHits(resp.getHits(), "1"); - resp = client().prepareSearch("test").setQuery(queryStringQuery("12.23")).get(); - assertHits(resp.getHits(), "1"); resp = client().prepareSearch("test").setQuery(queryStringQuery("127.0.0.1")).get(); assertHits(resp.getHits(), "1"); // binary doesn't match diff --git a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java index 3c4a0f88230..fb2fbd337dd 100644 --- a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java +++ b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java @@ -1890,19 +1890,4 @@ public class SearchQueryIT extends ESIntegTestCase { } } - public void testRangeQueryRangeFields_24744() throws Exception { - assertAcked(prepareCreate("test") - .addMapping("type1", "int_range", "type=integer_range")); - - client().prepareIndex("test", "type1", "1") - .setSource(jsonBuilder() - .startObject() - .startObject("int_range").field("gte", 10).field("lte", 20).endObject() - .endObject()).get(); - refresh(); - - RangeQueryBuilder range = new RangeQueryBuilder("int_range").relation("intersects").from(Integer.MIN_VALUE).to(Integer.MAX_VALUE); - SearchResponse searchResponse = client().prepareSearch("test").setQuery(range).get(); - assertHitCount(searchResponse, 1); - } } diff --git a/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java b/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java index 398b30abbe1..bd4bf0624fe 100644 --- a/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java +++ b/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java @@ -498,8 +498,6 @@ public class SimpleQueryStringIT extends ESIntegTestCase { assertHits(resp.getHits(), "1"); resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("1.5")).get(); assertHits(resp.getHits(), "1"); - resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("12.23")).get(); - assertHits(resp.getHits(), "1"); resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("127.0.0.1")).get(); assertHits(resp.getHits(), "1"); // binary doesn't match diff --git a/core/src/test/resources/org/elasticsearch/index/mapper/multifield/test-multi-fields.json b/core/src/test/resources/org/elasticsearch/index/mapper/multifield/test-multi-fields.json index 7d4f819a250..b7317aba3c1 100644 --- a/core/src/test/resources/org/elasticsearch/index/mapper/multifield/test-multi-fields.json +++ b/core/src/test/resources/org/elasticsearch/index/mapper/multifield/test-multi-fields.json @@ -18,12 +18,6 @@ "type": "text", "store": true, "eager_global_ordinals": true - }, - "test2": { - "type": "token_count", - "index": true, - "store": true, - "analyzer": "simple" } } }, diff --git a/core/src/test/resources/org/elasticsearch/search/query/all-example-document.json b/core/src/test/resources/org/elasticsearch/search/query/all-example-document.json index 9e4d04930a7..abc22939b64 100644 --- a/core/src/test/resources/org/elasticsearch/search/query/all-example-document.json +++ b/core/src/test/resources/org/elasticsearch/search/query/all-example-document.json @@ -21,7 +21,6 @@ "f_long": "42", "f_float": "1.7", "f_hfloat": "1.5", - "f_sfloat": "12.23", "f_ip": "127.0.0.1", "f_binary": "VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhCg==", "f_suggest": { diff --git a/core/src/test/resources/org/elasticsearch/search/query/all-query-index.json b/core/src/test/resources/org/elasticsearch/search/query/all-query-index.json index 89c41217125..3b068132d51 100644 --- a/core/src/test/resources/org/elasticsearch/search/query/all-query-index.json +++ b/core/src/test/resources/org/elasticsearch/search/query/all-query-index.json @@ -18,8 +18,7 @@ "f_multi": { "type": "text", "fields": { - "raw": {"type": "keyword"}, - "f_token_count": {"type": "token_count", "analyzer": "standard"} + "raw": {"type": "keyword"} } }, "f_object": { @@ -49,7 +48,6 @@ "f_long": {"type": "long"}, "f_float": {"type": "float"}, "f_hfloat": {"type": "half_float"}, - "f_sfloat": {"type": "scaled_float", "scaling_factor": 100}, "f_ip": {"type": "ip"}, "f_binary": {"type": "binary"}, "f_suggest": {"type": "completion"}, diff --git a/modules/lang-painless/build.gradle b/modules/lang-painless/build.gradle index 87e3d265f42..dddc98ae138 100644 --- a/modules/lang-painless/build.gradle +++ b/modules/lang-painless/build.gradle @@ -24,6 +24,10 @@ esplugin { classname 'org.elasticsearch.painless.PainlessPlugin' } +integTestCluster { + module project.project(':modules:mapper-extras') +} + dependencies { compile 'org.antlr:antlr4-runtime:4.5.1-1' compile 'org.ow2.asm:asm-debug-all:5.1' diff --git a/modules/mapper-extras/build.gradle b/modules/mapper-extras/build.gradle new file mode 100644 index 00000000000..7831de3a68e --- /dev/null +++ b/modules/mapper-extras/build.gradle @@ -0,0 +1,23 @@ +/* + * 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. + */ + +esplugin { + description 'Adds advanced field mappers' + classname 'org.elasticsearch.index.mapper.MapperExtrasPlugin' +} diff --git a/core/src/main/java/org/apache/lucene/queries/BinaryDocValuesRangeQuery.java b/modules/mapper-extras/src/main/java/org/apache/lucene/queries/BinaryDocValuesRangeQuery.java similarity index 100% rename from core/src/main/java/org/apache/lucene/queries/BinaryDocValuesRangeQuery.java rename to modules/mapper-extras/src/main/java/org/apache/lucene/queries/BinaryDocValuesRangeQuery.java diff --git a/core/src/main/java/org/elasticsearch/index/mapper/BinaryRangeUtil.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/BinaryRangeUtil.java similarity index 100% rename from core/src/main/java/org/elasticsearch/index/mapper/BinaryRangeUtil.java rename to modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/BinaryRangeUtil.java diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/MapperExtrasPlugin.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/MapperExtrasPlugin.java new file mode 100644 index 00000000000..d91d2b28df8 --- /dev/null +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/MapperExtrasPlugin.java @@ -0,0 +1,42 @@ +/* + * 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; + +import org.elasticsearch.plugins.MapperPlugin; +import org.elasticsearch.plugins.Plugin; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +public class MapperExtrasPlugin extends Plugin implements MapperPlugin { + + @Override + public Map getMappers() { + Map mappers = new LinkedHashMap<>(); + mappers.put(ScaledFloatFieldMapper.CONTENT_TYPE, new ScaledFloatFieldMapper.TypeParser()); + mappers.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser()); + for (RangeFieldMapper.RangeType type : RangeFieldMapper.RangeType.values()) { + mappers.put(type.typeName(), new RangeFieldMapper.TypeParser(type)); + } + return Collections.unmodifiableMap(mappers); + } + +} diff --git a/core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java similarity index 98% rename from core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java rename to modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java index c243858cd91..d6c453bd6e6 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java @@ -289,21 +289,17 @@ public class RangeFieldMapper extends FieldMapper { @Override public Query termQuery(Object value, QueryShardContext context) { - Query query = rangeQuery(value, value, true, true, ShapeRelation.INTERSECTS, context); + Query query = rangeQuery(value, value, true, true, ShapeRelation.INTERSECTS, null, null, context); if (boost() != 1f) { query = new BoostQuery(query, boost()); } return query; } - public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, - ShapeRelation relation, QueryShardContext context) { - failIfNotIndexed(); - return rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, relation, null, dateMathParser, context); - } - + @Override public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, ShapeRelation relation, DateTimeZone timeZone, DateMathParser parser, QueryShardContext context) { + failIfNotIndexed(); return rangeType.rangeQuery(name(), hasDocValues(), lowerTerm, upperTerm, includeLower, includeUpper, relation, timeZone, parser, context); } @@ -525,9 +521,6 @@ public class RangeFieldMapper extends FieldMapper { return InetAddressRange.newIntersectsQuery(field, includeLower ? lower : nextUp(lower), includeUpper ? upper : nextDown(upper)); } - public String toString(InetAddress address) { - return InetAddresses.toAddrString(address); - } }, DATE("date_range", NumberType.LONG) { @Override diff --git a/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java similarity index 100% rename from core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java rename to modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java diff --git a/core/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java similarity index 100% rename from core/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java rename to modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/TokenCountFieldMapper.java diff --git a/core/src/test/java/org/apache/lucene/queries/BaseRandomBinaryDocValuesRangeQueryTestCase.java b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/BaseRandomBinaryDocValuesRangeQueryTestCase.java similarity index 92% rename from core/src/test/java/org/apache/lucene/queries/BaseRandomBinaryDocValuesRangeQueryTestCase.java rename to modules/mapper-extras/src/test/java/org/apache/lucene/queries/BaseRandomBinaryDocValuesRangeQueryTestCase.java index b83dac78d07..fcc9f67229f 100644 --- a/core/src/test/java/org/apache/lucene/queries/BaseRandomBinaryDocValuesRangeQueryTestCase.java +++ b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/BaseRandomBinaryDocValuesRangeQueryTestCase.java @@ -49,7 +49,7 @@ public abstract class BaseRandomBinaryDocValuesRangeQueryTestCase extends BaseRa @Override protected final Field newRangeField(Range box) { - AbstractRange testRange = (AbstractRange) box; + AbstractRange testRange = (AbstractRange) box; RangeFieldMapper.Range range = new RangeFieldMapper.Range(rangeType(), testRange.getMin(), testRange.getMax(), true , true); try { BytesRef encodeRange = rangeType().encodeRanges(Collections.singleton(range)); @@ -61,25 +61,25 @@ public abstract class BaseRandomBinaryDocValuesRangeQueryTestCase extends BaseRa @Override protected final Query newIntersectsQuery(Range box) { - AbstractRange testRange = (AbstractRange) box; + AbstractRange testRange = (AbstractRange) box; return rangeType().dvRangeQuery(fieldName(), INTERSECTS, testRange.getMin(), testRange.getMax(), true, true); } @Override protected final Query newContainsQuery(Range box) { - AbstractRange testRange = (AbstractRange) box; + AbstractRange testRange = (AbstractRange) box; return rangeType().dvRangeQuery(fieldName(), CONTAINS, testRange.getMin(), testRange.getMax(), true, true); } @Override protected final Query newWithinQuery(Range box) { - AbstractRange testRange = (AbstractRange) box; + AbstractRange testRange = (AbstractRange) box; return rangeType().dvRangeQuery(fieldName(), WITHIN, testRange.getMin(), testRange.getMax(), true, true); } @Override protected final Query newCrossesQuery(Range box) { - AbstractRange testRange = (AbstractRange) box; + AbstractRange testRange = (AbstractRange) box; return rangeType().dvRangeQuery(fieldName(), CROSSES, testRange.getMin(), testRange.getMax(), true, true); } @@ -116,7 +116,7 @@ public abstract class BaseRandomBinaryDocValuesRangeQueryTestCase extends BaseRa @Override protected final boolean isEqual(Range o) { - AbstractRange other = (AbstractRange) o; + AbstractRange other = (AbstractRange) o; return Objects.equals(getMin(), other.getMin()) && Objects.equals(getMax(), other.getMax()); } diff --git a/core/src/test/java/org/apache/lucene/queries/BinaryDocValuesRangeQueryTests.java b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/BinaryDocValuesRangeQueryTests.java similarity index 100% rename from core/src/test/java/org/apache/lucene/queries/BinaryDocValuesRangeQueryTests.java rename to modules/mapper-extras/src/test/java/org/apache/lucene/queries/BinaryDocValuesRangeQueryTests.java diff --git a/core/src/test/java/org/apache/lucene/queries/DoubleRandomBinaryDocValuesRangeQueryTests.java b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/DoubleRandomBinaryDocValuesRangeQueryTests.java similarity index 96% rename from core/src/test/java/org/apache/lucene/queries/DoubleRandomBinaryDocValuesRangeQueryTests.java rename to modules/mapper-extras/src/test/java/org/apache/lucene/queries/DoubleRandomBinaryDocValuesRangeQueryTests.java index aa15a803195..984b1d72ef8 100644 --- a/core/src/test/java/org/apache/lucene/queries/DoubleRandomBinaryDocValuesRangeQueryTests.java +++ b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/DoubleRandomBinaryDocValuesRangeQueryTests.java @@ -56,7 +56,7 @@ public class DoubleRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinary } } - private static class DoubleTestRange extends AbstractRange { + private static class DoubleTestRange extends AbstractRange { double min; double max; @@ -66,7 +66,7 @@ public class DoubleRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinary } @Override - public Object getMin() { + public Double getMin() { return min; } @@ -82,7 +82,7 @@ public class DoubleRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinary } @Override - public Object getMax() { + public Double getMax() { return max; } diff --git a/core/src/test/java/org/apache/lucene/queries/FloatRandomBinaryDocValuesRangeQueryTests.java b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/FloatRandomBinaryDocValuesRangeQueryTests.java similarity index 96% rename from core/src/test/java/org/apache/lucene/queries/FloatRandomBinaryDocValuesRangeQueryTests.java rename to modules/mapper-extras/src/test/java/org/apache/lucene/queries/FloatRandomBinaryDocValuesRangeQueryTests.java index 8a04a50448f..a7f877392cf 100644 --- a/core/src/test/java/org/apache/lucene/queries/FloatRandomBinaryDocValuesRangeQueryTests.java +++ b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/FloatRandomBinaryDocValuesRangeQueryTests.java @@ -56,7 +56,7 @@ public class FloatRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryD } } - private static class FloatTestRange extends AbstractRange { + private static class FloatTestRange extends AbstractRange { float min; float max; @@ -66,7 +66,7 @@ public class FloatRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryD } @Override - public Object getMin() { + public Float getMin() { return min; } @@ -82,7 +82,7 @@ public class FloatRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryD } @Override - public Object getMax() { + public Float getMax() { return max; } diff --git a/core/src/test/java/org/apache/lucene/queries/InetAddressRandomBinaryDocValuesRangeQueryTests.java b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/InetAddressRandomBinaryDocValuesRangeQueryTests.java similarity index 96% rename from core/src/test/java/org/apache/lucene/queries/InetAddressRandomBinaryDocValuesRangeQueryTests.java rename to modules/mapper-extras/src/test/java/org/apache/lucene/queries/InetAddressRandomBinaryDocValuesRangeQueryTests.java index 1592e89d174..2def2702d38 100644 --- a/core/src/test/java/org/apache/lucene/queries/InetAddressRandomBinaryDocValuesRangeQueryTests.java +++ b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/InetAddressRandomBinaryDocValuesRangeQueryTests.java @@ -67,7 +67,7 @@ public class InetAddressRandomBinaryDocValuesRangeQueryTests extends BaseRandomB } } - private static class IpRange extends AbstractRange { + private static class IpRange extends AbstractRange { InetAddress minAddress; InetAddress maxAddress; byte[] min; @@ -81,7 +81,7 @@ public class InetAddressRandomBinaryDocValuesRangeQueryTests extends BaseRandomB } @Override - public Object getMin() { + public InetAddress getMin() { return minAddress; } @@ -101,7 +101,7 @@ public class InetAddressRandomBinaryDocValuesRangeQueryTests extends BaseRandomB } @Override - public Object getMax() { + public InetAddress getMax() { return maxAddress; } diff --git a/core/src/test/java/org/apache/lucene/queries/IntegerRandomBinaryDocValuesRangeQueryTests.java b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/IntegerRandomBinaryDocValuesRangeQueryTests.java similarity index 96% rename from core/src/test/java/org/apache/lucene/queries/IntegerRandomBinaryDocValuesRangeQueryTests.java rename to modules/mapper-extras/src/test/java/org/apache/lucene/queries/IntegerRandomBinaryDocValuesRangeQueryTests.java index 6fe59b88273..1d04cdbaaca 100644 --- a/core/src/test/java/org/apache/lucene/queries/IntegerRandomBinaryDocValuesRangeQueryTests.java +++ b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/IntegerRandomBinaryDocValuesRangeQueryTests.java @@ -64,7 +64,7 @@ public class IntegerRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinar } } - private static class IntTestRange extends AbstractRange { + private static class IntTestRange extends AbstractRange { int min; int max; @@ -74,7 +74,7 @@ public class IntegerRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinar } @Override - public Object getMin() { + public Integer getMin() { return min; } @@ -90,7 +90,7 @@ public class IntegerRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinar } @Override - public Object getMax() { + public Integer getMax() { return max; } diff --git a/core/src/test/java/org/apache/lucene/queries/LongRandomBinaryDocValuesRangeQueryTests.java b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/LongRandomBinaryDocValuesRangeQueryTests.java similarity index 96% rename from core/src/test/java/org/apache/lucene/queries/LongRandomBinaryDocValuesRangeQueryTests.java rename to modules/mapper-extras/src/test/java/org/apache/lucene/queries/LongRandomBinaryDocValuesRangeQueryTests.java index 139cb3f0b12..e506c2c2690 100644 --- a/core/src/test/java/org/apache/lucene/queries/LongRandomBinaryDocValuesRangeQueryTests.java +++ b/modules/mapper-extras/src/test/java/org/apache/lucene/queries/LongRandomBinaryDocValuesRangeQueryTests.java @@ -64,7 +64,7 @@ public class LongRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryDo } } - private static class LongTestRange extends AbstractRange { + private static class LongTestRange extends AbstractRange { long min; long max; @@ -74,7 +74,7 @@ public class LongRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryDo } @Override - public Object getMin() { + public Long getMin() { return min; } @@ -90,7 +90,7 @@ public class LongRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryDo } @Override - public Object getMax() { + public Long getMax() { return max; } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/template/BWCTemplateTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/BWCTemplateTests.java similarity index 82% rename from core/src/test/java/org/elasticsearch/action/admin/indices/template/BWCTemplateTests.java rename to modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/BWCTemplateTests.java index 40c314edd41..1d9671218c4 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/template/BWCTemplateTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/BWCTemplateTests.java @@ -17,11 +17,15 @@ * under the License. */ -package org.elasticsearch.action.admin.indices.template; +package org.elasticsearch.index.mapper; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.index.mapper.MapperExtrasPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; +import java.util.Collection; + import static org.elasticsearch.test.StreamsUtils.copyToBytesFromClasspath; /** @@ -29,11 +33,16 @@ import static org.elasticsearch.test.StreamsUtils.copyToBytesFromClasspath; * prior to their 5.x releases work for newly created indices */ public class BWCTemplateTests extends ESSingleNodeTestCase { + @Override + protected Collection> getPlugins() { + return pluginList(MapperExtrasPlugin.class); + } + public void testBeatsTemplatesBWC() throws Exception { - byte[] metricBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/metricbeat-5.0.template.json"); - byte[] packetBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/packetbeat-5.0.template.json"); - byte[] fileBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/filebeat-5.0.template.json"); - byte[] winLogBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/winlogbeat-5.0.template.json"); + byte[] metricBeat = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/metricbeat-5.0.template.json"); + byte[] packetBeat = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/packetbeat-5.0.template.json"); + byte[] fileBeat = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/filebeat-5.0.template.json"); + byte[] winLogBeat = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/winlogbeat-5.0.template.json"); client().admin().indices().preparePutTemplate("metricbeat").setSource(metricBeat, XContentType.JSON).get(); client().admin().indices().preparePutTemplate("packetbeat").setSource(packetBeat, XContentType.JSON).get(); client().admin().indices().preparePutTemplate("filebeat").setSource(fileBeat, XContentType.JSON).get(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/BinaryRangeUtilTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/BinaryRangeUtilTests.java similarity index 100% rename from core/src/test/java/org/elasticsearch/index/mapper/BinaryRangeUtilTests.java rename to modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/BinaryRangeUtilTests.java diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/MapperExtrasClientYamlTestSuiteIT.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/MapperExtrasClientYamlTestSuiteIT.java new file mode 100644 index 00000000000..e2f10791739 --- /dev/null +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/MapperExtrasClientYamlTestSuiteIT.java @@ -0,0 +1,40 @@ +/* + * 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; + +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; + +/** Runs yaml rest tests */ +public class MapperExtrasClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + + public MapperExtrasClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { + super(testCandidate); + } + + @ParametersFactory + public static Iterable parameters() throws Exception { + return ESClientYamlSuiteTestCase.createParameters(); + } +} + diff --git a/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java similarity index 98% rename from core/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java rename to modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java index 7bae878b924..0742aeadcb5 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java @@ -27,10 +27,13 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.test.InternalSettingsPlugin; import java.io.IOException; import java.net.InetAddress; import java.util.Arrays; +import java.util.Collection; import java.util.HashSet; import java.util.Locale; @@ -42,6 +45,12 @@ import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { + + @Override + protected Collection> getPlugins() { + return pluginList(InternalSettingsPlugin.class, MapperExtrasPlugin.class); + } + private static String FROM_DATE = "2016-10-31"; private static String TO_DATE = "2016-11-01 20:00:00"; private static String FROM_IP = "::ffff:c0a8:107"; diff --git a/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java similarity index 99% rename from core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java rename to modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java index 328e61c2330..81056355596 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java @@ -95,7 +95,7 @@ public class RangeFieldTypeTests extends FieldTypeTestCase { Object to = nextTo(from); assertEquals(getExpectedRangeQuery(relation, from, to, includeLower, includeUpper), - ft.rangeQuery(from, to, includeLower, includeUpper, relation, context)); + ft.rangeQuery(from, to, includeLower, includeUpper, relation, null, null, context)); } private Query getExpectedRangeQuery(ShapeRelation relation, Object from, Object to, boolean includeLower, boolean includeUpper) { diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java similarity index 99% rename from core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java rename to modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java index c0650c9c72e..42f8bff5449 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java @@ -50,7 +50,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { @Override protected Collection> getPlugins() { - return pluginList(InternalSettingsPlugin.class); + return pluginList(InternalSettingsPlugin.class, MapperExtrasPlugin.class); } public void testDefaults() throws Exception { diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java similarity index 100% rename from core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java rename to modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java diff --git a/core/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperIntegrationIT.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperIntegrationIT.java similarity index 99% rename from core/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperIntegrationIT.java rename to modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperIntegrationIT.java index 75b588df85a..3d69b0d013e 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperIntegrationIT.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperIntegrationIT.java @@ -220,7 +220,8 @@ public class TokenCountFieldMapperIntegrationIT extends ESIntegTestCase { assertThat(hit.field("foo.token_count_without_position_increments"), not(nullValue())); assertThat(hit.field("foo.token_count_without_position_increments").getValues().size(), equalTo(englishTermCounts.length)); for (int i = 0; i < englishTermCounts.length; i++) { - assertThat((Integer) hit.field("foo.token_count_without_position_increments").getValues().get(i), equalTo(englishTermCounts[i])); + assertThat((Integer) hit.field("foo.token_count_without_position_increments").getValues().get(i), + equalTo(englishTermCounts[i])); } if (loadCountedFields && storeCountedFields) { diff --git a/core/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java similarity index 99% rename from core/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java rename to modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java index 861586370ae..633f1027609 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/TokenCountFieldMapperTests.java @@ -45,6 +45,12 @@ import static org.hamcrest.Matchers.equalTo; * Test for {@link TokenCountFieldMapper}. */ public class TokenCountFieldMapperTests extends ESSingleNodeTestCase { + + @Override + protected Collection> getPlugins() { + return pluginList(InternalSettingsPlugin.class, MapperExtrasPlugin.class); + } + public void testMerge() throws IOException { String stage1Mapping = XContentFactory.jsonBuilder().startObject() .startObject("person") @@ -122,11 +128,6 @@ public class TokenCountFieldMapperTests extends ESSingleNodeTestCase { return analyzer; } - @Override - protected Collection> getPlugins() { - return pluginList(InternalSettingsPlugin.class); - } - public void testEmptyName() throws IOException { IndexService indexService = createIndex("test"); DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); diff --git a/core/src/test/resources/org/elasticsearch/action/admin/indices/template/filebeat-5.0.template.json b/modules/mapper-extras/src/test/resources/org/elasticsearch/index/mapper/filebeat-5.0.template.json similarity index 100% rename from core/src/test/resources/org/elasticsearch/action/admin/indices/template/filebeat-5.0.template.json rename to modules/mapper-extras/src/test/resources/org/elasticsearch/index/mapper/filebeat-5.0.template.json diff --git a/core/src/test/resources/org/elasticsearch/action/admin/indices/template/metricbeat-5.0.template.json b/modules/mapper-extras/src/test/resources/org/elasticsearch/index/mapper/metricbeat-5.0.template.json similarity index 100% rename from core/src/test/resources/org/elasticsearch/action/admin/indices/template/metricbeat-5.0.template.json rename to modules/mapper-extras/src/test/resources/org/elasticsearch/index/mapper/metricbeat-5.0.template.json diff --git a/core/src/test/resources/org/elasticsearch/action/admin/indices/template/packetbeat-5.0.template.json b/modules/mapper-extras/src/test/resources/org/elasticsearch/index/mapper/packetbeat-5.0.template.json similarity index 100% rename from core/src/test/resources/org/elasticsearch/action/admin/indices/template/packetbeat-5.0.template.json rename to modules/mapper-extras/src/test/resources/org/elasticsearch/index/mapper/packetbeat-5.0.template.json diff --git a/core/src/test/resources/org/elasticsearch/action/admin/indices/template/winlogbeat-5.0.template.json b/modules/mapper-extras/src/test/resources/org/elasticsearch/index/mapper/winlogbeat-5.0.template.json similarity index 100% rename from core/src/test/resources/org/elasticsearch/action/admin/indices/template/winlogbeat-5.0.template.json rename to modules/mapper-extras/src/test/resources/org/elasticsearch/index/mapper/winlogbeat-5.0.template.json diff --git a/modules/mapper-extras/src/test/resources/rest-api-spec/test/range/10_basic.yml b/modules/mapper-extras/src/test/resources/rest-api-spec/test/range/10_basic.yml new file mode 100644 index 00000000000..9fd54d6342d --- /dev/null +++ b/modules/mapper-extras/src/test/resources/rest-api-spec/test/range/10_basic.yml @@ -0,0 +1,334 @@ +setup: + - do: + indices.create: + index: test + body: + settings: + number_of_replicas: 0 + mappings: + doc: + "properties": + "integer_range": + "type" : "integer_range" + "long_range": + "type" : "long_range" + "float_range": + "type" : "float_range" + "double_range": + "type" : "double_range" + "date_range": + "type" : "date_range" + "ip_range": + "type" : "ip_range" + +--- +"Integer range": + + - do: + index: + index: test + type: doc + id: 1 + body: { "integer_range" : { "gte": 1, "lte": 5 } } + + - do: + index: + index: test + type: doc + id: 2 + body: { "integer_range" : { "gte": 1, "lte": 3 } } + + - do: + index: + index: test + type: doc + id: 3 + body: { "integer_range" : { "gte": 4, "lte": 5 } } + + + - do: + indices.refresh: {} + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4 } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } + + - match: { hits.total: 1 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } + + - match: { hits.total: 0 } + +--- +"Long range": + + - do: + index: + index: test + type: doc + id: 1 + body: { "long_range" : { "gte": 1, "lte": 5 } } + + - do: + index: + index: test + type: doc + id: 2 + body: { "long_range" : { "gte": 1, "lte": 3 } } + + - do: + index: + index: test + type: doc + id: 3 + body: { "long_range" : { "gte": 4, "lte": 5 } } + + + - do: + indices.refresh: {} + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4 } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } + + - match: { hits.total: 1 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } + + - match: { hits.total: 0 } + +--- +"Float range": + + - do: + index: + index: test + type: doc + id: 1 + body: { "float_range" : { "gte": 1, "lte": 5 } } + + - do: + index: + index: test + type: doc + id: 2 + body: { "float_range" : { "gte": 1, "lte": 3 } } + + - do: + index: + index: test + type: doc + id: 3 + body: { "float_range" : { "gte": 4, "lte": 5 } } + + + - do: + indices.refresh: {} + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4 } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } + + - match: { hits.total: 1 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } + + - match: { hits.total: 0 } + +--- +"Double range": + + - do: + index: + index: test + type: doc + id: 1 + body: { "double_range" : { "gte": 1, "lte": 5 } } + + - do: + index: + index: test + type: doc + id: 2 + body: { "double_range" : { "gte": 1, "lte": 3 } } + + - do: + index: + index: test + type: doc + id: 3 + body: { "double_range" : { "gte": 4, "lte": 5 } } + + + - do: + indices.refresh: {} + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4 } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } + + - match: { hits.total: 1 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } + + - match: { hits.total: 0 } + +--- +"IP range": + + - do: + index: + index: test + type: doc + id: 1 + body: { "ip_range" : { "gte": "192.168.0.1", "lte": "192.168.0.5" } } + + - do: + index: + index: test + type: doc + id: 2 + body: { "ip_range" : { "gte": "192.168.0.1", "lte": "192.168.0.3" } } + + - do: + index: + index: test + type: doc + id: 3 + body: { "ip_range" : { "gte": "192.168.0.4", "lte": "192.168.0.5" } } + + + - do: + indices.refresh: {} + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4" } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4", "relation": "intersects" } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4", "relation": "contains" } } } } + + - match: { hits.total: 1 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4", "relation": "within" } } } } + + - match: { hits.total: 0 } + +--- +"Date range": + + - do: + index: + index: test + type: doc + id: 1 + body: { "date_range" : { "gte": "2017-09-01", "lte": "2017-09-05" } } + + - do: + index: + index: test + type: doc + id: 2 + body: { "date_range" : { "gte": "2017-09-01", "lte": "2017-09-03" } } + + - do: + index: + index: test + type: doc + id: 3 + body: { "date_range" : { "gte": "2017-09-04", "lte": "2017-09-05" } } + + + - do: + indices.refresh: {} + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04" } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04", "relation": "intersects" } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04", "relation": "contains" } } } } + + - match: { hits.total: 1 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04", "relation": "within" } } } } + + - match: { hits.total: 0 } diff --git a/modules/mapper-extras/src/test/resources/rest-api-spec/test/scaled_float/10_basic.yml b/modules/mapper-extras/src/test/resources/rest-api-spec/test/scaled_float/10_basic.yml new file mode 100644 index 00000000000..6840d8aae20 --- /dev/null +++ b/modules/mapper-extras/src/test/resources/rest-api-spec/test/scaled_float/10_basic.yml @@ -0,0 +1,105 @@ +setup: + - do: + indices.create: + index: test + body: + settings: + number_of_replicas: 0 + mappings: + doc: + "properties": + "number": + "type" : "scaled_float" + "scaling_factor": 100 + + - do: + index: + index: test + type: doc + id: 1 + body: { "number" : 1 } + + - do: + index: + index: test + type: doc + id: 2 + body: { "number" : 1.53 } + + - do: + index: + index: test + type: doc + id: 3 + body: { "number" : -2.1 } + + - do: + index: + index: test + type: doc + id: 4 + body: { "number" : 1.53 } + + - do: + indices.refresh: {} + +--- +"Aggregations": + + - do: + search: + body: { "size" : 0, "aggs" : { "my_terms" : { "terms" : { "field" : "number" } } } } + + - match: { hits.total: 4 } + + - length: { aggregations.my_terms.buckets: 3 } + + - match: { aggregations.my_terms.buckets.0.key: 1.53 } + + - is_false: aggregations.my_terms.buckets.0.key_as_string + + - match: { aggregations.my_terms.buckets.0.doc_count: 2 } + + - match: { aggregations.my_terms.buckets.1.key: -2.1 } + + - is_false: aggregations.my_terms.buckets.1.key_as_string + + - match: { aggregations.my_terms.buckets.1.doc_count: 1 } + + - match: { aggregations.my_terms.buckets.2.key: 1 } + + - is_false: aggregations.my_terms.buckets.2.key_as_string + + - match: { aggregations.my_terms.buckets.2.doc_count: 1 } + +--- +"Search": + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "number" : { "gte" : -2 } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "number" : { "gte" : 0 } } } } + + - match: { hits.total: 3 } + + - do: + search: + body: { "size" : 0, "query" : { "range" : { "number" : { "lt" : 1.5 } } } } + + - match: { hits.total: 2 } + +--- +"Sort": + + - do: + search: + body: { "size" : 1, "sort" : { "number" : { "order" : "asc" } } } + + - match: { hits.total: 4 } + - match: { hits.hits.0._id: "3" } + diff --git a/modules/percolator/build.gradle b/modules/percolator/build.gradle index cf55368861a..36b93fd4d86 100644 --- a/modules/percolator/build.gradle +++ b/modules/percolator/build.gradle @@ -25,7 +25,16 @@ esplugin { dependencies { // for testing hasChild and hasParent rejections + compile project(path: ':modules:mapper-extras', configuration: 'runtime') testCompile project(path: ':modules:parent-join', configuration: 'runtime') } + +dependencyLicenses { + // Don't check the client's license. We know it. + dependencies = project.configurations.runtime.fileCollection { + it.group.startsWith('org.elasticsearch') == false + } - project.configurations.provided +} + compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes" compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yml index 9cc30bbcd1b..5ac79a89881 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/20_terms.yml @@ -20,9 +20,6 @@ setup: type: double number: type: long - scaled_float: - type: scaled_float - scaling_factor: 100 date: type: date @@ -300,56 +297,6 @@ setup: - match: { aggregations.double_terms.buckets.1.doc_count: 1 } ---- -"Scaled float test": - - skip: - version: " - 5.2.0" - reason: scaled_float were considered as longs in aggregations, this was fixed in 5.2.0 - - - do: - index: - index: test_1 - type: test - id: 1 - body: { "scaled_float": 9.99 } - - - do: - index: - index: test_1 - type: test - id: 2 - body: { "scaled_float": 9.994 } - - - do: - index: - index: test_1 - type: test - id: 3 - body: { "scaled_float": 8.99 } - - - do: - indices.refresh: {} - - - do: - search: - body: { "size" : 0, "aggs" : { "scaled_float_terms" : { "terms" : { "field" : "scaled_float" } } } } - - - match: { hits.total: 3 } - - - length: { aggregations.scaled_float_terms.buckets: 2 } - - - match: { aggregations.scaled_float_terms.buckets.0.key: 9.99 } - - - is_false: aggregations.scaled_float_terms.buckets.0.key_as_string - - - match: { aggregations.scaled_float_terms.buckets.0.doc_count: 2 } - - - match: { aggregations.scaled_float_terms.buckets.1.key: 8.99 } - - - is_false: aggregations.scaled_float_terms.buckets.1.key_as_string - - - match: { aggregations.scaled_float_terms.buckets.1.doc_count: 1 } - --- "Date test": - do: diff --git a/settings.gradle b/settings.gradle index 220dda259b2..698f5600684 100644 --- a/settings.gradle +++ b/settings.gradle @@ -35,6 +35,7 @@ List projects = [ 'modules:lang-expression', 'modules:lang-mustache', 'modules:lang-painless', + 'modules:mapper-extras', 'modules:parent-join', 'modules:percolator', 'modules:reindex', @@ -65,6 +66,7 @@ List projects = [ 'qa:auto-create-index', 'qa:evil-tests', 'qa:full-cluster-restart', + 'qa:integration-bwc', 'qa:mixed-cluster', 'qa:multi-cluster-search', 'qa:no-bootstrap-tests', diff --git a/core/src/test/java/org/elasticsearch/index/mapper/AbstractNumericFieldMapperTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/mapper/AbstractNumericFieldMapperTestCase.java similarity index 100% rename from core/src/test/java/org/elasticsearch/index/mapper/AbstractNumericFieldMapperTestCase.java rename to test/framework/src/main/java/org/elasticsearch/index/mapper/AbstractNumericFieldMapperTestCase.java diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java index c38b6b759de..d56db722def 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java @@ -137,19 +137,17 @@ public abstract class AbstractQueryTestCase> public static final String STRING_FIELD_NAME = "mapped_string"; protected static final String STRING_FIELD_NAME_2 = "mapped_string_2"; protected static final String INT_FIELD_NAME = "mapped_int"; - protected static final String INT_RANGE_FIELD_NAME = "mapped_int_range"; protected static final String DOUBLE_FIELD_NAME = "mapped_double"; protected static final String BOOLEAN_FIELD_NAME = "mapped_boolean"; protected static final String DATE_FIELD_NAME = "mapped_date"; - protected static final String DATE_RANGE_FIELD_NAME = "mapped_date_range"; protected static final String OBJECT_FIELD_NAME = "mapped_object"; protected static final String GEO_POINT_FIELD_NAME = "mapped_geo_point"; protected static final String GEO_SHAPE_FIELD_NAME = "mapped_geo_shape"; - protected static final String[] MAPPED_FIELD_NAMES = new String[]{STRING_FIELD_NAME, INT_FIELD_NAME, INT_RANGE_FIELD_NAME, - DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME, DATE_RANGE_FIELD_NAME, OBJECT_FIELD_NAME, GEO_POINT_FIELD_NAME, + protected static final String[] MAPPED_FIELD_NAMES = new String[]{STRING_FIELD_NAME, INT_FIELD_NAME, + DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME, OBJECT_FIELD_NAME, GEO_POINT_FIELD_NAME, GEO_SHAPE_FIELD_NAME}; - private static final String[] MAPPED_LEAF_FIELD_NAMES = new String[]{STRING_FIELD_NAME, INT_FIELD_NAME, INT_RANGE_FIELD_NAME, - DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME, DATE_RANGE_FIELD_NAME, GEO_POINT_FIELD_NAME, }; + private static final String[] MAPPED_LEAF_FIELD_NAMES = new String[]{STRING_FIELD_NAME, INT_FIELD_NAME, + DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME, GEO_POINT_FIELD_NAME, }; private static final int NUMBER_OF_TESTQUERIES = 20; protected static Version indexVersionCreated; @@ -1078,11 +1076,9 @@ public abstract class AbstractQueryTestCase> STRING_FIELD_NAME, "type=text", STRING_FIELD_NAME_2, "type=keyword", INT_FIELD_NAME, "type=integer", - INT_RANGE_FIELD_NAME, "type=integer_range", DOUBLE_FIELD_NAME, "type=double", BOOLEAN_FIELD_NAME, "type=boolean", DATE_FIELD_NAME, "type=date", - DATE_RANGE_FIELD_NAME, "type=date_range", OBJECT_FIELD_NAME, "type=object", GEO_POINT_FIELD_NAME, "type=geo_point", GEO_SHAPE_FIELD_NAME, "type=geo_shape"