Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mappings and settings with json #985

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.opensearch.client.opensearch.indices;

import jakarta.json.stream.JsonGenerator;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
Expand All @@ -43,6 +44,7 @@
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.opensearch._types.ErrorResponse;
import org.opensearch.client.opensearch._types.RequestBase;
import org.opensearch.client.opensearch._types.Time;
Expand Down Expand Up @@ -304,6 +306,25 @@ public final Builder mappings(@Nullable TypeMapping value) {
return this;
}

/**
* Mapping for fields in the index. If specified, this mapping can include:
* <ul>
* <li>Field names</li>
* <li>Field data types</li>
* <li>Mapping parameters</li>
* </ul>
* <p>
* API name: {@code mappings}
*/
public final Builder mappings(@Nullable String typeMappingJson) {
return this.mappings(deserialize(TypeMapping._DESERIALIZER, typeMappingJson));
}

private <T> T deserialize(JsonpDeserializer<T> deserializer, String json) {
JsonpMapper jsonpMapper = new JacksonJsonpMapper();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not going to work, the JsonpMapper is provided by the user when OpenSearchClient instance is created, it has to be respected.

return deserializer.deserialize(jsonpMapper.jsonProvider().createParser(new StringReader(json)), jsonpMapper);
}

/**
* Mapping for fields in the index. If specified, this mapping can include:
* <ul>
Expand Down Expand Up @@ -366,6 +387,13 @@ public final Builder settings(@Nullable IndexSettings value) {
return this;
}

/**
* API name: {@code settings}
*/
public final Builder settings(String indexSettingsJson) {
return this.settings(deserialize(IndexSettings._DESERIALIZER, indexSettingsJson));
}

/**
* API name: {@code settings}
*/
Expand Down
Loading