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

**URL:** https://discuss.elastic.co/t/how-to-get-mappingmetadata-per-type-using-rest-high-level-client/257082
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [November 30, 2020, 2:42pm UTC](https://discuss.elastic.co/t/how-to-get-mappingmetadata-per-type-using-rest-high-level-client/257082 "2020-11-30T14:42:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![amishar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amishar/32/76363_2.png) [@amishar](https://discuss.elastic.co/u/amishar)
#### Post date: [November 30, 2020, 2:42pm UTC](https://discuss.elastic.co/t/how-to-get-mappingmetadata-per-type-using-rest-high-level-client/257082/1 "2020-11-30T14:42:11Z")

</div>

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:

```auto
        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 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:

```auto
        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`

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [November 30, 2020, 2:52pm UTC](https://discuss.elastic.co/t/how-to-get-mappingmetadata-per-type-using-rest-high-level-client/257082/2 "2020-11-30T14:52:09Z")

</div>

> [@amishar](#):
>
> For a given index, there could be multiple `MappingMetadata` one each for a type.

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

---

<div class="post-metadata">

### Author: ![amishar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amishar/32/76363_2.png) [@amishar](https://discuss.elastic.co/u/amishar)
#### Post date: [November 30, 2020, 3:11pm UTC](https://discuss.elastic.co/t/how-to-get-mappingmetadata-per-type-using-rest-high-level-client/257082/3 "2020-11-30T15:11:06Z")

</div>

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>>`

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [November 30, 2020, 3:31pm UTC](https://discuss.elastic.co/t/how-to-get-mappingmetadata-per-type-using-rest-high-level-client/257082/4 "2020-11-30T15:31:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [December 28, 2020, 3:31pm UTC](https://discuss.elastic.co/t/how-to-get-mappingmetadata-per-type-using-rest-high-level-client/257082/5 "2020-12-28T15:31:51Z")

</div>

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