SpringDataElasticsearch Queries

Add only spring-data-elasticsearch dependency
--------------------Model----------

public class ArunOrder {
    @Id
    private Integer id;

    private Integer userId;
    private String description;

    private Boolean hidden;

    @Field(type = FieldType.Date)
    private Long createdDate;

 @Field(type = FieldType.Date)
    private Long updatedDate;

//getter and setter
}

------------------Repository--------------
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MyOrderElastricSearchRepository extends ElasticsearchRepository<ArunOrder , Integer> {

//Search a text in order description any where
    List<ArunOrder> findByDescriptionContaining(String subject);


//Search a text in description for order of particular user only 
  List<ArunOrder> findByDescriptionContainingAndUserId(String subject, Integer userId);


//Search a text in description for visible order of particular user only 
  List<ArunOrder> findByDescriptionContainingAndUserIdAndHiddenFalse
(String subject, Integer userId);
   }


//Search a text in description for visible messages of particular user only and sort by created date
  List<ArunOrder> findByDescriptionContainingAndUserIdAndHiddenFalseOrderByCreatedDateDesc
(String subject, Integer userId);
   }

Application.yml and jars required for SpringBoot 2.4 + with Elasticsearch 7.1 +

Build.Gradle

ext {
    springBootVersion = '2.5.0'
}

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web') {
      exclude module: "spring-boot-starter-tomcat"
    }

implementation ('org.springframework.data:spring-data-elasticsearch')

}

application.yml

elasticsearch:
  rest:
    uris: http://localhost:9200

or with username and password
elasticsearch:
  rest:
    uris: https://MyHost:9200
    username: arun
    password: mypassword

Elasticsearch Java Config

package com.arun.config;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.arun.elasticsearch.repository")
@ComponentScan(basePackages = { "com.arun.elasticsearch.service" })
public class ElasticSearchConfig {
    private static final String HOST = "aws_host";//localhost
    private static final int PORT = 443;/9092
    private static final String PROTOCOL = "https";//http

    @Bean
    public RestHighLevelClient client() {
       final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("UserName", "Password"));

        RestClientBuilder builder = RestClient.builder(new HttpHost( HOST, PORT, PROTOCOL))
                .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                    @Override
                    public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                        return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                    }
                });

       
    }

}