Move non-core mappers to a module. (#26549)

Today we have all non-plugin mappers in core. I'd like to start moving those
that neither map to json datatypes nor are very frequently used like `date` or
`ip` to a module.

This commit creates a new module called `mappers-extra` and moves the
`scaled_float` and `token_count` mappers to it. I'd like to eventually move
`range` fields there but it's more complicated due to their intimate
relationship with range queries.

Relates #10368
This commit is contained in:
Adrien Grand 2017-09-13 17:58:53 +02:00 committed by GitHub
parent 7404221b55
commit 93da7720ff
53 changed files with 692 additions and 332 deletions

View File

@ -596,7 +596,6 @@
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]PathMapperTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]PathMapperTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]RoutingFieldMapperTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]RoutingFieldMapperTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]SourceFieldMapperTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]SourceFieldMapperTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]TokenCountFieldMapperIntegrationIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]UpdateMappingOnClusterIT.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]UpdateMappingOnClusterIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]UpdateMappingTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]mapper[/\\]UpdateMappingTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]query[/\\]BoolQueryBuilderTests.java" checks="LineLength" /> <suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]index[/\\]query[/\\]BoolQueryBuilderTests.java" checks="LineLength" />

View File

@ -28,8 +28,8 @@ import org.apache.lucene.index.IndexableFieldType;
import java.io.Reader; import java.io.Reader;
// used for binary and geo fields // used for binary, geo and range fields
abstract class CustomDocValuesField implements IndexableField { public abstract class CustomDocValuesField implements IndexableField {
public static final FieldType TYPE = new FieldType(); public static final FieldType TYPE = new FieldType();
static { static {
@ -39,7 +39,7 @@ abstract class CustomDocValuesField implements IndexableField {
private final String name; private final String name;
CustomDocValuesField(String name) { protected CustomDocValuesField(String name) {
this.name = name; this.name = name;
} }

View File

@ -62,8 +62,7 @@ import java.util.Objects;
/** A {@link FieldMapper} for numeric types: byte, short, int, long, float and double. */ /** A {@link FieldMapper} for numeric types: byte, short, int, long, float and double. */
public class NumberFieldMapper extends FieldMapper { public class NumberFieldMapper extends FieldMapper {
// this is private since it has a different default public static final Setting<Boolean> COERCE_SETTING =
static final Setting<Boolean> COERCE_SETTING =
Setting.boolSetting("index.mapping.coerce", true, Property.IndexScope); Setting.boolSetting("index.mapping.coerce", true, Property.IndexScope);
public static class Defaults { public static class Defaults {
@ -162,7 +161,7 @@ public class NumberFieldMapper extends FieldMapper {
public enum NumberType { public enum NumberType {
HALF_FLOAT("half_float", NumericType.HALF_FLOAT) { HALF_FLOAT("half_float", NumericType.HALF_FLOAT) {
@Override @Override
Float parse(Object value, boolean coerce) { public Float parse(Object value, boolean coerce) {
final float result; final float result;
if (value instanceof Number) { if (value instanceof Number) {
@ -178,20 +177,20 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Float parse(XContentParser parser, boolean coerce) throws IOException { public Float parse(XContentParser parser, boolean coerce) throws IOException {
float parsed = parser.floatValue(coerce); float parsed = parser.floatValue(coerce);
validateParsed(parsed); validateParsed(parsed);
return parsed; return parsed;
} }
@Override @Override
Query termQuery(String field, Object value) { public Query termQuery(String field, Object value) {
float v = parse(value, false); float v = parse(value, false);
return HalfFloatPoint.newExactQuery(field, v); return HalfFloatPoint.newExactQuery(field, v);
} }
@Override @Override
Query termsQuery(String field, List<Object> values) { public Query termsQuery(String field, List<Object> values) {
float[] v = new float[values.size()]; float[] v = new float[values.size()];
for (int i = 0; i < values.size(); ++i) { for (int i = 0; i < values.size(); ++i) {
v[i] = parse(values.get(i), false); v[i] = parse(values.get(i), false);
@ -200,7 +199,7 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm, public Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper, boolean includeLower, boolean includeUpper,
boolean hasDocValues) { boolean hasDocValues) {
float l = Float.NEGATIVE_INFINITY; float l = Float.NEGATIVE_INFINITY;
@ -254,7 +253,7 @@ public class NumberFieldMapper extends FieldMapper {
}, },
FLOAT("float", NumericType.FLOAT) { FLOAT("float", NumericType.FLOAT) {
@Override @Override
Float parse(Object value, boolean coerce) { public Float parse(Object value, boolean coerce) {
final float result; final float result;
if (value instanceof Number) { if (value instanceof Number) {
@ -270,20 +269,20 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Float parse(XContentParser parser, boolean coerce) throws IOException { public Float parse(XContentParser parser, boolean coerce) throws IOException {
float parsed = parser.floatValue(coerce); float parsed = parser.floatValue(coerce);
validateParsed(parsed); validateParsed(parsed);
return parsed; return parsed;
} }
@Override @Override
Query termQuery(String field, Object value) { public Query termQuery(String field, Object value) {
float v = parse(value, false); float v = parse(value, false);
return FloatPoint.newExactQuery(field, v); return FloatPoint.newExactQuery(field, v);
} }
@Override @Override
Query termsQuery(String field, List<Object> values) { public Query termsQuery(String field, List<Object> values) {
float[] v = new float[values.size()]; float[] v = new float[values.size()];
for (int i = 0; i < values.size(); ++i) { for (int i = 0; i < values.size(); ++i) {
v[i] = parse(values.get(i), false); v[i] = parse(values.get(i), false);
@ -292,7 +291,7 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm, public Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper, boolean includeLower, boolean includeUpper,
boolean hasDocValues) { boolean hasDocValues) {
float l = Float.NEGATIVE_INFINITY; float l = Float.NEGATIVE_INFINITY;
@ -344,27 +343,27 @@ public class NumberFieldMapper extends FieldMapper {
}, },
DOUBLE("double", NumericType.DOUBLE) { DOUBLE("double", NumericType.DOUBLE) {
@Override @Override
Double parse(Object value, boolean coerce) { public Double parse(Object value, boolean coerce) {
double parsed = objectToDouble(value); double parsed = objectToDouble(value);
validateParsed(parsed); validateParsed(parsed);
return parsed; return parsed;
} }
@Override @Override
Double parse(XContentParser parser, boolean coerce) throws IOException { public Double parse(XContentParser parser, boolean coerce) throws IOException {
double parsed = parser.doubleValue(coerce); double parsed = parser.doubleValue(coerce);
validateParsed(parsed); validateParsed(parsed);
return parsed; return parsed;
} }
@Override @Override
Query termQuery(String field, Object value) { public Query termQuery(String field, Object value) {
double v = parse(value, false); double v = parse(value, false);
return DoublePoint.newExactQuery(field, v); return DoublePoint.newExactQuery(field, v);
} }
@Override @Override
Query termsQuery(String field, List<Object> values) { public Query termsQuery(String field, List<Object> values) {
double[] v = new double[values.size()]; double[] v = new double[values.size()];
for (int i = 0; i < values.size(); ++i) { for (int i = 0; i < values.size(); ++i) {
v[i] = parse(values.get(i), false); v[i] = parse(values.get(i), false);
@ -373,7 +372,7 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm, public Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper, boolean includeLower, boolean includeUpper,
boolean hasDocValues) { boolean hasDocValues) {
double l = Double.NEGATIVE_INFINITY; double l = Double.NEGATIVE_INFINITY;
@ -425,7 +424,7 @@ public class NumberFieldMapper extends FieldMapper {
}, },
BYTE("byte", NumericType.BYTE) { BYTE("byte", NumericType.BYTE) {
@Override @Override
Byte parse(Object value, boolean coerce) { public Byte parse(Object value, boolean coerce) {
double doubleValue = objectToDouble(value); double doubleValue = objectToDouble(value);
if (doubleValue < Byte.MIN_VALUE || doubleValue > Byte.MAX_VALUE) { if (doubleValue < Byte.MIN_VALUE || doubleValue > Byte.MAX_VALUE) {
@ -443,7 +442,7 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Short parse(XContentParser parser, boolean coerce) throws IOException { public Short parse(XContentParser parser, boolean coerce) throws IOException {
int value = parser.intValue(coerce); int value = parser.intValue(coerce);
if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
throw new IllegalArgumentException("Value [" + value + "] is out of range for a byte"); throw new IllegalArgumentException("Value [" + value + "] is out of range for a byte");
@ -452,17 +451,17 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Query termQuery(String field, Object value) { public Query termQuery(String field, Object value) {
return INTEGER.termQuery(field, value); return INTEGER.termQuery(field, value);
} }
@Override @Override
Query termsQuery(String field, List<Object> values) { public Query termsQuery(String field, List<Object> values) {
return INTEGER.termsQuery(field, values); return INTEGER.termsQuery(field, values);
} }
@Override @Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm, public Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper, boolean includeLower, boolean includeUpper,
boolean hasDocValues) { boolean hasDocValues) {
return INTEGER.rangeQuery(field, lowerTerm, upperTerm, includeLower, includeUpper, hasDocValues); return INTEGER.rangeQuery(field, lowerTerm, upperTerm, includeLower, includeUpper, hasDocValues);
@ -481,7 +480,7 @@ public class NumberFieldMapper extends FieldMapper {
}, },
SHORT("short", NumericType.SHORT) { SHORT("short", NumericType.SHORT) {
@Override @Override
Short parse(Object value, boolean coerce) { public Short parse(Object value, boolean coerce) {
double doubleValue = objectToDouble(value); double doubleValue = objectToDouble(value);
if (doubleValue < Short.MIN_VALUE || doubleValue > Short.MAX_VALUE) { if (doubleValue < Short.MIN_VALUE || doubleValue > Short.MAX_VALUE) {
@ -499,22 +498,22 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Short parse(XContentParser parser, boolean coerce) throws IOException { public Short parse(XContentParser parser, boolean coerce) throws IOException {
return parser.shortValue(coerce); return parser.shortValue(coerce);
} }
@Override @Override
Query termQuery(String field, Object value) { public Query termQuery(String field, Object value) {
return INTEGER.termQuery(field, value); return INTEGER.termQuery(field, value);
} }
@Override @Override
Query termsQuery(String field, List<Object> values) { public Query termsQuery(String field, List<Object> values) {
return INTEGER.termsQuery(field, values); return INTEGER.termsQuery(field, values);
} }
@Override @Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm, public Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper, boolean includeLower, boolean includeUpper,
boolean hasDocValues) { boolean hasDocValues) {
return INTEGER.rangeQuery(field, lowerTerm, upperTerm, includeLower, includeUpper, hasDocValues); return INTEGER.rangeQuery(field, lowerTerm, upperTerm, includeLower, includeUpper, hasDocValues);
@ -533,7 +532,7 @@ public class NumberFieldMapper extends FieldMapper {
}, },
INTEGER("integer", NumericType.INT) { INTEGER("integer", NumericType.INT) {
@Override @Override
Integer parse(Object value, boolean coerce) { public Integer parse(Object value, boolean coerce) {
double doubleValue = objectToDouble(value); double doubleValue = objectToDouble(value);
if (doubleValue < Integer.MIN_VALUE || doubleValue > Integer.MAX_VALUE) { if (doubleValue < Integer.MIN_VALUE || doubleValue > Integer.MAX_VALUE) {
@ -551,12 +550,12 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Integer parse(XContentParser parser, boolean coerce) throws IOException { public Integer parse(XContentParser parser, boolean coerce) throws IOException {
return parser.intValue(coerce); return parser.intValue(coerce);
} }
@Override @Override
Query termQuery(String field, Object value) { public Query termQuery(String field, Object value) {
if (hasDecimalPart(value)) { if (hasDecimalPart(value)) {
return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part"); return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
} }
@ -565,7 +564,7 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Query termsQuery(String field, List<Object> values) { public Query termsQuery(String field, List<Object> values) {
int[] v = new int[values.size()]; int[] v = new int[values.size()];
int upTo = 0; int upTo = 0;
@ -586,7 +585,7 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm, public Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper, boolean includeLower, boolean includeUpper,
boolean hasDocValues) { boolean hasDocValues) {
int l = Integer.MIN_VALUE; int l = Integer.MIN_VALUE;
@ -644,7 +643,7 @@ public class NumberFieldMapper extends FieldMapper {
}, },
LONG("long", NumericType.LONG) { LONG("long", NumericType.LONG) {
@Override @Override
Long parse(Object value, boolean coerce) { public Long parse(Object value, boolean coerce) {
if (value instanceof Long) { if (value instanceof Long) {
return (Long)value; return (Long)value;
} }
@ -665,12 +664,12 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Long parse(XContentParser parser, boolean coerce) throws IOException { public Long parse(XContentParser parser, boolean coerce) throws IOException {
return parser.longValue(coerce); return parser.longValue(coerce);
} }
@Override @Override
Query termQuery(String field, Object value) { public Query termQuery(String field, Object value) {
if (hasDecimalPart(value)) { if (hasDecimalPart(value)) {
return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part"); return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
} }
@ -679,7 +678,7 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Query termsQuery(String field, List<Object> values) { public Query termsQuery(String field, List<Object> values) {
long[] v = new long[values.size()]; long[] v = new long[values.size()];
int upTo = 0; int upTo = 0;
@ -700,7 +699,7 @@ public class NumberFieldMapper extends FieldMapper {
} }
@Override @Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm, public Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper, boolean includeLower, boolean includeUpper,
boolean hasDocValues) { boolean hasDocValues) {
long l = Long.MIN_VALUE; long l = Long.MIN_VALUE;
@ -773,13 +772,13 @@ public class NumberFieldMapper extends FieldMapper {
final NumericType numericType() { final NumericType numericType() {
return numericType; return numericType;
} }
abstract Query termQuery(String field, Object value); public abstract Query termQuery(String field, Object value);
abstract Query termsQuery(String field, List<Object> values); public abstract Query termsQuery(String field, List<Object> values);
abstract Query rangeQuery(String field, Object lowerTerm, Object upperTerm, public abstract Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper, boolean includeLower, boolean includeUpper,
boolean hasDocValues); boolean hasDocValues);
abstract Number parse(XContentParser parser, boolean coerce) throws IOException; public abstract Number parse(XContentParser parser, boolean coerce) throws IOException;
abstract Number parse(Object value, boolean coerce); public abstract Number parse(Object value, boolean coerce);
public abstract List<Field> createFields(String name, Number value, boolean indexed, public abstract List<Field> createFields(String name, Number value, boolean indexed,
boolean docValued, boolean stored); boolean docValued, boolean stored);
Number valueForSearch(Number value) { Number valueForSearch(Number value) {

View File

@ -39,7 +39,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.FieldNamesFieldMapper; import org.elasticsearch.index.mapper.FieldNamesFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.RangeFieldMapper;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import java.io.IOException; import java.io.IOException;

View File

@ -28,7 +28,6 @@ import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.MetadataFieldMapper; import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.mapper.NumberFieldMapper; import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.index.mapper.ScaledFloatFieldMapper;
import org.elasticsearch.index.mapper.TextFieldMapper; import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardContext;
@ -44,6 +43,7 @@ import java.util.Set;
*/ */
public final class QueryParserHelper { public final class QueryParserHelper {
// Mapping types the "all-ish" query can be executed against // 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<String> ALLOWED_QUERY_MAPPER_TYPES; private static final Set<String> ALLOWED_QUERY_MAPPER_TYPES;
static { static {
@ -54,7 +54,7 @@ public final class QueryParserHelper {
for (NumberFieldMapper.NumberType nt : NumberFieldMapper.NumberType.values()) { for (NumberFieldMapper.NumberType nt : NumberFieldMapper.NumberType.values()) {
ALLOWED_QUERY_MAPPER_TYPES.add(nt.typeName()); 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); ALLOWED_QUERY_MAPPER_TYPES.add(TextFieldMapper.CONTENT_TYPE);
} }

View File

@ -43,13 +43,10 @@ import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.mapper.NumberFieldMapper; import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.index.mapper.ObjectMapper; import org.elasticsearch.index.mapper.ObjectMapper;
import org.elasticsearch.index.mapper.ParentFieldMapper; import org.elasticsearch.index.mapper.ParentFieldMapper;
import org.elasticsearch.index.mapper.RangeFieldMapper;
import org.elasticsearch.index.mapper.RoutingFieldMapper; import org.elasticsearch.index.mapper.RoutingFieldMapper;
import org.elasticsearch.index.mapper.ScaledFloatFieldMapper;
import org.elasticsearch.index.mapper.SeqNoFieldMapper; import org.elasticsearch.index.mapper.SeqNoFieldMapper;
import org.elasticsearch.index.mapper.SourceFieldMapper; import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.mapper.TextFieldMapper; import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.mapper.TokenCountFieldMapper;
import org.elasticsearch.index.mapper.TypeFieldMapper; import org.elasticsearch.index.mapper.TypeFieldMapper;
import org.elasticsearch.index.mapper.UidFieldMapper; import org.elasticsearch.index.mapper.UidFieldMapper;
import org.elasticsearch.index.mapper.VersionFieldMapper; import org.elasticsearch.index.mapper.VersionFieldMapper;
@ -95,17 +92,12 @@ public class IndicesModule extends AbstractModule {
for (NumberFieldMapper.NumberType type : NumberFieldMapper.NumberType.values()) { for (NumberFieldMapper.NumberType type : NumberFieldMapper.NumberType.values()) {
mappers.put(type.typeName(), new NumberFieldMapper.TypeParser(type)); 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(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser());
mappers.put(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser()); mappers.put(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser());
mappers.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser()); mappers.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser());
mappers.put(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.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(TextFieldMapper.CONTENT_TYPE, new TextFieldMapper.TypeParser());
mappers.put(KeywordFieldMapper.CONTENT_TYPE, new KeywordFieldMapper.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.CONTENT_TYPE, new ObjectMapper.TypeParser());
mappers.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser()); mappers.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser());
mappers.put(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser()); mappers.put(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser());

View File

@ -19,7 +19,6 @@
package org.elasticsearch.get; package org.elasticsearch.get;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.ShardOperationFailedException;
@ -913,68 +912,6 @@ public class GetActionIT extends ESIntegTestCase {
index("test", "doc", "1", doc); 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) { private void assertGetFieldsAlwaysWorks(String index, String type, String docId, String[] fields) {
assertGetFieldsAlwaysWorks(index, type, docId, fields, null); assertGetFieldsAlwaysWorks(index, type, docId, fields, null);
} }
@ -997,18 +934,6 @@ public class GetActionIT extends ESIntegTestCase {
assertNotNull(response.getField(field)); 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) { protected void assertGetFieldsNull(String index, String type, String docId, String[] fields) {
assertGetFieldsNull(index, type, docId, fields, null); assertGetFieldsNull(index, type, docId, fields, null);
} }

View File

@ -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().tokenized(), equalTo(true));
assertThat(docMapper.mappers().getMapper("name.test1").fieldType().eagerGlobalOrdinals(), 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"), notNullValue());
assertThat(docMapper.mappers().getMapper("object1.multi1"), instanceOf(DateFieldMapper.class)); assertThat(docMapper.mappers().getMapper("object1.multi1"), instanceOf(DateFieldMapper.class));
assertThat(docMapper.mappers().getMapper("object1.multi1.string"), notNullValue()); assertThat(docMapper.mappers().getMapper("object1.multi1.string"), notNullValue());

View File

@ -130,42 +130,6 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase {
assertThat(countResponse.getHits().getTotalHits(), equalTo(1L)); 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<String, Object> 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 { public void testCompletionMultiField() throws Exception {
assertAcked( assertAcked(
client().admin().indices().prepareCreate("my-index") client().admin().indices().prepareCreate("my-index")

View File

@ -49,9 +49,7 @@ import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
@ -500,4 +498,25 @@ public class NumberFieldTypeTests extends FieldTypeTestCase {
message = m; 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));
}
} }

View File

@ -19,8 +19,6 @@
package org.elasticsearch.index.query; package org.elasticsearch.index.query;
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
import org.apache.lucene.document.IntPoint; import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.LongPoint; import org.apache.lucene.document.LongPoint;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
@ -33,7 +31,6 @@ import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermRangeQuery;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.geo.ShapeRelation;
import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.lucene.BytesRefs;
import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.mapper.FieldNamesFieldMapper; import org.elasticsearch.index.mapper.FieldNamesFieldMapper;
@ -64,13 +61,13 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
switch (randomIntBetween(0, 2)) { switch (randomIntBetween(0, 2)) {
case 0: case 0:
// use mapped integer field for numeric range queries // use mapped integer field for numeric range queries
query = new RangeQueryBuilder(randomBoolean() ? INT_FIELD_NAME : INT_RANGE_FIELD_NAME); query = new RangeQueryBuilder(INT_FIELD_NAME);
query.from(randomIntBetween(1, 100)); query.from(randomIntBetween(1, 100));
query.to(randomIntBetween(101, 200)); query.to(randomIntBetween(101, 200));
break; break;
case 1: case 1:
// use mapped date field, using date string representation // use mapped date field, using date string representation
query = new RangeQueryBuilder(randomBoolean() ? DATE_FIELD_NAME : DATE_RANGE_FIELD_NAME); query = new RangeQueryBuilder(DATE_FIELD_NAME);
query.from(new DateTime(System.currentTimeMillis() - randomIntBetween(0, 1000000), DateTimeZone.UTC).toString()); query.from(new DateTime(System.currentTimeMillis() - randomIntBetween(0, 1000000), DateTimeZone.UTC).toString());
query.to(new DateTime(System.currentTimeMillis() + randomIntBetween(0, 1000000), DateTimeZone.UTC).toString()); query.to(new DateTime(System.currentTimeMillis() + randomIntBetween(0, 1000000), DateTimeZone.UTC).toString());
// Create timestamp option only then we have a date mapper, // Create timestamp option only then we have a date mapper,
@ -98,9 +95,6 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
if (randomBoolean()) { if (randomBoolean()) {
query.to(null); query.to(null);
} }
if (query.fieldName().equals(INT_RANGE_FIELD_NAME) || query.fieldName().equals(DATE_RANGE_FIELD_NAME)) {
query.relation(RandomPicks.randomFrom(random(), ShapeRelation.values()).getRelationName());
}
return query; return query;
} }
@ -137,9 +131,7 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
} else if (getCurrentTypes().length == 0 || } else if (getCurrentTypes().length == 0 ||
(queryBuilder.fieldName().equals(DATE_FIELD_NAME) == false (queryBuilder.fieldName().equals(DATE_FIELD_NAME) == false
&& queryBuilder.fieldName().equals(INT_FIELD_NAME) == false && queryBuilder.fieldName().equals(INT_FIELD_NAME) == false)) {
&& queryBuilder.fieldName().equals(DATE_RANGE_FIELD_NAME) == false
&& queryBuilder.fieldName().equals(INT_RANGE_FIELD_NAME) == false)) {
assertThat(query, instanceOf(TermRangeQuery.class)); assertThat(query, instanceOf(TermRangeQuery.class));
TermRangeQuery termRangeQuery = (TermRangeQuery) query; TermRangeQuery termRangeQuery = (TermRangeQuery) query;
assertThat(termRangeQuery.getField(), equalTo(queryBuilder.fieldName())); assertThat(termRangeQuery.getField(), equalTo(queryBuilder.fieldName()));
@ -215,9 +207,6 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
maxInt--; maxInt--;
} }
} }
} else if (queryBuilder.fieldName().equals(DATE_RANGE_FIELD_NAME)
|| queryBuilder.fieldName().equals(INT_RANGE_FIELD_NAME)) {
// todo can't check RangeFieldQuery because its currently package private (this will change)
} else { } else {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -79,8 +79,7 @@ public class TermsQueryBuilderTests extends AbstractQueryTestCase<TermsQueryBuil
String fieldName; String fieldName;
do { do {
fieldName = getRandomFieldName(); fieldName = getRandomFieldName();
} while (fieldName.equals(GEO_POINT_FIELD_NAME) || fieldName.equals(GEO_SHAPE_FIELD_NAME) } while (fieldName.equals(GEO_POINT_FIELD_NAME) || fieldName.equals(GEO_SHAPE_FIELD_NAME));
|| fieldName.equals(INT_RANGE_FIELD_NAME) || fieldName.equals(DATE_RANGE_FIELD_NAME));
Object[] values = new Object[randomInt(5)]; Object[] values = new Object[randomInt(5)];
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
values[i] = getRandomValueForFieldName(fieldName); values[i] = getRandomValueForFieldName(fieldName);

View File

@ -71,10 +71,6 @@ public class QueryStringIT extends ESIntegTestCase {
ensureGreen("test"); ensureGreen("test");
} }
private QueryStringQueryBuilder lenientQuery(String queryText) {
return queryStringQuery(queryText).lenient(true);
}
public void testBasicAllQuery() throws Exception { public void testBasicAllQuery() throws Exception {
List<IndexRequestBuilder> reqs = new ArrayList<>(); List<IndexRequestBuilder> reqs = new ArrayList<>();
reqs.add(client().prepareIndex("test", "doc", "1").setSource("f1", "foo bar baz")); 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"); assertHits(resp.getHits(), "1");
resp = client().prepareSearch("test").setQuery(queryStringQuery("1.5")).get(); resp = client().prepareSearch("test").setQuery(queryStringQuery("1.5")).get();
assertHits(resp.getHits(), "1"); 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(); resp = client().prepareSearch("test").setQuery(queryStringQuery("127.0.0.1")).get();
assertHits(resp.getHits(), "1"); assertHits(resp.getHits(), "1");
// binary doesn't match // binary doesn't match

View File

@ -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);
}
} }

View File

@ -498,8 +498,6 @@ public class SimpleQueryStringIT extends ESIntegTestCase {
assertHits(resp.getHits(), "1"); assertHits(resp.getHits(), "1");
resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("1.5")).get(); resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("1.5")).get();
assertHits(resp.getHits(), "1"); 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(); resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("127.0.0.1")).get();
assertHits(resp.getHits(), "1"); assertHits(resp.getHits(), "1");
// binary doesn't match // binary doesn't match

View File

@ -18,12 +18,6 @@
"type": "text", "type": "text",
"store": true, "store": true,
"eager_global_ordinals": true "eager_global_ordinals": true
},
"test2": {
"type": "token_count",
"index": true,
"store": true,
"analyzer": "simple"
} }
} }
}, },

View File

@ -21,7 +21,6 @@
"f_long": "42", "f_long": "42",
"f_float": "1.7", "f_float": "1.7",
"f_hfloat": "1.5", "f_hfloat": "1.5",
"f_sfloat": "12.23",
"f_ip": "127.0.0.1", "f_ip": "127.0.0.1",
"f_binary": "VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhCg==", "f_binary": "VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhCg==",
"f_suggest": { "f_suggest": {

View File

@ -18,8 +18,7 @@
"f_multi": { "f_multi": {
"type": "text", "type": "text",
"fields": { "fields": {
"raw": {"type": "keyword"}, "raw": {"type": "keyword"}
"f_token_count": {"type": "token_count", "analyzer": "standard"}
} }
}, },
"f_object": { "f_object": {
@ -49,7 +48,6 @@
"f_long": {"type": "long"}, "f_long": {"type": "long"},
"f_float": {"type": "float"}, "f_float": {"type": "float"},
"f_hfloat": {"type": "half_float"}, "f_hfloat": {"type": "half_float"},
"f_sfloat": {"type": "scaled_float", "scaling_factor": 100},
"f_ip": {"type": "ip"}, "f_ip": {"type": "ip"},
"f_binary": {"type": "binary"}, "f_binary": {"type": "binary"},
"f_suggest": {"type": "completion"}, "f_suggest": {"type": "completion"},

View File

@ -24,6 +24,10 @@ esplugin {
classname 'org.elasticsearch.painless.PainlessPlugin' classname 'org.elasticsearch.painless.PainlessPlugin'
} }
integTestCluster {
module project.project(':modules:mapper-extras')
}
dependencies { dependencies {
compile 'org.antlr:antlr4-runtime:4.5.1-1' compile 'org.antlr:antlr4-runtime:4.5.1-1'
compile 'org.ow2.asm:asm-debug-all:5.1' compile 'org.ow2.asm:asm-debug-all:5.1'

View File

@ -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'
}

View File

@ -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<String, Mapper.TypeParser> getMappers() {
Map<String, Mapper.TypeParser> 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);
}
}

View File

@ -289,21 +289,17 @@ public class RangeFieldMapper extends FieldMapper {
@Override @Override
public Query termQuery(Object value, QueryShardContext context) { 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) { if (boost() != 1f) {
query = new BoostQuery(query, boost()); query = new BoostQuery(query, boost());
} }
return query; return query;
} }
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, @Override
ShapeRelation relation, QueryShardContext context) {
failIfNotIndexed();
return rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, relation, null, dateMathParser, context);
}
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper,
ShapeRelation relation, DateTimeZone timeZone, DateMathParser parser, QueryShardContext context) { ShapeRelation relation, DateTimeZone timeZone, DateMathParser parser, QueryShardContext context) {
failIfNotIndexed();
return rangeType.rangeQuery(name(), hasDocValues(), lowerTerm, upperTerm, includeLower, includeUpper, relation, return rangeType.rangeQuery(name(), hasDocValues(), lowerTerm, upperTerm, includeLower, includeUpper, relation,
timeZone, parser, context); timeZone, parser, context);
} }
@ -525,9 +521,6 @@ public class RangeFieldMapper extends FieldMapper {
return InetAddressRange.newIntersectsQuery(field, return InetAddressRange.newIntersectsQuery(field,
includeLower ? lower : nextUp(lower), includeUpper ? upper : nextDown(upper)); includeLower ? lower : nextUp(lower), includeUpper ? upper : nextDown(upper));
} }
public String toString(InetAddress address) {
return InetAddresses.toAddrString(address);
}
}, },
DATE("date_range", NumberType.LONG) { DATE("date_range", NumberType.LONG) {
@Override @Override

View File

@ -49,7 +49,7 @@ public abstract class BaseRandomBinaryDocValuesRangeQueryTestCase extends BaseRa
@Override @Override
protected final Field newRangeField(Range box) { 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); RangeFieldMapper.Range range = new RangeFieldMapper.Range(rangeType(), testRange.getMin(), testRange.getMax(), true , true);
try { try {
BytesRef encodeRange = rangeType().encodeRanges(Collections.singleton(range)); BytesRef encodeRange = rangeType().encodeRanges(Collections.singleton(range));
@ -61,25 +61,25 @@ public abstract class BaseRandomBinaryDocValuesRangeQueryTestCase extends BaseRa
@Override @Override
protected final Query newIntersectsQuery(Range box) { 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); return rangeType().dvRangeQuery(fieldName(), INTERSECTS, testRange.getMin(), testRange.getMax(), true, true);
} }
@Override @Override
protected final Query newContainsQuery(Range box) { 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); return rangeType().dvRangeQuery(fieldName(), CONTAINS, testRange.getMin(), testRange.getMax(), true, true);
} }
@Override @Override
protected final Query newWithinQuery(Range box) { 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); return rangeType().dvRangeQuery(fieldName(), WITHIN, testRange.getMin(), testRange.getMax(), true, true);
} }
@Override @Override
protected final Query newCrossesQuery(Range box) { 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); return rangeType().dvRangeQuery(fieldName(), CROSSES, testRange.getMin(), testRange.getMax(), true, true);
} }
@ -116,7 +116,7 @@ public abstract class BaseRandomBinaryDocValuesRangeQueryTestCase extends BaseRa
@Override @Override
protected final boolean isEqual(Range o) { 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()); return Objects.equals(getMin(), other.getMin()) && Objects.equals(getMax(), other.getMax());
} }

View File

@ -56,7 +56,7 @@ public class DoubleRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinary
} }
} }
private static class DoubleTestRange extends AbstractRange { private static class DoubleTestRange extends AbstractRange<Double> {
double min; double min;
double max; double max;
@ -66,7 +66,7 @@ public class DoubleRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinary
} }
@Override @Override
public Object getMin() { public Double getMin() {
return min; return min;
} }
@ -82,7 +82,7 @@ public class DoubleRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinary
} }
@Override @Override
public Object getMax() { public Double getMax() {
return max; return max;
} }

View File

@ -56,7 +56,7 @@ public class FloatRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryD
} }
} }
private static class FloatTestRange extends AbstractRange { private static class FloatTestRange extends AbstractRange<Float> {
float min; float min;
float max; float max;
@ -66,7 +66,7 @@ public class FloatRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryD
} }
@Override @Override
public Object getMin() { public Float getMin() {
return min; return min;
} }
@ -82,7 +82,7 @@ public class FloatRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryD
} }
@Override @Override
public Object getMax() { public Float getMax() {
return max; return max;
} }

View File

@ -67,7 +67,7 @@ public class InetAddressRandomBinaryDocValuesRangeQueryTests extends BaseRandomB
} }
} }
private static class IpRange extends AbstractRange { private static class IpRange extends AbstractRange<InetAddress> {
InetAddress minAddress; InetAddress minAddress;
InetAddress maxAddress; InetAddress maxAddress;
byte[] min; byte[] min;
@ -81,7 +81,7 @@ public class InetAddressRandomBinaryDocValuesRangeQueryTests extends BaseRandomB
} }
@Override @Override
public Object getMin() { public InetAddress getMin() {
return minAddress; return minAddress;
} }
@ -101,7 +101,7 @@ public class InetAddressRandomBinaryDocValuesRangeQueryTests extends BaseRandomB
} }
@Override @Override
public Object getMax() { public InetAddress getMax() {
return maxAddress; return maxAddress;
} }

View File

@ -64,7 +64,7 @@ public class IntegerRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinar
} }
} }
private static class IntTestRange extends AbstractRange { private static class IntTestRange extends AbstractRange<Integer> {
int min; int min;
int max; int max;
@ -74,7 +74,7 @@ public class IntegerRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinar
} }
@Override @Override
public Object getMin() { public Integer getMin() {
return min; return min;
} }
@ -90,7 +90,7 @@ public class IntegerRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinar
} }
@Override @Override
public Object getMax() { public Integer getMax() {
return max; return max;
} }

View File

@ -64,7 +64,7 @@ public class LongRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryDo
} }
} }
private static class LongTestRange extends AbstractRange { private static class LongTestRange extends AbstractRange<Long> {
long min; long min;
long max; long max;
@ -74,7 +74,7 @@ public class LongRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryDo
} }
@Override @Override
public Object getMin() { public Long getMin() {
return min; return min;
} }
@ -90,7 +90,7 @@ public class LongRandomBinaryDocValuesRangeQueryTests extends BaseRandomBinaryDo
} }
@Override @Override
public Object getMax() { public Long getMax() {
return max; return max;
} }

View File

@ -17,11 +17,15 @@
* under the License. * under the License.
*/ */
package org.elasticsearch.action.admin.indices.template; package org.elasticsearch.index.mapper;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.MapperExtrasPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
import java.util.Collection;
import static org.elasticsearch.test.StreamsUtils.copyToBytesFromClasspath; 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 * prior to their 5.x releases work for newly created indices
*/ */
public class BWCTemplateTests extends ESSingleNodeTestCase { public class BWCTemplateTests extends ESSingleNodeTestCase {
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(MapperExtrasPlugin.class);
}
public void testBeatsTemplatesBWC() throws Exception { public void testBeatsTemplatesBWC() throws Exception {
byte[] metricBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/metricbeat-5.0.template.json"); byte[] metricBeat = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/metricbeat-5.0.template.json");
byte[] packetBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/packetbeat-5.0.template.json"); byte[] packetBeat = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/packetbeat-5.0.template.json");
byte[] fileBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/filebeat-5.0.template.json"); byte[] fileBeat = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/filebeat-5.0.template.json");
byte[] winLogBeat = copyToBytesFromClasspath("/org/elasticsearch/action/admin/indices/template/winlogbeat-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("metricbeat").setSource(metricBeat, XContentType.JSON).get();
client().admin().indices().preparePutTemplate("packetbeat").setSource(packetBeat, XContentType.JSON).get(); client().admin().indices().preparePutTemplate("packetbeat").setSource(packetBeat, XContentType.JSON).get();
client().admin().indices().preparePutTemplate("filebeat").setSource(fileBeat, XContentType.JSON).get(); client().admin().indices().preparePutTemplate("filebeat").setSource(fileBeat, XContentType.JSON).get();

View File

@ -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<Object[]> parameters() throws Exception {
return ESClientYamlSuiteTestCase.createParameters();
}
}

View File

@ -27,10 +27,13 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.InternalSettingsPlugin;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
@ -42,6 +45,12 @@ import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase { public class RangeFieldMapperTests extends AbstractNumericFieldMapperTestCase {
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(InternalSettingsPlugin.class, MapperExtrasPlugin.class);
}
private static String FROM_DATE = "2016-10-31"; private static String FROM_DATE = "2016-10-31";
private static String TO_DATE = "2016-11-01 20:00:00"; private static String TO_DATE = "2016-11-01 20:00:00";
private static String FROM_IP = "::ffff:c0a8:107"; private static String FROM_IP = "::ffff:c0a8:107";

View File

@ -95,7 +95,7 @@ public class RangeFieldTypeTests extends FieldTypeTestCase {
Object to = nextTo(from); Object to = nextTo(from);
assertEquals(getExpectedRangeQuery(relation, from, to, includeLower, includeUpper), 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) { private Query getExpectedRangeQuery(ShapeRelation relation, Object from, Object to, boolean includeLower, boolean includeUpper) {

View File

@ -50,7 +50,7 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
@Override @Override
protected Collection<Class<? extends Plugin>> getPlugins() { protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(InternalSettingsPlugin.class); return pluginList(InternalSettingsPlugin.class, MapperExtrasPlugin.class);
} }
public void testDefaults() throws Exception { public void testDefaults() throws Exception {

View File

@ -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"), not(nullValue()));
assertThat(hit.field("foo.token_count_without_position_increments").getValues().size(), equalTo(englishTermCounts.length)); assertThat(hit.field("foo.token_count_without_position_increments").getValues().size(), equalTo(englishTermCounts.length));
for (int i = 0; i < englishTermCounts.length; i++) { 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) { if (loadCountedFields && storeCountedFields) {

View File

@ -45,6 +45,12 @@ import static org.hamcrest.Matchers.equalTo;
* Test for {@link TokenCountFieldMapper}. * Test for {@link TokenCountFieldMapper}.
*/ */
public class TokenCountFieldMapperTests extends ESSingleNodeTestCase { public class TokenCountFieldMapperTests extends ESSingleNodeTestCase {
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(InternalSettingsPlugin.class, MapperExtrasPlugin.class);
}
public void testMerge() throws IOException { public void testMerge() throws IOException {
String stage1Mapping = XContentFactory.jsonBuilder().startObject() String stage1Mapping = XContentFactory.jsonBuilder().startObject()
.startObject("person") .startObject("person")
@ -122,11 +128,6 @@ public class TokenCountFieldMapperTests extends ESSingleNodeTestCase {
return analyzer; return analyzer;
} }
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(InternalSettingsPlugin.class);
}
public void testEmptyName() throws IOException { public void testEmptyName() throws IOException {
IndexService indexService = createIndex("test"); IndexService indexService = createIndex("test");
DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); DocumentMapperParser parser = indexService.mapperService().documentMapperParser();

View File

@ -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 }

View File

@ -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" }

View File

@ -25,7 +25,16 @@ esplugin {
dependencies { dependencies {
// for testing hasChild and hasParent rejections // for testing hasChild and hasParent rejections
compile project(path: ':modules:mapper-extras', configuration: 'runtime')
testCompile project(path: ':modules:parent-join', 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" compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes"
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes" compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes"

View File

@ -20,9 +20,6 @@ setup:
type: double type: double
number: number:
type: long type: long
scaled_float:
type: scaled_float
scaling_factor: 100
date: date:
type: date type: date
@ -300,56 +297,6 @@ setup:
- match: { aggregations.double_terms.buckets.1.doc_count: 1 } - 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": "Date test":
- do: - do:

View File

@ -35,6 +35,7 @@ List projects = [
'modules:lang-expression', 'modules:lang-expression',
'modules:lang-mustache', 'modules:lang-mustache',
'modules:lang-painless', 'modules:lang-painless',
'modules:mapper-extras',
'modules:parent-join', 'modules:parent-join',
'modules:percolator', 'modules:percolator',
'modules:reindex', 'modules:reindex',
@ -65,6 +66,7 @@ List projects = [
'qa:auto-create-index', 'qa:auto-create-index',
'qa:evil-tests', 'qa:evil-tests',
'qa:full-cluster-restart', 'qa:full-cluster-restart',
'qa:integration-bwc',
'qa:mixed-cluster', 'qa:mixed-cluster',
'qa:multi-cluster-search', 'qa:multi-cluster-search',
'qa:no-bootstrap-tests', 'qa:no-bootstrap-tests',

View File

@ -137,19 +137,17 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
public static final String STRING_FIELD_NAME = "mapped_string"; public static final String STRING_FIELD_NAME = "mapped_string";
protected static final String STRING_FIELD_NAME_2 = "mapped_string_2"; 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_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 DOUBLE_FIELD_NAME = "mapped_double";
protected static final String BOOLEAN_FIELD_NAME = "mapped_boolean"; protected static final String BOOLEAN_FIELD_NAME = "mapped_boolean";
protected static final String DATE_FIELD_NAME = "mapped_date"; 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 OBJECT_FIELD_NAME = "mapped_object";
protected static final String GEO_POINT_FIELD_NAME = "mapped_geo_point"; 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 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, protected static final String[] MAPPED_FIELD_NAMES = new String[]{STRING_FIELD_NAME, INT_FIELD_NAME,
DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME, DATE_RANGE_FIELD_NAME, OBJECT_FIELD_NAME, GEO_POINT_FIELD_NAME, DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME, OBJECT_FIELD_NAME, GEO_POINT_FIELD_NAME,
GEO_SHAPE_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, 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, DATE_RANGE_FIELD_NAME, GEO_POINT_FIELD_NAME, }; DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME, GEO_POINT_FIELD_NAME, };
private static final int NUMBER_OF_TESTQUERIES = 20; private static final int NUMBER_OF_TESTQUERIES = 20;
protected static Version indexVersionCreated; protected static Version indexVersionCreated;
@ -1078,11 +1076,9 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
STRING_FIELD_NAME, "type=text", STRING_FIELD_NAME, "type=text",
STRING_FIELD_NAME_2, "type=keyword", STRING_FIELD_NAME_2, "type=keyword",
INT_FIELD_NAME, "type=integer", INT_FIELD_NAME, "type=integer",
INT_RANGE_FIELD_NAME, "type=integer_range",
DOUBLE_FIELD_NAME, "type=double", DOUBLE_FIELD_NAME, "type=double",
BOOLEAN_FIELD_NAME, "type=boolean", BOOLEAN_FIELD_NAME, "type=boolean",
DATE_FIELD_NAME, "type=date", DATE_FIELD_NAME, "type=date",
DATE_RANGE_FIELD_NAME, "type=date_range",
OBJECT_FIELD_NAME, "type=object", OBJECT_FIELD_NAME, "type=object",
GEO_POINT_FIELD_NAME, "type=geo_point", GEO_POINT_FIELD_NAME, "type=geo_point",
GEO_SHAPE_FIELD_NAME, "type=geo_shape" GEO_SHAPE_FIELD_NAME, "type=geo_shape"