Skip to main content

Getting Started With Elasticsearch


Elasticsearch is open source search system based of Apache Lucene. this is a brief introduction, you can find more information on Elasticsearch Official Site or  Wiki.

What are features of Elasticsearch?

Here are list of features of Elasticsearch.
  • Real Time Search and Analytic.
  • Distributed Data (Scales Horizontally) 
  • Based on Apache Lucene
  • High Availability
  • Full Text Search
  • JSON Based Documents
  • RESTful API
  • Multi Facets
  • Geo Location Search
  • Open Source

How to install ElasticSearch?


Download the latest version from elasticsearch.org/download.
Then unzip it or use following command in console to download Elasticsearch.

curl -L -O http://download.elasticsearch.org/PATH/TO/LATEST/$VERSION.zip
unzip elasticsearch-$VERSION.zip
cd  elasticsearch-$VERSION

Now move to unzip folder and run following command

{elasticsearch unzip folder path}/bin/elasticsearch

It will start Elasticsearch

How to use ElasticSearch?

To interactive with data using Elasticsearch we will use head plugin of Elasticsearch.

To install head plugin in your system run following command.

{elasticsearch unzip folder path}/bin/plugin --install mobz/elasticsearch-head

After successful installation open your favorite browser and  type following URL to use head plugin.


It will open head plugin user interface, now we can manipulate Elasticsearch records.

To start with data manipulation, first we need to create Index and Type.

Index acts as Database and Type as Table, therefore we can have multiple Type inside single Index.

First create new index, to create new index click button New Index from homepage of head plugin.




Then type name of index (for this blog we type "database" as Index and use Type as "Table") and click Ok.
It will create new index on Elasticsearch.

How to perform CRUD operation on Elasticsearch?

To perform CRUD operation on Elasticsearch select Any Request Tab
It will open user interface as shown below


There are several section defined in above image. lets see them one by one
  • Index: Index on which you want to perform action, it is located just after localhost:9200/
  • Type: Type within selected Index, it will come after Index value.
  • Action: which type of action you want to perform like search, mapping, etc.
  • Action Method: it is REST API action methods like POST, GET, PUT, DELETE.

Following is record or document structure that we are going to create.

{
   name : String,
   description: String,
   profile_image : String,
   birthdate : Date,
   address: String
}

Create Mapping:

First new need to define structure of data, by default it would be string for all fields but we can set different data type as date, geo point, etc.

To define mapping, select Index and Type, then type _mapping in Action area to perform mapping related tasks, then select Action Method as POST and type following mapping structure and click on Request button. 

{
  "table": {
   "properties":{
      "name": {"type" : "string"},
      "description": {"type" : "string"},
      "profile_image":{"type" : "string"},
      "birthdate":{"type" : "date"},
      "address":{"type" : "string"}
    }
  }
}

To ensure mapping is created , just change Action Method to GET and click Request button.



Create Record:

To create record on selected Index and Type, make Action  value empty 
and Action Method as POST after that add following JSON record.

{
  "name": "Zainul",
  "description" : "Software Developer",
  "birthdate": "1985-03-13T00:00:00",
  "profile_image" : "image1.png"
}

And click on Request button. It will index the one record.




Read Indexed Records:

To fetch indexed records from Elasticsearch, select Index and Type then Action as _search and Action Method as POST , make query body empty then click on Request button.
It will fetch 10 records from selected Index and Type.





Update Records:


To update value of name field, select Index and Type then Action as _update and Action Method as PUT and add following JSON record in query section then click on Request button.

{
 "script": "ctx._source.name=\"Zainul Abedin \""
}



to check record is updated or not, fire search query.


Delete Records:

To delete record from selected Index and Type, make Action value empty and select Action Method as DELETE and click on Request button.



This is a brief introduction to CRUD operations. in next blog post you will see how to access Elasticsearch via Java Client.

Comments

Subscribe for latest tutorial updates

* indicates required

Popular posts from this blog

Preload Images Using Javascript

Preload Image is technique which helps browser to render images with minimum delay. Today we will see example of image gallery. Gallery contain 5 images which load images one after another whenever user clicks next and back button. This is a basic image gallery scenario which is used in all possible website, then why we need preloaded images for this gallery? Now a day’s most of website becoming faster and user expectation is increasing. Suppose your website doesn’t use preload image technique for gallery and a user visits any image gallery from Google Plus or Facebook and visits your website gallery. Then that user always prefer those websites rather than yours. Why? Because your website load one image at a time. When user click on next button, then only gallery load image and user has wait till it get loaded. To avoid this situation gallery needs to download all images

Spring Boot RestTemplate Guide with Example

What is RestTemplet? RestTemplate is a HTTP Client library that provides basic APIs for executing different HTTP type requests. RestTemplate is one of the HTTP libraries available on the market. The Spring Boot team designed and maintains it. As previously said, it is a client library, which means it may be utilised in our application as a stand-alone dependency. To utilise it, you don't require a complete Spring boot application. It's suitable for use in simple Java applications as well as other frameworks such as Micronaut, Play and others. Setup Add RestTemplate dependency to project, for this tutorial I am creating a simple java application to consume HTTP request and a node application to provide HTTP service. For Gradle build tool Add the following dependency in the build.gradle file . // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web implementation group: 'org.springframework.boot' , name: 'spring-boot-starter-w

CSS: How To Create Custom Scrollbar For Webkit Supported Browsers

In this tutorial, we will learn how to create a custom scroll bar using custom CSS styles. Custom scrollbars are becoming increasingly popular, and I'm excited to learn more about them. A scrollbar can be customised for a variety of reasons. The default scrollbar, for example, can make an app's UI look inconsistent across various versions of windows, thus we can benefit from having a single style here. This tutorial will help to create a custom scrollbar. Let's see how One of the most interesting aspects of these scrollbars is that they may be rendered in a variety of styles for different HTML elements on the same webpage. We will see the implementation of such a scrollbar for Webkit-supported browsers. First we will look at the basic CSS properties of the scrollbar. ::-webkit-scrollbar              ::-webkit-scrollbar-thumb        ::-webkit-scrollbar-track        ::-webkit-scrollbar-button       ::-webkit-scrollbar-track-piece  ::-webkit-scrollbar-cor