Skip to content

Commit 000e887

Browse files
committed
Change the default value of doc_values in WildcardFieldMapper to true
Signed-off-by: kkewwei <kewei.11@bytedance.com> Signed-off-by: kkewwei <kkewwei@163.com>
1 parent 09b3b96 commit 000e887

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3131
- Refactor the ThreadPoolStats.Stats class to use the Builder pattern instead of constructors ([#19317](https://github.com/opensearch-project/OpenSearch/pull/19317))
3232
- Refactor the IndexingStats.Stats class to use the Builder pattern instead of constructors ([#19306](https://github.com/opensearch-project/OpenSearch/pull/19306))
3333
- Remove FeatureFlag.MERGED_SEGMENT_WARMER_EXPERIMENTAL_FLAG. ([#19715](https://github.com/opensearch-project/OpenSearch/pull/19715))
34-
-
34+
- Change the default value of doc_values in WildcardFieldMapper to true. ([#19722](https://github.com/opensearch-project/OpenSearch/pull/19722))
35+
3536
### Fixed
3637
- Fix Allocation and Rebalance Constraints of WeightFunction are incorrectly reset ([#19012](https://github.com/opensearch-project/OpenSearch/pull/19012))
3738
- Fix flaky test FieldDataLoadingIT.testIndicesFieldDataCacheSizeSetting ([#19571](https://github.com/opensearch-project/OpenSearch/pull/19571))

rest-api-spec/src/main/resources/rest-api-spec/test/search/270_wildcard_fieldtype_queries.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ setup:
1919
type: wildcard
2020
doc_values: true
2121

22+
- do:
23+
indices.create:
24+
index: test1
25+
body:
26+
mappings:
27+
properties:
28+
my_field:
29+
type: wildcard
30+
2231
- do:
2332
index:
2433
index: test
@@ -78,6 +87,15 @@ setup:
7887
- do:
7988
indices.refresh: {}
8089

90+
---
91+
# Verify that mappings doc_values is stored.
92+
"Mappings":
93+
- do:
94+
indices.get_mapping:
95+
index: test1
96+
- is_true: test1.mappings
97+
- match: { test1.mappings.properties.my_field.doc_values: true }
98+
8199
---
82100
"term query matches exact value":
83101
- do:

server/src/main/java/org/opensearch/index/mapper/WildcardFieldMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static final class Builder extends ParametrizedFieldMapper.Builder {
102102
);
103103
private final Parameter<String> normalizer = Parameter.stringParam("normalizer", false, m -> toType(m).normalizerName, "default");
104104
private final Parameter<Map<String, String>> meta = Parameter.metaParam();
105-
private final Parameter<Boolean> hasDocValues = Parameter.docValuesParam(m -> toType(m).hasDocValues, false).alwaysSerialize();
105+
private final Parameter<Boolean> hasDocValues = Parameter.docValuesParam(m -> toType(m).hasDocValues, true).alwaysSerialize();
106106
private final IndexAnalyzers indexAnalyzers;
107107

108108
public Builder(String name, IndexAnalyzers indexAnalyzers) {
@@ -328,7 +328,7 @@ public ValueFetcher valueFetcher(QueryShardContext context, SearchLookup searchL
328328
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't " + "support formats.");
329329
}
330330

331-
if (hasDocValues()) {
331+
if (hasDocValues() && searchLookup != null) {
332332
return new DocValueFetcher(DocValueFormat.RAW, searchLookup.doc().getForField(this));
333333
}
334334

server/src/test/java/org/opensearch/index/mapper/WildcardFieldMapperTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,16 @@ public void testEnableDocValues() throws IOException {
128128
assertEquals(DocValuesType.NONE, fields[0].fieldType().docValuesType());
129129
assertEquals(DocValuesType.SORTED_SET, fields[1].fieldType().docValuesType());
130130

131+
// doc_values is true by default
131132
mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "wildcard")));
132133
doc = mapper.parse(source(b -> b.field("field", "1234")));
133134
fields = doc.rootDoc().getFields("field");
135+
assertEquals(2, fields.length);
136+
assertEquals(DocValuesType.NONE, fields[0].fieldType().docValuesType());
137+
138+
mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "wildcard").field("doc_values", false)));
139+
doc = mapper.parse(source(b -> b.field("field", "1234")));
140+
fields = doc.rootDoc().getFields("field");
134141
assertEquals(1, fields.length);
135142
assertEquals(DocValuesType.NONE, fields[0].fieldType().docValuesType());
136143
}

0 commit comments

Comments
 (0)