Coming to the Elasticsearch Version, Refer this site:
https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#preface.versions
For using Elasticsearch with SpringBoot, we include three dependencies:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-high-level-client -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
As You can see My Elasticsearch Version is 6.2.2(to match the server side version) and my Spring Version is 2.1.13.RELEASE.
There are basically 2 Clients used. I would suggest you to use Rest High Level Client. The other one is Transport Client.
Here is a how you can integrate Rest High Level Client to your application:
@Configuration
public class ElasticClientService extends AbstractElasticsearchConfiguration {
@Override
@Bean
public RestHighLevelClient elasticsearchClient() {
final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo("localhost:9200").build();
return RestClients.create(clientConfiguration).rest();
}
}
Once the client is created, only thing left is to perform CRUD operations.
@Autowired
ElasticClientService client;
public void save(Object object, String id, String type, String indexName) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> objectMap = objectMapper.convertValue(object, Map.class);
IndexRequest indexRequest = new IndexRequest(indexName, type, id);
indexRequest.source(objectMap);
IndexResponse response = client.elasticsearchClient().index(indexRequest);
}
public void deleteById(String id, String type, String indexName) throws IOException {
DeleteRequest request = new DeleteRequest(indexName, type, id);
DeleteResponse deleteResponse = client.elasticsearchClient().delete(request);
}
The above two operations create a Document(row) in elastic index and delete a document(row) from elastic index according to ID.
For more reference See :https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.2/java-rest-high-document-delete.html *
*Change Version According to your need
You could Refer this for further assistance