How to create index using json file?


How can I create an index using a json file ?

Below code is not creating mappings for me:

import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.opensearch._types.mapping.TypeMapping;

  public void createIndex() {
    try {
      JsonpMapper mapper = openSearchClient._transport().jsonpMapper();
      JsonParser parser = mapper.jsonProvider()
                                .createParser(new StringReader(Files.readString(Path.of(Objects.requireNonNull(getClass()

      CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(openSearchProperties.getIndexName())
                                                                              .mappings(TypeMapping._DESERIALIZER.deserialize(parser, mapper))
      CreateIndexResponse createIndexResponse = openSearchClient.indices().create(createIndexRequest);
      if (FALSE.equals(createIndexResponse.acknowledged())) {
        throw new RuntimeException("Create index response is not acknowledged");
    } catch (Exception ex) {
      throw new RuntimeException("Failed to create index");

Can you share more about what the inputs look like and what errors you are getting? Also, what versions of client and server you are using.