Indexing, Retrieving, Deleting Documents in Elastic Search (Using Kibana)


Indexing, Retrieving, Deleting Documents in Elastic Search (Using Kibana)

Elasticsearch (ELK Stack) – Part 1

I have been playing around with ELK (Elasticsearch, Logstash, Kibana – Elastic Stack) and I though I would paste some of my notes here.

The command below will index (insert) a car document (object/row)┬áinto “cars” type (table) inside “vehicles” index (database).

GET /vehicles/cars/1 — get the metadata and the indexed data for the document

GET /vehicles/cars/1/_source — get only the data that in indexed

HEAD /vehicles/cars/1/ — check if document exists

Documents are immutable so if we try the index the same document after changing a value it will not only update the changed field but re-index the whole document again. most granular level of operation is done on the document level.

“_update” endpoint

We can also use _update endpoint to update a certain field (term) in a document using the syntax below. But that is exacly the same as changing a single field and putting the same document again. the complete document is re-indexed, this is not a single field update.

response will be something like below:

adding another field using _update endpoint:

This will also work the same. re-index the entire document. You can see the version increase in the result output inside kibana.
DELETE /vehicles/cars/1 -> deletes the document deletes the specified document from the vehicles index
this will not immediately delete the document but will mark it as deleted. elastic search then periodicaly wipes these documents from the disk later.

DELETING Types/Indeces

it is not possible to delete a type. The command:

will display an error in kibana output panel like this:

No handler found for uri [/vehicles/cars] and method [DELETE]

deleting an index is possible:

DELETE vehicles -> will return “acknowledged:true” response and the index will be deleted.

GETTING Types/Indices

GET /vehicles -> will return the structure for the specified index. in this case “vehicles” index.
but the GET for “Types” will not work. Note: field types will be automatically determined by elestic search. You can see it in the output window inside kibana.

The command :

will return the message below:

Hope this helps.
Good Luck,