How to get MappingMetadata per type using Rest High Level Client?

We are migrating from Transport Client to High Level Rest Client. We have a piece of code that get indices, mappings and settings using GetIndex call.

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

        GetIndexResponse response = client.get()
                .setFeatures(GetIndexRequest.Feature.MAPPINGS, GetIndexRequest.Feature.SETTINGS)

The response mappings field is a ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>>
But for rest high level client, the mappings field is a Map<String, MappingMetadata>.

For a given index, there could be multiple MappingMetadata one each for a type. In transport client, this is represented as ImmutableOpenMap<String, MappingMetaData>> where key is type and value is the metadata. But in rest high level client, it only return a MappingMetadata per Index. How do I get mapping metadata per type?

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);
        } 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

What version are you using? Support for multiple mapping types was removed in 6.0.


We are using 6.8. I see so when we use TransportClient, it is safe to assume that the Map per index in the response will only have one entry. Client response object is not changed may be because of backward compatibility reasons?
The mappings field in org.elasticsearch.action.admin.indices.get.GetIndexResponse should probably be ImmutableOpenMap<String, MappingMetaData> instead of ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>>

In theory in 6.8 you could still have some indices created in 5.6 (e.g. you just upgraded) which are allowed to have multiple mapping types. This isn't reflected in the REST client API because it's such a corner case, and you can always drop to the low-level REST client if you really need to.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.