Creating ElasticSearch index from Java

Introduction

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

Library introduction

Find the version from the MVN repository and copy the Gradle description. image.png

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 creation summary example

//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();

Other

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

Creating ElasticSearch index from Java
[JAWS-UG CLI] CodeBuild: # 1 Creating Source Code (Java)
Creating ElasticSearch index from Java
Call Java from JRuby
Eval Java source from Java
Access API.AI from Java
From Java to Ruby !!
Migration from Cobol to JAVA
Java starting from beginner, override
New features from Java7 to Java8
Try creating APNG from JavaFX
Connect from Java to PostgreSQL
Java, instance starting from beginner
Java starting from beginner, inheritance
Java life starting from scratch
Using Docker from Java Gradle
From Ineffective Java to Effective Java
JavaScript as seen from Java
Execute non-Java instructions from Java
Call Kotlin's sealed class from Java
Java, abstract classes starting from beginners
Java learning memo (creating an array)
Code Java from Emacs with Eclim
Deep Learning Java from scratch 6.4 Regularization
Get country from IP address (Java)
Run node.js from android java (processing)
Run a batch file from Java
[Java] Remove whitespace from character strings
Akka hands-on preparation procedure from Java
Access Teradata from a Java application
Creating an Elasticsearch Plugin Series (2) Search
Use Chrome Headless from Selenium / Java
Java to be involved from today
From Java to VB.NET-Writing Contrast Memo-
Java overload constructor starting from beginner
Work with Google Sheets from Java
Java, interface to start from beginner
Creating lexical analysis in Java 8 (Part 2)
The road from JavaScript to Java
Reintroducing Java 8 available from Android Studio 2.4
Call TensorFlow Java API from Scala
[Java] Conversion from array to List
Sample code using Minio from Java
[Effective Java] Avoid creating unnecessary objects
Creating lexical analysis in Java 8 (Part 1)