Use Elasticsearch REST Client instead of Node client.

Closes #610
Original pull request: #612.
This commit is contained in:
Prakhar Gupta
2021-04-09 16:42:47 +05:30
committed by Mark Paluch
parent d70804b15c
commit aa95ff65a8
13 changed files with 17 additions and 330 deletions

View File

@@ -1,8 +1,5 @@
# Spring Data Elasticsearch - Examples
**NOTE**: Elastic recommends usage of the [High Level REST Client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high.html). Please check out the [rest](https://github.com/spring-projects/spring-data-examples/tree/master/elasticsearch/rest) example.
Requirements:
* [Maven](http://maven.apache.org/download.cgi) - required.

View File

@@ -5,7 +5,7 @@
<artifactId>spring-data-elasticsearch-example</artifactId>
<name>Spring Data Elasticsearch - Node Client Example</name>
<name>Spring Data Elasticsearch - High Level REST Client Example</name>
<description>Sample projects for Spring Data Elasticsearch</description>
<url>https://github.com/spring-projects/spring-data-elasticsearch</url>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020 the original author or authors.
* Copyright 2020-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,25 +16,20 @@
package example.springdata.elasticsearch.conference;
import java.util.Arrays;
import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.elasticsearch.client.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
/**
* @author Artur Konczak
* @author Oliver Gierke
* @author Christoph Strobl
* @author Prakhar Gupta
*/
@SpringBootApplication
class ApplicationConfiguration {
@@ -42,23 +37,6 @@ class ApplicationConfiguration {
@Autowired ElasticsearchOperations operations;
@Autowired ConferenceRepository repository;
@Bean
public NodeClientFactoryBean client() {
NodeClientFactoryBean bean = new NodeClientFactoryBean(true);
bean.setClusterName(UUID.randomUUID().toString());
bean.setEnableHttp(false);
bean.setPathData("target/elasticsearchTestData");
bean.setPathHome("src/test/resources/test-home-dir");
return bean;
}
@Bean
public ElasticsearchTemplate elasticsearchTemplate(Client client) {
return new ElasticsearchTemplate(client);
}
@PreDestroy
public void deleteIndex() {
operations.indexOps(Conference.class).delete();