When linking ElasticSearch from JAVA, you can easily operate it by using ElasticSearch Rest High Level Client library. https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high.html
Find the version from the MVN repository and copy the Gradle description.
Example:
// https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-high-level-client
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '7.3.1'
//Index key
String blogId = "xxxx";
//Index data (example created with MongoDB Document)
Document document = new Document();
document.put("title", "first blog");
document.put("body", "xxxxx");
//New INDEX
IndexRequest upsertRequest = new IndexRequest("blogs");
upsertRequest.source(document, XContentType.JSON);
upsertRequest.id(blogId);
//Update INDEX
UpdateRequest updateRequest = new UpdateRequest("blogs", blogId);
updateRequest.upsert(upsertRequest);
updateRequest.doc(document, XContentType.JSON);
//Client generation
RestHighLevelClient esClient = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));
//Introduced to ElasticSearch
esClient.update(updateRequest, RequestOptions.DEFAULT);
//Close client
esClient.close();
The above is a sample of new and updated. GET:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-get.html Exists:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-exists.html Delete:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-delete.html Search:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_search_apis.html
that's all
Recommended Posts