GithubHelp home page GithubHelp logo

elk-for-ibm-cloud's Introduction

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.

elk-for-ibm-cloud's People

Contributors

musaberatbahadir avatar

Stargazers

Fergal Connolly avatar Erin McKean avatar Baris avatar Mehmet Aydin Bahadir avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.