0

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 Answers1

0

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.

Tom Elias
  • 751
  • 6
  • 15
  • This looks like a call through `TransportClient` which we are migrating away from. Also, We need to get both settings, mappings for a specific set of indices using the new High Level Rest Client. – Amit Sharma Nov 30 '20 at 11:36
  • See the return type of these seemingly similar calls(One is Map<> other is Map>): Transport Client: ```ImmutableOpenMap> mappings = esclient.admin().indices().getMappings(new GetMappingsRequest()).actionGet().getMappings();``` vs Rest Client : ```Map mappings = client.indices().getMapping(new GetMappingsRequest(), RequestOptions.DEFAULT).mappings();``` – Amit Sharma Nov 30 '20 at 14:04