Skip to content

Commit

Permalink
fix constant_keyword field type not working
Browse files Browse the repository at this point in the history
  • Loading branch information
kkewwei committed Jul 4, 2024
1 parent 501a702 commit 4abd9ae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix file cache initialization ([#14004](https://github.com/opensearch-project/OpenSearch/pull/14004))
- Handle NPE in GetResult if "found" field is missing ([#14552](https://github.com/opensearch-project/OpenSearch/pull/14552))
- Refactoring FilterPath.parse by using an iterative approach ([#14200](https://github.com/opensearch-project/OpenSearch/pull/14200))
- Fix constant_keyword field type not working ([#14651](https://github.com/opensearch-project/OpenSearch/pull/14651))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ private static ConstantKeywordFieldMapper toType(FieldMapper in) {
*/
public static class Builder extends ParametrizedFieldMapper.Builder {

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

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public void testMissingDefaultIndexMapper() throws Exception {
assertThat(e.getMessage(), containsString("Field [field] is missing required parameter [value]"));
}

public void testBuilderToXContent() throws IOException {
ConstantKeywordFieldMapper.Builder builder = new ConstantKeywordFieldMapper.Builder("name", "value1");
XContentBuilder xContentBuilder = JsonXContent.contentBuilder().startObject();
builder.toXContent(xContentBuilder, false);
xContentBuilder.endObject();
assertEquals("{\"value\":\"value1\"}", xContentBuilder.toString());
}

private final SourceToParse source(CheckedConsumer<XContentBuilder, IOException> build) throws IOException {
XContentBuilder builder = JsonXContent.contentBuilder().startObject();
build.accept(builder);
Expand Down

0 comments on commit 4abd9ae

Please sign in to comment.