Skip to content

musaberatbahadir/ELK-for-IBM-Cloud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Perform CRUD operations with Compose for Elasticsearch

Elasticsearch is basically an analytics and full-text search engine. It's often used for enabling search functionality for applications. Besides providing lots of functionality and flexibility in regards to searching data, Elasticsearch is also highly scalable. IBM Compose for Elasticsearch makes Elasticsearch even better by managing it for you. This includes offering an easy, auto-scaling deployment system which delivers high availability and redundancy, automated no-stop backups and much more.

This tutorial will demonstrate how to perform Create, Read, Update and Delete operations with IBM Compose for Elasticsearch.

Table of Contents

  1. Introduction
  2. Prerequsites
    1. Download Postman
    2. A Billable account
  3. Steps
    1. Create an Elasticsearch service on IBM Cloud
    2. Get your Endpoint
    3. Put your Index
    4. Add a document to your index
    5. Add a document with id
    6. Get a document
    7. Update a document
    8. Delete a Document
  4. Conclusion

Prerequsites

1- Download Postman

Postman is a useful tool when trying to dissect RESTful APIs made by others or test ones you have made yourself. It offers a sleek user interface with which to make HTML requests, without the hassle of writing a bunch of code just to test an API's functionality.

Download it from here.

2- A Billable account

Unfortunately IBM Compose for Elasticsearch is not available for Lite Accounts, so you are not able to follow this guide with a Lite Account.

You can look at Billable Account types here.

Steps

1- Create an Elasticsearch service on IBM Cloud

After clicking the Catalog, you should select Data&Analystics from the menu on the left. Then you can select Compose for Elasticsearch service.

create_service

Before creating service, you should select a valid Region, Organization and Space.

2- Get your Endpoint

Your elasticsearch service will be hosted on yellow rectangular area. You will use this link as "yourlink" in the whole scenario.

copy_cred

3- Put your Index

Now you are finally ready to send your first request to the Elasticsearch cluster.

Open Postman application on your computer.

  1. Select "PUT" from request types.
  2. Paste your endpoint + indexname. It should be something like this: https://admin:HSYFMLSITJFLCHJS@portal-ddl888-8.bmix-dal-yp-123esed2-23ss-1111-333a-32352451.asdasda-us-ibm-com.composedb.com:12345/myindex
  3. You can send your request by clicking Send.
  4. When you select body,the result will be seen.

put_index

4- Add a document to your index

Now that you have an index, Let's add some some documents to it. You do that by sending a POST request to a URI consisting of index name, followed by a type. In this how-to our index name is "myindex" and type name is "default", that make the request URI "myindex/default".

  1. Select "POST" from request types and add your endpoint /myindex/default
  2. Select Body and choose Raw option to write your document.
  3. You should write a json document for adding to index. In the example document has been written like:
{
	"name": "Musa Berat Bahadir",
	"contents": {
		"topic": "Compose for Elasticsearch",
		"details": "CRUD operations"
	}
}

add_doc

  1. You can send your request and result will be shown when you click the Header on the left the Body.

add_doc_res

Since you did not identify an id, Elasticsearch gives your document a random id.

5- Add a document with id

For avoiding to automatically generated id, you should trace the steps below.

  1. You need to change the HTTP verb to PUT and specify the id.
  2. Again select Body and choose Raw option to write your document.
  3. You should write a json document for adding to index. In the example document has been written like:
{
	"name": "Musa Berat Bahadir 2",
	"contents": {
		"topic": "Compose for Elasticsearch",
		"details": "CRUD operations"
	}
}

add_doc_id

  1. You can send your request and result will be shown when you click the Header on the left the Body. add_doc_id

6- Get a document

Now, you have a couple of documents available within your index. For retrieving a document with id from your index:

  1. Select "GET" from request types and add your endpoint to /myindex/default/1 to URI area.
  2. Send your request.
  3. Click Header to see the result.

get_doc

7- Update a document

Instead of replacing the entire document, you can patch it by only specifying what you want.

  1. Select "POST" from request types and add your endpoint to /myindex/default/1/_update
  2. Select Body and choose Raw option to add your document.
  3. Update API expects a JSON object and within this object you should add a "doc" property, which itself should be an object. In the example document has been written like:
{
	"doc": {
		"name": "Unidentified Flying Object",
		"tags": ["Elasticsearch", "IBM Cloud"]
	}
}

Within this object you can specify the fields that you would like to change ("name") or you can also add new fields with this approach("tags").

  1. Now you can send your request.

updat_doc

  1. Click Headers to see the result.

update_doc_res

8- Delete a Document

Deleting document is easist operation in all.

  1. Select "DELETE" from request types and add your endpoint to /myindex/default/1
  2. Send your request then result will appear below.

delete_doc

Conclusion

At the end of this how-to, you created an index and learned CRUD operations in Elasticsearch without installation Elasticsearch locally.

For further, when you creating a Compose for Elasticsearch service, you are able to choose your Elasticsearch version and you are able to control your security with: SSL incoming connections with certificate confirmation, IP whitelisting, and mandatory creation of users with passwords ensure the Elasticsearch database.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published