ElasticSearchRepository usage in java low level client

I am using 'elasticsearch-rest-client:8.3.3' to connect elasticsearch using java low level rest client. Is there a way to use ElasticsearchRepository (@Document annotation) when using low level rest client. I know it is possible when using High Level Rest Client as below

//Repository class

@Repository
public interface MessageRepository extends ElasticsearchRepository<DemoMessage, Long> {}

//Configuration class

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.demo.elasticsearch.repositories")
@ComponentScan(basePackages = {"com.demo.elasticsearch"})
public class ElasticSearchConfiguration  {

    @Bean
    public RestHighLevelClient elasticsearchClient() {...}

}

Thanks!

Repository comes from Spring Data Elasticsearch and not High Level Rest Client.

The Low Level Rest Client is – as its name implies – low level. So it only deals with raw http requests and responses. So no, no repository at that level.

So it is not possible to use spring-boot-starter-data-elasticsearch features when using low level rest client? Is there a way to send request like below using low level client.

 SearchResponse response = client.prepareSearch("kal").setTypes("products")
            .setSearchType(SearchType.DEFAULT)
            .setQuery(qb)
            .get();

I have been using below code for sending request.

Request req = new Request(HttpMethod.PUT.name(), MESSAGE_INDEX + "/_doc/" + message.getId());
            ObjectMapper mapper = new ObjectMapper();
            String jsonObj = mapper.writeValueAsString(message);
            req.setJsonEntity(jsonObj);
            Response resp = client.performRequest(req);

Thanks!!

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