Error in Creating Elastic Config file - JAVA - Springboot

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

Welcome!

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

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

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

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

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

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

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

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

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?

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

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

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 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: )

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