# Error in Creating Elastic Config file - JAVA - Springboot

**URL:** <https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542>\
**Category:** Elasticsearch\
**Created:** [April 1, 2024, 10:40am UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542 "2024-04-01T10:40:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Priyam\_Omer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priyam_omer/32/133157_2.png) [@Priyam\_Omer](https://discuss.elastic.co/u/Priyam_Omer)\
**Post date:** [April 1, 2024, 10:40am UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/1 "2024-04-01T10:40:46Z")

</div>

```auto
package com.example.springbootelasticseach;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.support.HttpHeaders;

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.example.springbootelasticseach")
public class ElasticSearchConfig extends ElasticsearchConfiguration {

    @Override
    public ClientConfiguration clientConfiguration() {

        return ClientConfiguration.builder()
                .connectedTo("aws_domain:443").
                withBasicAuth("user","password")
                .withHeaders(() -> {
                    HttpHeaders headers = new HttpHeaders();
                    headers.add("Content-type", "application/json");
                    headers.add("Accept","application/json");
                    return headers;
                })
                .build();
    }
}

```

I am getting error in above code when trying to connect to the aws domain  
as Excepting JSON data but repsones content type is text/html please guide me how to correct this in my Elasticsearch config (above)  
node:aws\_domain, status: 400, [es/indices.create] Expecting JSON data but response content-type is: text/html

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 1, 2024, 11:42am UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/2 "2024-04-01T11:42:30Z")

</div>

Welcome!

What is your Elasticsearch version and where is it running?  
And what are the spring versions?

---

<div class="post-metadata">

**Author:** ![Priyam\_Omer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priyam_omer/32/133157_2.png) [@Priyam\_Omer](https://discuss.elastic.co/u/Priyam_Omer)\
**Post date:** [April 1, 2024, 12:18pm UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/3 "2024-04-01T12:18:32Z")

</div>

Spring version : 3.2.4  
Elastic search : 7.1 (AWS)  
Futher, Here is the Dependency package (pox.xml)

```auto
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>SpringBootElasticSeach</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>SpringBootElasticSeach</name>
    <description>SpringBootElasticSeach</description>
    <properties>
        <java.version>21</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>

        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.16.1</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>2.4.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.17.0</version>
        </dependency>

        <!-- <dependency>-->
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
<!-- <artifactId>jackson-databind</artifactId>-->
<!-- <version>2.5.2</version>-->
<!-- </dependency>-->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 1, 2024, 12:52pm UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/4 "2024-04-01T12:52:09Z")

</div>

You need to use the same version for the client and the server.

And I'd recommend using Elasticsearch 7.17.x at least.

---

<div class="post-metadata">

**Author:** ![Priyam\_Omer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priyam_omer/32/133157_2.png) [@Priyam\_Omer](https://discuss.elastic.co/u/Priyam_Omer)\
**Post date:** [April 1, 2024, 1:31pm UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/5 "2024-04-01T13:31:58Z")

</div>

Ok will try that I also think that could be problem as using Elasticsearch 7.17 locally there is no such problem

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 1, 2024, 3:11pm UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/6 "2024-04-01T15:11:09Z")

</div>

Upgrade your cluster to 7.17 and then we can iterate from there.  
And while you are at it, switch to the new client.

> **[Switching from the Java High Level Rest Client to the new Java API Client](https://www.elastic.co/blog/switching-from-the-java-high-level-rest-client-to-the-new-java-api-client)**
>
> Let's say you have a Java project using Elastic 7.17 and the deprecated High Level Rest Client (HLRC). You have been asked to switch to Elastic 8.11 but the HLRC does not exist for this version. This ...

---

<div class="post-metadata">

**Author:** ![Yusuf\_Musa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yusuf_musa/32/130285_2.png) [@Yusuf\_Musa](https://discuss.elastic.co/u/Yusuf_Musa)\
**Post date:** [April 27, 2024, 1:49pm UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/7 "2024-04-27T13:49:51Z")

</div>

You found a fix please? I've traveled searching the whole Internet, I couldn't find a fix.

Local works fine but connecting to AWS ES is no chance. I appreciate if you've a solution

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 27, 2024, 2:56pm UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/8 "2024-04-27T14:56:18Z")

</div>

Elasticsearch does not respond with any HTML messages, so if you are getting that there must be a proxy in place between you and Elasticsearch. If you are using an AWS managed service they control the proxies but also use non-standard builds and plugins, so there is nothing we can help with here. You will need to contact AWS support.

Elastic does offer a Elasticsearch as a hosted service that as far as I know do not suffer from this issue and has the very latest versions. Have you looked at [Elastic Cloud](https://www.elastic.co/cloud)?

---

<div class="post-metadata">

**Author:** ![Priyam\_Omer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priyam_omer/32/133157_2.png) [@Priyam\_Omer](https://discuss.elastic.co/u/Priyam_Omer)\
**Post date:** [April 27, 2024, 3:56pm UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/9 "2024-04-27T15:56:42Z")

</div>

I had solved the problem by changing the versions there is version mismatch between what the AWS support and what Elasticsearch Dependency has been added

---

<div class="post-metadata">

**Author:** ![Yusuf\_Musa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yusuf_musa/32/130285_2.png) [@Yusuf\_Musa](https://discuss.elastic.co/u/Yusuf_Musa)\
**Post date:** [April 27, 2024, 10:05pm UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/10 "2024-04-27T22:05:31Z")

</div>

I thought of that. It didn't work for me.

This article would help and it means you can even use the latest Spring Data Elasticsearch dependency and it works. You have to use Google Translate, it is a Korean Developer blog.

flambeeyoga(dot)tistory(dot)com/entry/Spring-elasticsearch-rest-client-853%EC%97%90-opensearch-%EC%97%B0%EA%B2%B0%ED%95%98%EA%B8%B0

---

<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:** [April 27, 2024, 10:05pm UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/11 "2024-04-27T22:05:31Z")

</div>

OpenSearch/OpenDistro are AWS run products and differ from the original Elasticsearch and Kibana products that Elastic builds and maintains. You may need to contact them directly for further assistance. See [What is OpenSearch and the OpenSearch Dashboard? | Elastic](https://www.elastic.co/elasticsearch/opensearch) for more details.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

---

<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:** [May 25, 2024, 10:05pm UTC](https://discuss.elastic.co/t/error-in-creating-elastic-config-file-java-springboot/356542/12 "2024-05-25T22:05:40Z")

</div>

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