Handling Mappings when migrating Get Index call from Transport client to Rest High Level Client

182 views Asked by At

We are migrating from Transport Client to High Level Rest Client. How do we reconcile the difference in the mappings field of GetIndexResponse object returned from Transport client vs Rest High Level Client?

For transport client, we use this code to obtain the index information:

        GetIndexResponse response = client.get()
                .admin()
                .indices()
                .prepareGetIndex()
                .setFeatures(GetIndexRequest.Feature.MAPPINGS, GetIndexRequest.Feature.SETTINGS)
                .setIndices(indices)
                .get();

The response mappings field is a ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> But for rest high level client, the mappings field is just a Map<String, MappingMetadata>. Here is the code for High Level Rest Client:

        GetIndexRequest request = new GetIndexRequest(indices);
        request.addFeatures(GetIndexRequest.Feature.MAPPINGS, GetIndexRequest.Feature.SETTINGS);
        try {
            GetIndexResponse response = esClient.indices().get(request, RequestOptions.DEFAULT);
            return
        } catch (IOException ex) {
            throw new SafeRuntimeException(ex);
        }
    }

These are the response object classes: Transport Client: org.elasticsearch.action.admin.indices.get.GetIndexResponse Rest High Level Client: org.elasticsearch.client.indices.GetIndexResponse

1

There are 1 answers

2
Tom Elias On

for mappings use the GetMappings request:

ImmutableOpenMap<String, ?> mappings = esclient.admin().indices().getMappings(new GetMappingsRequest()).actionGet().getMappings();

and you can also specify the indices you want.

EDIT: ah i see, you mean this:

client.indices().getMapping(new GetMappingsRequest().indices("index_name1", "index_name2"), RequestOptions.DEFAULT);
client.indices().getSettings(new GetSettingsRequest().indices("index_name1", "index_name2"), RequestOptions.DEFAULT);

when "client" is an instance of the High level REST client.