This Blog will help us to know how to do CRUD operation using ES 5.4 and Java 1.8

1) Download ES- 5.4.2 :  https://www.elastic.co/downloads/elasticsearch and unzip
2) Install Xpack

a) Goto C:\Subhasish\elasticsearch-5.4.2\elasticsearch-5.4.2\bin

xpack-installation

b) elasticsearch-plugin install x-pack ( press enter)

Continute twice with Y option

Continue with installation? [y/N]y
Continue with installation? [y/N]y

3) Install Java 1.8

4) Make the following changes in elasticsearch.yml file
cluster.name: my-application
xpack.security.transport.filter.allow: 127.0.0.1
xpack.security.enabled: false
xpack.security.transport.ssl.enabled: false
xpack.security.http.ssl.enabled: false

5) Create a maven project or include the following jar in build path

es_jars

6) Create a Java client class :  ElasticSearchClient.java

7) Create a TransportClient  connects remotely to an Elasticsearch cluster using the transport module

Settings settings =Settings.builder().put(“cluster.name”, “my-application”).build();

TransportClient  client = new PreBuiltTransportClient(settings) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(“127.0.0.1”), 9300));

Note : If you dont specify any customized cluster name in your yml file then use “elasticsearch”  instead of  ” my-application” in above code.

Use port 9300 instead of 9200 ( default port used in ES) when you are connecting through TCP

CRUD OPERATIONS:

a) C-Create

create_index

b) R- read

Get API – allows you to get a typed JSON document, based on the ID, from the index.

read

Search API

search

c) U- Update

Note: if field does not exists then it will create a new one

update

d) D -Delete

Note: After deletion you will status as “Not Found”

delete

Full code:

ElasticSearchClient

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s