Skip to content

Commit

Permalink
Remove use_field_mapping format option for docvalue fields. (#55622)
Browse files Browse the repository at this point in the history
In 7.0, we began formatting `docvalue_fields` by default using each field's
mapping definition. To ease the transition from 6.x, we added the format
option `use_field_mapping`. This parameter was deprecated in 7.0, and we can
remove it in 8.0.
  • Loading branch information
jtibshirani authored Apr 27, 2020
1 parent d67a1b4 commit 724e24d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 61 deletions.
7 changes: 7 additions & 0 deletions docs/reference/migration/migrate_8_0/search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@ deprecated in 7.6, and are now removed in 8.x. The form
The `indices_boost` option in the search request used to accept the boosts
both as an object and as an array. The object format has been deprecated since
5.2 and is now removed in 8.0.

[float]
==== Removal of `use_field_mapping` for docvalues fields
In 7.0, we began formatting `docvalue_fields` by default using each field's
mapping definition. To ease the transition from 6.x, we added the format
option `use_field_mapping`. This parameter was deprecated in 7.0, and is now
removed in 8.0.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
*/
package org.elasticsearch.search.fetch.subphase;

import org.apache.logging.log4j.LogManager;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.ReaderUtil;
import org.apache.lucene.index.SortedNumericDocValues;
import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.index.fielddata.LeafFieldData;
import org.elasticsearch.index.fielddata.LeafNumericFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.LeafFieldData;
import org.elasticsearch.index.fielddata.LeafNumericFieldData;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData;
Expand All @@ -45,7 +43,6 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

import static org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import static org.elasticsearch.search.DocValueFormat.withNanosecondResolution;
Expand All @@ -57,10 +54,6 @@
*/
public final class FetchDocValuesPhase implements FetchSubPhase {

private static final String USE_DEFAULT_FORMAT = "use_field_mapping";
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(
LogManager.getLogger(FetchDocValuesPhase.class));

@Override
public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOException {

Expand All @@ -82,16 +75,6 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOExcept
hits = hits.clone(); // don't modify the incoming hits
Arrays.sort(hits, Comparator.comparingInt(SearchHit::docId));

if (context.docValuesContext().fields().stream()
.map(f -> f.format)
.filter(USE_DEFAULT_FORMAT::equals)
.findAny()
.isPresent()) {
DEPRECATION_LOGGER.deprecatedAndMaybeLog("explicit_default_format",
"[" + USE_DEFAULT_FORMAT + "] is a special format that was only used to " +
"ease the transition to 7.x. It has become the default and shouldn't be set explicitly anymore.");
}

for (FieldAndFormat fieldAndFormat : context.docValuesContext().fields()) {
String field = fieldAndFormat.field;
MappedFieldType fieldType = context.mapperService().fieldType(field);
Expand All @@ -105,10 +88,6 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOExcept
}
final DocValueFormat format;
String formatDesc = fieldAndFormat.format;
if (Objects.equals(formatDesc, USE_DEFAULT_FORMAT)) {
// TODO: Remove in 8.x
formatDesc = null;
}
if (isNanosecond) {
format = withNanosecondResolution(fieldType.docValueFormat(formatDesc, null));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,42 +889,6 @@ public void testDocValueFields() throws Exception {
assertThat(searchResponse.getHits().getAt(0).getFields().get("binary_field").getValue(), equalTo("KmQ"));
assertThat(searchResponse.getHits().getAt(0).getFields().get("ip_field").getValue(), equalTo("::1"));

builder = client().prepareSearch().setQuery(matchAllQuery())
.addDocValueField("text_field", "use_field_mapping")
.addDocValueField("keyword_field", "use_field_mapping")
.addDocValueField("byte_field", "use_field_mapping")
.addDocValueField("short_field", "use_field_mapping")
.addDocValueField("integer_field", "use_field_mapping")
.addDocValueField("long_field", "use_field_mapping")
.addDocValueField("float_field", "use_field_mapping")
.addDocValueField("double_field", "use_field_mapping")
.addDocValueField("date_field", "use_field_mapping")
.addDocValueField("boolean_field", "use_field_mapping")
.addDocValueField("binary_field", "use_field_mapping")
.addDocValueField("ip_field", "use_field_mapping");
searchResponse = builder.get();

assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
assertThat(searchResponse.getHits().getHits().length, equalTo(1));
fields = new HashSet<>(searchResponse.getHits().getAt(0).getFields().keySet());
assertThat(fields, equalTo(newHashSet("byte_field", "short_field", "integer_field", "long_field",
"float_field", "double_field", "date_field", "boolean_field", "text_field", "keyword_field",
"binary_field", "ip_field")));

assertThat(searchResponse.getHits().getAt(0).getFields().get("byte_field").getValue().toString(), equalTo("1"));
assertThat(searchResponse.getHits().getAt(0).getFields().get("short_field").getValue().toString(), equalTo("2"));
assertThat(searchResponse.getHits().getAt(0).getFields().get("integer_field").getValue(), equalTo((Object) 3L));
assertThat(searchResponse.getHits().getAt(0).getFields().get("long_field").getValue(), equalTo((Object) 4L));
assertThat(searchResponse.getHits().getAt(0).getFields().get("float_field").getValue(), equalTo((Object) 5.0));
assertThat(searchResponse.getHits().getAt(0).getFields().get("double_field").getValue(), equalTo((Object) 6.0d));
assertThat(searchResponse.getHits().getAt(0).getFields().get("date_field").getValue(),
equalTo(DateFormatter.forPattern("dateOptionalTime").format(date)));
assertThat(searchResponse.getHits().getAt(0).getFields().get("boolean_field").getValue(), equalTo((Object) true));
assertThat(searchResponse.getHits().getAt(0).getFields().get("text_field").getValue(), equalTo("foo"));
assertThat(searchResponse.getHits().getAt(0).getFields().get("keyword_field").getValue(), equalTo("foo"));
assertThat(searchResponse.getHits().getAt(0).getFields().get("binary_field").getValue(), equalTo("KmQ"));
assertThat(searchResponse.getHits().getAt(0).getFields().get("ip_field").getValue(), equalTo("::1"));

builder = client().prepareSearch().setQuery(matchAllQuery())
.addDocValueField("byte_field", "#.0")
.addDocValueField("short_field", "#.0")
Expand Down Expand Up @@ -1029,7 +993,7 @@ public void testDocValueFieldsWithFieldAlias() throws Exception {

SearchRequestBuilder builder = client().prepareSearch().setQuery(matchAllQuery())
.addDocValueField("text_field_alias")
.addDocValueField("date_field_alias", "use_field_mapping")
.addDocValueField("date_field_alias")
.addDocValueField("date_field");
SearchResponse searchResponse = builder.get();

Expand Down Expand Up @@ -1091,7 +1055,7 @@ public void testWildcardDocValueFieldsWithFieldAlias() throws Exception {
refresh("test");

SearchRequestBuilder builder = client().prepareSearch().setQuery(matchAllQuery())
.addDocValueField("*alias", "use_field_mapping")
.addDocValueField("*alias")
.addDocValueField("date_field");
SearchResponse searchResponse = builder.get();

Expand Down

0 comments on commit 724e24d

Please sign in to comment.