A Basic CRUD Application Using ElasticSearch

Reading Time: 2 minutes

In our previous post Introduction To ElasticSearch, we talked about the basic terminology of elastic search and basic requests to create or delete an index, check the health status of the cluster, indices etc.

In this post, we are going to talk about creating a basic CRUD application using DSL. Without waiting let’s get started. To create an application, first, create an SBT Project, add elastic search dependency in build.sbt.

The Project has been set up. Next, we need a client which will talk to the elastic search server. There are various clients i.e rest high-level client, transport client etc. We will be using Java High-Level Rest Client as it is light weight. To use it we have to add the following dependency for it.

Let’s create a client

Now we have a client and can easily query the Elastic search server. Let’s create the first document of the books in the library.

Let’s index this document to elastic search

To delete the document by an id

To update any document.

To search the document by field. Let’s say title name

We are done with basic crud operations. We will see bulk requests, term query or different ways of query in ES and how we can tune our searching. For full code get it from here

Hope it will help. Please feel free to suggest or comment.

References:

Elastic Search Documentation


Knoldus-blog-footer-image

Written by 

I am a Software Consultant with experience of more than 1.5 years. I am a Functional Programing i.e Scala and Big Data technology enthusiast.I am a active blogger, love to travel, explore and a foodie.

Knoldus Pune Careers - Hiring Freshers

Get a head start on your career at Knoldus. Join us!