# Elasticsearch 7.17 Java RestHighLevelClient to Elasticsearch 8.10.0 server communication issue

**URL:** https://discuss.elastic.co/t/elasticsearch-7-17-java-resthighlevelclient-to-elasticsearch-8-10-0-server-communication-issue/353048
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [February 12, 2024, 9:31am UTC](https://discuss.elastic.co/t/elasticsearch-7-17-java-resthighlevelclient-to-elasticsearch-8-10-0-server-communication-issue/353048 "2024-02-12T09:31:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Muthukumaran\_Kothand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muthukumaran_kothand/32/46017_2.png) [@Muthukumaran\_Kothand](https://discuss.elastic.co/u/Muthukumaran_Kothand)
#### Post date: [February 12, 2024, 9:31am UTC](https://discuss.elastic.co/t/elasticsearch-7-17-java-resthighlevelclient-to-elasticsearch-8-10-0-server-communication-issue/353048/1 "2024-02-12T09:31:51Z")

</div>

Hi,

Since we have a large Java Client codebase, our migration to 8.x Java Client would take time and as intermediary solution, we are constrained to use Elasticsearch 7.17.x client in combination with 8.10.0 server

I am trying to get Elasticsearch 7.17 Java RestHighLevelClient to talk to Elasticsearch 8.10.0 Server. As recommended by the document, I am using the `setApiCompatibility(true)` - [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-compatibility.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-compatibility.html)

Below is the code which I tried testing using

Client Libraries version 7.17.0  
Server Version 8.10.0

```auto
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.RestHighLevelClientBuilder;
import org.elasticsearch.xcontent.XContentType;

import java.io.IOException;

public class TestESPutMapping {

    public static void main(String[] args) {

        RestClient client1 = RestClient.builder(new HttpHost("localhost", 9200, "http")).build();
        RestHighLevelClient client = new RestHighLevelClientBuilder(client1).setApiCompatibilityMode(true).build();
        try {
            String indexName = "elasticsearch-sql_test_index_account";

            // Create mapping JSON
            String dataMapping = "{\n" +
                    " \"properties\": {\n" +
                    " \"gender\": {\n" +
                    " \"type\": \"text\"\n" +
                    " }," +
                    " \"address\": {\n" +
                    " \"type\": \"text\"\n" +
                    " }," +
                    " \"state\": {\n" +
                    " \"type\": \"text\"\n" +
                    " }" +
                    " }"+
                    " }";

            // Create put mapping request
            PutMappingRequest putMappingRequest = new PutMappingRequest(indexName)
                    .source(dataMapping, XContentType.JSON).type("_doc");
            // Update mapping
            AcknowledgedResponse putMappingResponse = client.indices().putMapping(putMappingRequest, RequestOptions.DEFAULT);
            boolean acknowledged = putMappingResponse.isAcknowledged();
            System.out.println("Mapping update acknowledged: " + acknowledged);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

```

With above code,

1. if I remove `.type("_doc")` in `PutMappingRequest`, I get below exception

```auto
Exception in thread "main" org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: mapping type is missing;
	at org.elasticsearch.action.ValidateActions.addValidationError(ValidateActions.java:15)
	at org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest.validate(PutMappingRequest.java:118)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:2133)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:2105)
	at org.elasticsearch.client.IndicesClient.putMapping(IndicesClient.java:490)
	at org.nlpcn.es4sql.TestESPutMapping.main(TestESPutMapping.java:43)

```

1. With same code if I retain `.type("_doc")` , I get below exception

```auto
Exception in thread "main" ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping: Root mapping definition has unsupported parameters: [address : {type=text}] [gender : {type=text}] [state : {type=text}]]]; nested: ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=Root mapping definition has unsupported parameters: [address : {type=text}] [gender : {type=text}] [state : {type=text}]]];
	at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:178)
	at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:2484)
	at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:2461)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:2184)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:2137)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:2105)
	at org.elasticsearch.client.IndicesClient.putMapping(IndicesClient.java:490)
	at org.nlpcn.es4sql.TestESPutMapping.main(TestESPutMapping.java:43)
	Suppressed: org.elasticsearch.client.ResponseException: method [PUT], host [http://localhost:9200], URI [/elasticsearch-sql_test_index_account/_mapping/_doc?master_timeout=30s&include_type_name=true&timeout=30s], status line [HTTP/1.1 400 Bad Request]
Warnings: [[types removal] Specifying types in put mapping request is deprecated. Use typeless api instead]

```

**Clarifications :**

1. Is `.type("_doc")` mandatory in above code
2. What is wrong with above simple mapping ? (formatted json as below to declutter escape chars)

```auto
{
  "properties": {
    "gender": {
      "type": "text"
    },
    "address": {
      "type": "text"
    },
    "state": {
      "type": "text"
    }
  }
}

```

Kindly let me know if I am missing something grossly.

Regards  
Muthu

---

<div class="post-metadata">

### Author: ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)
#### Post date: [February 13, 2024, 1:18am UTC](https://discuss.elastic.co/t/elasticsearch-7-17-java-resthighlevelclient-to-elasticsearch-8-10-0-server-communication-issue/353048/2 "2024-02-13T01:18:25Z")

</div>

> [@Muthukumaran\_Kothand](#):
>
> ```auto
> import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
> 
> ```

I believe you should be using `org.elasticsearch.client.indices.PutMappingRequest`

---

<div class="post-metadata">

### Author: ![Muthukumaran\_Kothand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muthukumaran_kothand/32/46017_2.png) [@Muthukumaran\_Kothand](https://discuss.elastic.co/u/Muthukumaran_Kothand)
#### Post date: [February 14, 2024, 9:16am UTC](https://discuss.elastic.co/t/elasticsearch-7-17-java-resthighlevelclient-to-elasticsearch-8-10-0-server-communication-issue/353048/3 "2024-02-14T09:16:41Z")

</div>

Thanks a lot @TimV , that fixed the issue ! Will mark as solution.

---

<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: [March 13, 2024, 9:17am UTC](https://discuss.elastic.co/t/elasticsearch-7-17-java-resthighlevelclient-to-elasticsearch-8-10-0-server-communication-issue/353048/4 "2024-03-13T09:17:21Z")

</div>

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