Skip to content

Commit c3909bd

Browse files
committed
Improves doc values format deprecation message (#33576)
* Improves doc values format deprecation message This changes the deprecation message when doc values fields do not supply a format form logging a deprecation warning for each offending field individually to logging a single message which lists all offending fields Closes #33572 * Updates YAML test with new deprecation message Also adds a test to ensure multiple deprecation warnings are collated into one message * Condenses collection of fields without format check Moves the collection of fields that don't have a format to a separate loop and moves the logging of the deprecation warning to be next to it at the expesnse of looping through the field list twice * fixes typo * Fixes test
1 parent 46f309d commit c3909bd

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

rest-api-spec/src/main/resources/rest-api-spec/test/search/10_source_filtering.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,26 @@ setup:
139139
features: warnings
140140
- do:
141141
warnings:
142-
- 'Doc-value field [count] is not using a format. The output will change in 7.0 when doc value fields get formatted based on mappings by default. It is recommended to pass [format=use_field_mapping] with the doc value field in order to opt in for the future behaviour and ease the migration to 7.0.'
142+
- 'There are doc-value fields which are not using a format. The output will change in 7.0 when doc value fields get formatted based on mappings by default. It is recommended to pass [format=use_field_mapping] with a doc value field in order to opt in for the future behaviour and ease the migration to 7.0: [count]'
143143
search:
144144
body:
145145
docvalue_fields: [ "count" ]
146146
- match: { hits.hits.0.fields.count: [1] }
147147

148+
---
149+
"multiple docvalue_fields":
150+
- skip:
151+
version: " - 6.3.99"
152+
reason: format option was added in 6.4
153+
features: warnings
154+
- do:
155+
warnings:
156+
- 'There are doc-value fields which are not using a format. The output will change in 7.0 when doc value fields get formatted based on mappings by default. It is recommended to pass [format=use_field_mapping] with a doc value field in order to opt in for the future behaviour and ease the migration to 7.0: [count, include.field1.keyword]'
157+
search:
158+
body:
159+
docvalue_fields: [ "count", "include.field1.keyword" ]
160+
- match: { hits.hits.0.fields.count: [1] }
161+
148162
---
149163
"docvalue_fields as url param":
150164
- skip:
@@ -153,7 +167,7 @@ setup:
153167
features: warnings
154168
- do:
155169
warnings:
156-
- 'Doc-value field [count] is not using a format. The output will change in 7.0 when doc value fields get formatted based on mappings by default. It is recommended to pass [format=use_field_mapping] with the doc value field in order to opt in for the future behaviour and ease the migration to 7.0.'
170+
- 'There are doc-value fields which are not using a format. The output will change in 7.0 when doc value fields get formatted based on mappings by default. It is recommended to pass [format=use_field_mapping] with a doc value field in order to opt in for the future behaviour and ease the migration to 7.0: [count]'
157171
search:
158172
docvalue_fields: [ "count" ]
159173
- match: { hits.hits.0.fields.count: [1] }

server/src/main/java/org/elasticsearch/search/fetch/subphase/DocValueFieldsFetchSubPhase.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.HashMap;
4747
import java.util.List;
4848
import java.util.Objects;
49+
import java.util.stream.Collectors;
4950

5051
/**
5152
* Query sub phase which pulls data from doc values
@@ -77,17 +78,22 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOExcept
7778
hits = hits.clone(); // don't modify the incoming hits
7879
Arrays.sort(hits, Comparator.comparingInt(SearchHit::docId));
7980

81+
List<String> noFormatFields = context.docValueFieldsContext().fields().stream().filter(f -> f.format == null).map(f -> f.field)
82+
.collect(Collectors.toList());
83+
if (noFormatFields.isEmpty() == false) {
84+
DEPRECATION_LOGGER.deprecated("There are doc-value fields which are not using a format. The output will "
85+
+ "change in 7.0 when doc value fields get formatted based on mappings by default. It is recommended to pass "
86+
+ "[format={}] with a doc value field in order to opt in for the future behaviour and ease the migration to "
87+
+ "7.0: {}", DocValueFieldsContext.USE_DEFAULT_FORMAT, noFormatFields);
88+
}
89+
8090
for (FieldAndFormat fieldAndFormat : context.docValueFieldsContext().fields()) {
8191
String field = fieldAndFormat.field;
8292
MappedFieldType fieldType = context.mapperService().fullName(field);
8393
if (fieldType != null) {
8494
final IndexFieldData<?> indexFieldData = context.getForField(fieldType);
8595
final DocValueFormat format;
8696
if (fieldAndFormat.format == null) {
87-
DEPRECATION_LOGGER.deprecated("Doc-value field [" + fieldAndFormat.field + "] is not using a format. The output will " +
88-
"change in 7.0 when doc value fields get formatted based on mappings by default. It is recommended to pass " +
89-
"[format={}] with the doc value field in order to opt in for the future behaviour and ease the migration to " +
90-
"7.0.", DocValueFieldsContext.USE_DEFAULT_FORMAT);
9197
format = null;
9298
} else {
9399
String formatDesc = fieldAndFormat.format;

0 commit comments

Comments
 (0)