Skip to content

Commit 04e4352

Browse files
committed
fix constant_keyword field type not working
Signed-off-by: kkewwei <kkewwei@163.com>
1 parent 501a702 commit 04e4352

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5555
- Fix file cache initialization ([#14004](https://github.com/opensearch-project/OpenSearch/pull/14004))
5656
- Handle NPE in GetResult if "found" field is missing ([#14552](https://github.com/opensearch-project/OpenSearch/pull/14552))
5757
- Refactoring FilterPath.parse by using an iterative approach ([#14200](https://github.com/opensearch-project/OpenSearch/pull/14200))
58+
- Fix constant_keyword field type not working ([#14651](https://github.com/opensearch-project/OpenSearch/pull/14651))
5859

5960
### Security
6061

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ private static ConstantKeywordFieldMapper toType(FieldMapper in) {
6868
*/
6969
public static class Builder extends ParametrizedFieldMapper.Builder {
7070

71-
private final Parameter<String> value;
71+
private final Parameter<String> value = Parameter.stringParam(valuePropertyName, false, m -> toType(m).value, null);
7272

7373
public Builder(String name, String value) {
7474
super(name);
75-
this.value = Parameter.stringParam(valuePropertyName, false, m -> toType(m).value, value);
75+
this.value.setValue(value);
7676
}
7777

7878
@Override

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ public void testMissingDefaultIndexMapper() throws Exception {
105105
assertThat(e.getMessage(), containsString("Field [field] is missing required parameter [value]"));
106106
}
107107

108+
public void testBuilderToXContent() throws IOException {
109+
ConstantKeywordFieldMapper.Builder builder = new ConstantKeywordFieldMapper.Builder("name", "value1");
110+
XContentBuilder xContentBuilder = JsonXContent.contentBuilder().startObject();
111+
builder.toXContent(xContentBuilder, false);
112+
xContentBuilder.endObject();
113+
assertEquals("{\"value\":\"value1\"}", xContentBuilder.toString());
114+
}
115+
108116
private final SourceToParse source(CheckedConsumer<XContentBuilder, IOException> build) throws IOException {
109117
XContentBuilder builder = JsonXContent.contentBuilder().startObject();
110118
build.accept(builder);

0 commit comments

Comments
 (0)