aws logo

AWS Elasticsearch: A beginners guide of how to index data.

AWS Elasticsearch Service makes it easy to deploy, operate, and scale Elasticsearch for log analytics, full text search and application monitoring

Prerequisites

  • Amazon AWS free tier account
  • Chrome browser
  • Sense (Beta) Chrome extension: A JSON aware interface to Elasticsearch

Create AWS Elasticsearch Domain

Open AWS Console and navigate to Analytics -> Elasticsearch service.

Click on “Create Domain” to create a domain. A wizard will walk you through the steps to create a domain.

Shop the best electronics products at yoshop.com! Enjoy free shipping and up to 69% OFF! Shop now!

You will be asked for a domain name, instance type, storage options and backup schedule. Choose your own index name. Choose “Allow open access to the domain” in the access policy tab. Your settings should look like this

aws elasticsearch settings confirm and create

The chosen access policy allows anyone to modify your elastic data, so this policy is strictly for learning purposes and not for any real data.

Now click on “Confirm and create”. After a few minutes your elastic cluster will be activated. Once your domain’s configuration state is “Active”, click on the domain name. The domain details are displayed here.

aws elasticsearch cluster details

 

SENSE(Beta)

Now open chrome and install the extension “Sense (Beta)”. Once installed open the Sense console by clicking on the green tree like icon on the top right corner of your browser.

sense beta editor

Copy the Endpoint url from Domain details in AWS Console and paste it in the field next to the Server label in Sense console.

Sense has a REST editor on the left and the results are displayed on the right section of the console.

Introducing FREE 2-Day Shipping at Walmart.com!

Now type “GET _cat” in the editor and click on the tiny green arrow button to execute the request. A successful response should display the cat api as shown in the above picture.

Great, now you can perform any kind of operation like index, map and search on your Elasticsearch instance.

Indexing on Elasticserch

There are many ways you can index your data, some common approaches are indexing by date, by region, by data-type and by dictionary words/ sentences.

Let us build a simple index based on all the user generated data on a particular day.

Example: User=”hemanthgunnam”, Date=”2017-03-19″

Elastic Index format: indexname/type/id (id is optional, a random id is generated if you don’t provide one)

So from the information in the above example your index name can be user-2017-03-19 or user20170319 and so on. You can create indexes on the fly by building the index name in your code while calling a REST request to Elasticsearch.

Your First Index

POST 2017-03-19/users/hemanthgunnam
{
   "category": "electronics",
   "clickedproductid": "1132423",
   "@timestamp":"2017-03-19T13:25:54Z"
}

Execute the above request to index your user data. In the above request url “2017-03-19” is your index name, “users” is the type field and mandatory. You cannot index your data without specifying the type. “hemanthgunnam” is the Id field.

sense beta ediotr with request response

Execute “GET _cat/indices” to view all of your indexs.

Replace POST with PUT in the above request to update existing data.

Searching

To retrieve the inserted data, elastic provides a Search API. Let us see two basic ways to retrieve elastic data.

Execute the request “GET 2017-03-19/users/_search ” as it is, to view all the users records under our index.

Execute the request “GET 2017-03-19/users/hemanthgunnam” to view all the data related to the user “hemanthgunnam” on this index.

For complex search queries and mappings visit
Elasticsearch Mappings. Please go to Indexing Strategies for strategies.