From cb1829d9dcb9111a4ec9c5d84895dd1360921942 Mon Sep 17 00:00:00 2001 From: jimczi Date: Thu, 31 Jan 2019 15:27:02 +0100 Subject: [PATCH 1/6] Add an option to force the numeric type of a field sort This change adds an option to the `FieldSortBuilder` that allows to transform the type of a numeric field into another. Possible values for this option are `long` that transforms the source field into an integer and `double` that transforms the source field into a floating point. This new option is useful for cross-index search when the sort field is mapped differently on some indices. For instance if a field is mapped as a floating point in one index and as an integer in another it is possible to align the type for both indices using the `numeric_type` option: ``` { "sort": { "field": "my_field", "numeric_type": "double" <1> } } ``` <1> Ensure that values for this field are transformed to a floating point if needed. Only `long` and `double` are supported at the moment but the goal is to also handle `date` and `date_nanos` when #32601 is merged. --- docs/reference/search/request/sort.asciidoc | 67 ++++++++++++++++++ .../plain/SortedNumericDVIndexFieldData.java | 27 ++++++-- .../search/sort/FieldSortBuilder.java | 65 +++++++++++++++++- .../search/sort/FieldSortBuilderTests.java | 8 ++- .../search/sort/FieldSortIT.java | 68 +++++++++++++++++++ 5 files changed, 225 insertions(+), 10 deletions(-) diff --git a/docs/reference/search/request/sort.asciidoc b/docs/reference/search/request/sort.asciidoc index bd8c0d1ad5c27..664447acb6bd2 100644 --- a/docs/reference/search/request/sort.asciidoc +++ b/docs/reference/search/request/sort.asciidoc @@ -108,6 +108,73 @@ POST /_search -------------------------------------------------- // CONSOLE +==== Sorting numeric fields + +For numeric fields it is also possible to cast the values from one type +to another using the `numeric_type` option. +This option accepts the following values: [`"double", "long"`] and can be useful +for cross-index search if the sort field is mapped differently on some +indices. + +Consider for instance these two indices: + +[source,js] +-------------------------------------------------- +PUT /index_double +{ + "mappings": { + "properties": { + "field": { "type": "double" } + } + } +} +-------------------------------------------------- +// CONSOLE + +[source,js] +-------------------------------------------------- +PUT /index_long +{ + "mappings": { + "properties": { + "field": { "type": "long" } + } + } +} +-------------------------------------------------- +// CONSOLE +// TEST[continued] + +Since `field` is mapped as a `double` in the first index and as a `long` +in the second index, it is not possible to use this field to sort requests +that query both indices bu default. However you can force the type to one +or the other with the `numeric_type` option in order to force a specific +type for all indices: + +[source,js] +-------------------------------------------------- +POST /index_long,index_double/_search +{ + "sort" : [ + { + "field" : { + "numeric_type" : "double" + } + } + ] +} +-------------------------------------------------- +// CONSOLE +// TEST[continued] + +In the example above, values for the `index_long` index are casted to +a double in order to be compatible with the values produced by the +`index_double` index. +It is also possible to transform a floating point field into a `long` +but note that in this case floating points are replaced by the largest +value that is less than or equal to the argument and is equal to a mathematical +integer. + [[nested-sorting]] ==== Sorting within nested objects. diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericDVIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericDVIndexFieldData.java index 1b28d3a8c7bc0..14ee1469c2076 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericDVIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericDVIndexFieldData.java @@ -31,6 +31,7 @@ import org.apache.lucene.search.SortedNumericSortField; import org.apache.lucene.util.Accountable; import org.apache.lucene.util.NumericUtils; +import org.elasticsearch.common.inject.name.Named; import org.elasticsearch.index.Index; import org.elasticsearch.index.fielddata.AtomicNumericFieldData; import org.elasticsearch.index.fielddata.FieldData; @@ -46,6 +47,9 @@ import java.io.IOException; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Predicate; /** * FieldData backed by {@link LeafReader#getSortedNumericDocValues(String)} @@ -62,10 +66,15 @@ public SortedNumericDVIndexFieldData(Index index, String fieldNames, NumericType this.numericType = numericType; } - @Override - public SortField sortField(Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { + /** + * Returns the {@link SortField} to used for sorting. + * Values are casted to the provided targetNumericType type if it doesn't + * match the field's numericType. + */ + public SortField sortField(NumericType targetNumericType, Object missingValue, MultiValueMode sortMode, Nested nested, + boolean reverse) { final XFieldComparatorSource source; - switch (numericType) { + switch (targetNumericType) { case HALF_FLOAT: case FLOAT: source = new FloatValuesComparatorSource(this, missingValue, sortMode, nested); @@ -76,7 +85,7 @@ public SortField sortField(Object missingValue, MultiValueMode sortMode, Nested break; default: - assert !numericType.isFloatingPoint(); + assert !targetNumericType.isFloatingPoint(); source = new LongValuesComparatorSource(this, missingValue, sortMode, nested); break; } @@ -86,8 +95,9 @@ public SortField sortField(Object missingValue, MultiValueMode sortMode, Nested * returns a custom sort field otherwise. */ if (nested != null - || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) - || numericType == NumericType.HALF_FLOAT) { + || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) + || numericType == NumericType.HALF_FLOAT + || targetNumericType != numericType) { return new SortField(fieldName, source, reverse); } @@ -112,6 +122,11 @@ public SortField sortField(Object missingValue, MultiValueMode sortMode, Nested return sortField; } + @Override + public SortField sortField(Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { + return sortField(numericType, missingValue, sortMode, nested, reverse); + } + @Override public NumericType getNumericType() { return numericType; diff --git a/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java b/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java index 9bd1efbe757f3..6be229aee2ddc 100644 --- a/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java @@ -33,6 +33,8 @@ import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; import org.elasticsearch.index.fielddata.IndexNumericFieldData; +import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType; +import org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryRewriteContext; @@ -42,6 +44,7 @@ import org.elasticsearch.search.MultiValueMode; import java.io.IOException; +import java.util.Locale; import java.util.Objects; import static org.elasticsearch.search.sort.NestedSortBuilder.NESTED_FIELD; @@ -56,6 +59,7 @@ public class FieldSortBuilder extends SortBuilder { public static final ParseField MISSING = new ParseField("missing"); public static final ParseField SORT_MODE = new ParseField("mode"); public static final ParseField UNMAPPED_TYPE = new ParseField("unmapped_type"); + public static final ParseField NUMERIC_TYPE = new ParseField("numeric_type"); /** * special field name to sort by index order @@ -72,6 +76,8 @@ public class FieldSortBuilder extends SortBuilder { private String unmappedType; + private String numericType; + private SortMode sortMode; private QueryBuilder nestedFilter; @@ -94,6 +100,7 @@ public FieldSortBuilder(FieldSortBuilder template) { if (template.getNestedSort() != null) { this.setNestedSort(template.getNestedSort()); } + this.numericType = template.numericType; } /** @@ -123,6 +130,9 @@ public FieldSortBuilder(StreamInput in) throws IOException { if (in.getVersion().onOrAfter(Version.V_6_1_0)) { nestedSort = in.readOptionalWriteable(NestedSortBuilder::new); } + if (in.getVersion().onOrAfter(Version.V_7_0_0)) { + numericType = in.readOptionalString(); + } } @Override @@ -137,6 +147,9 @@ public void writeTo(StreamOutput out) throws IOException { if (out.getVersion().onOrAfter(Version.V_6_1_0)) { out.writeOptionalWriteable(nestedSort); } + if (out.getVersion().onOrAfter(Version.V_7_0_0)) { + out.writeOptionalString(numericType); + } } /** Returns the document field this sort should be based on. */ @@ -274,6 +287,36 @@ public FieldSortBuilder setNestedSort(final NestedSortBuilder nestedSort) { return this; } + /** + * Returns the numeric type that values should translated to or null + * if the original numeric type should be preserved. + */ + public String getNumericType() { + return numericType; + } + + /** + * Forces the numeric type to use for the field. The query will fail if this option + * is set on a field that is not mapped as a numeric in some indices. + * Specifying a numeric type tells Elasticsearch what type the sort values should + * have, which is important for cross-index search, if a field does not have + * the same type on all indices. + * Allowed values are long and double. + */ + public FieldSortBuilder setNumericType(String numericType) { + String upperCase = numericType.toUpperCase(Locale.ENGLISH); + switch (upperCase) { + case "LONG": + case "DOUBLE": + break; + + default: + throw new IllegalArgumentException("invalid value for [numeric_type], must be [LONG, DOUBLE], got " + numericType); + } + this.numericType = upperCase; + return this; + } + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); @@ -297,6 +340,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (nestedSort != null) { builder.field(NESTED_FIELD.getPreferredName(), nestedSort); } + if (numericType != null) { + builder.field(NUMERIC_TYPE.getPreferredName(), numericType); + } builder.endObject(); builder.endObject(); return builder; @@ -351,7 +397,18 @@ public SortFieldAndFormat build(QueryShardContext context) throws IOException { && (sortMode == SortMode.SUM || sortMode == SortMode.AVG || sortMode == SortMode.MEDIAN)) { throw new QueryShardException(context, "we only support AVG, MEDIAN and SUM on number based fields"); } - SortField field = fieldData.sortField(missing, localSortMode, nested, reverse); + final SortField field; + if (numericType != null) { + if (fieldData instanceof SortedNumericDVIndexFieldData == false) { + throw new QueryShardException(context, + "[numeric_type] option cannot be set on a non-numeric field, got " + fieldType.typeName()); + } + SortedNumericDVIndexFieldData numericFieldData = (SortedNumericDVIndexFieldData) fieldData; + NumericType resolvedType = NumericType.valueOf(numericType); + field = numericFieldData.sortField(resolvedType, missing, localSortMode, nested, reverse); + } else { + field = fieldData.sortField(missing, localSortMode, nested, reverse); + } return new SortFieldAndFormat(field, fieldType.docValueFormat(null, null)); } } @@ -370,13 +427,14 @@ public boolean equals(Object other) { return (Objects.equals(this.fieldName, builder.fieldName) && Objects.equals(this.nestedFilter, builder.nestedFilter) && Objects.equals(this.nestedPath, builder.nestedPath) && Objects.equals(this.missing, builder.missing) && Objects.equals(this.order, builder.order) && Objects.equals(this.sortMode, builder.sortMode) - && Objects.equals(this.unmappedType, builder.unmappedType) && Objects.equals(this.nestedSort, builder.nestedSort)); + && Objects.equals(this.unmappedType, builder.unmappedType) && Objects.equals(this.nestedSort, builder.nestedSort)) + && Objects.equals(this.nestedFilter, builder.numericType); } @Override public int hashCode() { return Objects.hash(this.fieldName, this.nestedFilter, this.nestedPath, this.nestedSort, this.missing, this.order, this.sortMode, - this.unmappedType); + this.unmappedType, this.numericType); } @Override @@ -413,6 +471,7 @@ public static FieldSortBuilder fromXContent(XContentParser parser, String fieldN return SortBuilder.parseNestedFilter(p); }, NESTED_FILTER_FIELD); PARSER.declareObject(FieldSortBuilder::setNestedSort, (p, c) -> NestedSortBuilder.fromXContent(p), NESTED_FIELD); + PARSER.declareString((b, v) -> b.setNumericType(v), NUMERIC_TYPE); } @Override diff --git a/server/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java b/server/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java index fc32abe18c76b..cb96218778e34 100644 --- a/server/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java @@ -102,13 +102,16 @@ public FieldSortBuilder randomFieldSortBuilder() { } } } + if (randomBoolean()) { + builder.setNumericType(randomFrom(random(), "long", "double")); + } return builder; } @Override protected FieldSortBuilder mutate(FieldSortBuilder original) throws IOException { FieldSortBuilder mutated = new FieldSortBuilder(original); - int parameter = randomIntBetween(0, 4); + int parameter = randomIntBetween(0, 5); switch (parameter) { case 0: if (original.getNestedPath() == null && original.getNestedFilter() == null) { @@ -136,6 +139,9 @@ protected FieldSortBuilder mutate(FieldSortBuilder original) throws IOException case 4: mutated.order(randomValueOtherThan(original.order(), () -> randomFrom(SortOrder.values()))); break; + case 5: + mutated.setNumericType(randomValueOtherThan(original.getNumericType(), () -> randomFrom("long", "double"))); + break; default: throw new IllegalStateException("Unsupported mutation."); } diff --git a/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java b/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java index ad3e9fc52e064..93bc98f27af26 100644 --- a/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java +++ b/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java @@ -22,6 +22,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.UnicodeUtil; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchPhaseExecutionException; @@ -36,6 +37,7 @@ import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.rest.RestStatus; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptType; @@ -1638,4 +1640,70 @@ public void testFieldAliasesWithMissingValues() throws Exception { assertEquals(100.2, hits.getAt(1).getSortValues()[0]); assertEquals(120.3, hits.getAt(2).getSortValues()[0]); } + + public void testCastNumericType() throws Exception { + assertAcked(prepareCreate("index_double") + .addMapping("_doc", "field", "type=double")); + assertAcked(prepareCreate("index_long") + .addMapping("_doc", "field", "type=long")); + assertAcked(prepareCreate("index_float") + .addMapping("_doc", "field", "type=float")); + ensureGreen("index_double", "index_long", "index_float"); + + List builders = new ArrayList<>(); + builders.add(client().prepareIndex("index_double", "_doc").setSource("field", 12.6)); + builders.add(client().prepareIndex("index_long", "_doc").setSource("field", 12)); + builders.add(client().prepareIndex("index_float", "_doc").setSource("field", 12.1)); + indexRandom(true, true, builders); + + { + SearchResponse response = client().prepareSearch() + .setQuery(matchAllQuery()) + .setSize(builders.size()) + .addSort(SortBuilders.fieldSort("field").setNumericType("long")) + .get(); + SearchHits hits = response.getHits(); + + assertEquals(3, hits.getHits().length); + for (int i = 0; i < 3; i++) { + assertThat(hits.getAt(i).getSortValues()[0].getClass(), equalTo(Long.class)); + } + assertEquals(12l, hits.getAt(0).getSortValues()[0]); + assertEquals(12l, hits.getAt(1).getSortValues()[0]); + assertEquals(12l, hits.getAt(2).getSortValues()[0]); + } + + { + SearchResponse response = client().prepareSearch() + .setQuery(matchAllQuery()) + .setSize(builders.size()) + .addSort(SortBuilders.fieldSort("field").setNumericType("double")) + .get(); + SearchHits hits = response.getHits(); + assertEquals(3, hits.getHits().length); + for (int i = 0; i < 3; i++) { + assertThat(hits.getAt(i).getSortValues()[0].getClass(), equalTo(Double.class)); + } + assertEquals(12d, hits.getAt(0).getSortValues()[0]); + assertEquals(12.1d, (double) hits.getAt(1).getSortValues()[0], 0.001f); + assertEquals(12.6d, hits.getAt(2).getSortValues()[0]); + } + } + + public void testCastNumericTypeExceptions() throws Exception { + assertAcked(prepareCreate("index") + .addMapping("_doc", "keyword", "type=keyword", "ip", "type=ip")); + ensureGreen("index"); + for (String invalidField : new String[] {"keyword", "ip"}) { + for (String numericType : new String[]{"long", "double"}) { + ElasticsearchException exc = expectThrows(ElasticsearchException.class, () -> client().prepareSearch() + .setQuery(matchAllQuery()) + .addSort(SortBuilders.fieldSort(invalidField).setNumericType(numericType)) + .get() + ); + assertThat(exc.status(), equalTo(RestStatus.BAD_REQUEST)); + assertThat(exc.getDetailedMessage(), containsString("[numeric_type] option cannot be set on a non-numeric field")); + } + } + } } From 0174ca5ed1a1ecf2eca667fbaf6588f2d84a1070 Mon Sep 17 00:00:00 2001 From: jimczi Date: Thu, 31 Jan 2019 15:36:37 +0100 Subject: [PATCH 2/6] checkstyle --- .../index/fielddata/plain/SortedNumericDVIndexFieldData.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericDVIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericDVIndexFieldData.java index 14ee1469c2076..945b1966e1655 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericDVIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericDVIndexFieldData.java @@ -31,7 +31,6 @@ import org.apache.lucene.search.SortedNumericSortField; import org.apache.lucene.util.Accountable; import org.apache.lucene.util.NumericUtils; -import org.elasticsearch.common.inject.name.Named; import org.elasticsearch.index.Index; import org.elasticsearch.index.fielddata.AtomicNumericFieldData; import org.elasticsearch.index.fielddata.FieldData; @@ -47,9 +46,6 @@ import java.io.IOException; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Predicate; /** * FieldData backed by {@link LeafReader#getSortedNumericDocValues(String)} From 75feb1a0aa21c291f018e26516344eb3de839951 Mon Sep 17 00:00:00 2001 From: jimczi Date: Thu, 31 Jan 2019 21:05:44 +0100 Subject: [PATCH 3/6] checkstyle --- .../org/elasticsearch/search/sort/FieldSortIT.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java b/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java index 93bc98f27af26..5ff98764fb3f2 100644 --- a/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java +++ b/server/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java @@ -1668,9 +1668,9 @@ public void testCastNumericType() throws Exception { for (int i = 0; i < 3; i++) { assertThat(hits.getAt(i).getSortValues()[0].getClass(), equalTo(Long.class)); } - assertEquals(12l, hits.getAt(0).getSortValues()[0]); - assertEquals(12l, hits.getAt(1).getSortValues()[0]); - assertEquals(12l, hits.getAt(2).getSortValues()[0]); + assertEquals(12L, hits.getAt(0).getSortValues()[0]); + assertEquals(12L, hits.getAt(1).getSortValues()[0]); + assertEquals(12L, hits.getAt(2).getSortValues()[0]); } { @@ -1684,9 +1684,9 @@ public void testCastNumericType() throws Exception { for (int i = 0; i < 3; i++) { assertThat(hits.getAt(i).getSortValues()[0].getClass(), equalTo(Double.class)); } - assertEquals(12d, hits.getAt(0).getSortValues()[0]); - assertEquals(12.1d, (double) hits.getAt(1).getSortValues()[0], 0.001f); - assertEquals(12.6d, hits.getAt(2).getSortValues()[0]); + assertEquals(12D, hits.getAt(0).getSortValues()[0]); + assertEquals(12.1D, (double) hits.getAt(1).getSortValues()[0], 0.001f); + assertEquals(12.6D, hits.getAt(2).getSortValues()[0]); } } From 24c961afd1d7b6e0197d8d15e015761ffeae6d7d Mon Sep 17 00:00:00 2001 From: jimczi Date: Tue, 12 Mar 2019 10:14:33 +0100 Subject: [PATCH 4/6] address review --- docs/reference/search/request/sort.asciidoc | 4 ++-- .../java/org/elasticsearch/search/sort/FieldSortBuilder.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/reference/search/request/sort.asciidoc b/docs/reference/search/request/sort.asciidoc index 664447acb6bd2..cc1dc894f9686 100644 --- a/docs/reference/search/request/sort.asciidoc +++ b/docs/reference/search/request/sort.asciidoc @@ -172,8 +172,8 @@ a double in order to be compatible with the values produced by the `index_double` index. It is also possible to transform a floating point field into a `long` but note that in this case floating points are replaced by the largest -value that is less than or equal to the argument and is equal to a mathematical -integer. +value that is less than or equal (greater than or equal if the value +is negative) to the argument and is equal to a mathematical integer. [[nested-sorting]] ==== Sorting within nested objects. diff --git a/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java b/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java index 6be229aee2ddc..5b90cccbc67a6 100644 --- a/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java @@ -399,7 +399,7 @@ public SortFieldAndFormat build(QueryShardContext context) throws IOException { } final SortField field; if (numericType != null) { - if (fieldData instanceof SortedNumericDVIndexFieldData == false) { + if (fieldData instanceof IndexNumericFieldData == false) { throw new QueryShardException(context, "[numeric_type] option cannot be set on a non-numeric field, got " + fieldType.typeName()); } @@ -428,7 +428,7 @@ public boolean equals(Object other) { && Objects.equals(this.nestedPath, builder.nestedPath) && Objects.equals(this.missing, builder.missing) && Objects.equals(this.order, builder.order) && Objects.equals(this.sortMode, builder.sortMode) && Objects.equals(this.unmappedType, builder.unmappedType) && Objects.equals(this.nestedSort, builder.nestedSort)) - && Objects.equals(this.nestedFilter, builder.numericType); + && Objects.equals(this.numericType, builder.numericType); } @Override From a27eb7c6d9fe48b473abd542e3470302298f4077 Mon Sep 17 00:00:00 2001 From: jimczi Date: Tue, 12 Mar 2019 10:34:57 +0100 Subject: [PATCH 5/6] fix typo --- docs/reference/search/request/sort.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/search/request/sort.asciidoc b/docs/reference/search/request/sort.asciidoc index cc1dc894f9686..e9f00555c8d5e 100644 --- a/docs/reference/search/request/sort.asciidoc +++ b/docs/reference/search/request/sort.asciidoc @@ -147,7 +147,7 @@ PUT /index_long Since `field` is mapped as a `double` in the first index and as a `long` in the second index, it is not possible to use this field to sort requests -that query both indices bu default. However you can force the type to one +that query both indices by default. However you can force the type to one or the other with the `numeric_type` option in order to force a specific type for all indices: From 437fc6492e0950c6332aa32e5b3cb76734995e4c Mon Sep 17 00:00:00 2001 From: jimczi Date: Tue, 12 Mar 2019 11:04:00 +0100 Subject: [PATCH 6/6] adapt serialization version --- .../java/org/elasticsearch/search/sort/FieldSortBuilder.java | 4 ++-- .../org/elasticsearch/search/sort/FieldSortBuilderTests.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java b/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java index 5b90cccbc67a6..18ed910be30c2 100644 --- a/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java @@ -130,7 +130,7 @@ public FieldSortBuilder(StreamInput in) throws IOException { if (in.getVersion().onOrAfter(Version.V_6_1_0)) { nestedSort = in.readOptionalWriteable(NestedSortBuilder::new); } - if (in.getVersion().onOrAfter(Version.V_7_0_0)) { + if (in.getVersion().onOrAfter(Version.V_8_0_0)) { numericType = in.readOptionalString(); } } @@ -147,7 +147,7 @@ public void writeTo(StreamOutput out) throws IOException { if (out.getVersion().onOrAfter(Version.V_6_1_0)) { out.writeOptionalWriteable(nestedSort); } - if (out.getVersion().onOrAfter(Version.V_7_0_0)) { + if (out.getVersion().onOrAfter(Version.V_8_0_0)) { out.writeOptionalString(numericType); } } diff --git a/server/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java b/server/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java index cb96218778e34..a13f5ae4bfce3 100644 --- a/server/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java @@ -140,7 +140,7 @@ protected FieldSortBuilder mutate(FieldSortBuilder original) throws IOException mutated.order(randomValueOtherThan(original.order(), () -> randomFrom(SortOrder.values()))); break; case 5: - mutated.setNumericType(randomValueOtherThan(original.getNumericType(), () -> randomFrom("long", "double"))); + mutated.setNumericType(randomValueOtherThan(original.getNumericType(), () -> randomFrom("LONG", "DOUBLE"))); break; default: throw new IllegalStateException("Unsupported mutation.");