CRUD-operations-Elasticsearch

CRUD operations using Elasticsearch APIs

View project on GitHub

CRUD operations using Elasticsearch APIs

site

Launch Elasticsearch service

Open command prompt in administrative mode Type elasticsearch

In browser check this site: http://localhost:9200 or use curl

Check Elasticsearch

Check cluster heatlh status

GET /_cat/health?v&pretty

http://localhost:9200/_cat/health?v&pretty Check Elasticsearch

GET /_cat/nodes?v&pretty

http://localhost:9200/_cat/nodes?v&pretty Check nodes

Listing all indices

GET /_cat/indices?v&pretty http://localhost:9200/_cat/indices?v&pretty Check indices

Create an index (equivalent to creating a new database)

PUT /index-name

curl -XPUT "localhost:9200/products?&pretty"

Create index

Query a index/document

Apart from curl, you also use Postman or YARC for handling API request PUT /index-name/document-name/id

{ 
  “field”:”value”, 
    ... : ...
}

Id is optional, if not provided it will generate a unique id for this record YARC YARC

Fetching documents

GET /products/mobile/1

curl -GET "localhost:9200/products/mobiles/1?pretty" get documents

Getting partial documents

curl -GET "localhost:9200/products/mobiles/1?pretty&_source=false" get documents

curl -GET "localhost:9200/products/mobiles/1?pretty&_source=name,reviews" get documents

Updating documents

Updates using the _update API with “doc”

curl -XPOST -H "Content-Type: application/json" "localhost:9200/products/mobiles/2/_update?pretty" -d "{ \"doc\": { \"color\": \"black\"}}" update  update  update

Deletion

For deleting record

DELETE /index-name/document-name/id

curl -XDELETE "localhost:9200/products/mobiles/2?pretty" delete document record

For Removing index

DELETE /index-name

curl –XDELETE “localhost:9200/orders”

delete index