elasticsearch 6.0 deleting example using curl

Elasticsearch deleting example using curl with simple steps.


In our example we will learn how can we delete a document using curl in Elasticsearch.

cURL is a command line tool that can be used to transfer data over HTTP.In our example we will execute cURL command from cygwin.

  • To learn for deleting document.First we will index a document and after that we will delete it.
  • To index a document execute below command.
  • curl -XPUT 'localhost:9200/preparationforinterview2/elasticsearch-update/1?pretty' -H 'Content-Type: application/json' -d '{ "name" : "sam", "profession" : "engineer"}'



  • Explain

    syntax of cURL command is

    http://localhost:9200/index-name/type-name/document-name

    As we know in Elasticsearch every index have type and every type have document.In our example preparationforinterview2 is index name and elasticsearch-update is a type name while 1 is document name. For REST API Elasticsearch uses 9200 port as default port.

    Elasticsearch automatically adds index , type and mapping in that type.

    Elasticsearch automatically detects that name and profession is text and if new documents is added with more fields then Elasticsearch finds their type and adds it into mapping

  • We added more document to understand many scenario of delete, to check all indexed document first we will execute search command to see all indexed document.
  • curl 'localhost:9200/preparationforinterview2/elasticsearch-update/_search?pretty'


  • To delete a document by id , we execute below command.
  • curl -XDELETE 'localhost:9200/preparationforinterview2/elasticsearch-update/1?pretty'

    We get following output



    To check document with id 1 is deleted , we can execute search command again.

  • curl 'localhost:9200/preparationforinterview2/elasticsearch-update/_search?pretty'


  • If we want to delete index.For example in our case we have preparationforinterview2 index.To delete by it , execute below command.
  • curl -XDELETE 'localhost:9200/preparationforinterview2/'

    We get following output



    To check index preparationforinterview2 is deleted, we can execute search command again.

  • curl 'localhost:9200/preparationforinterview2/_search?pretty'





Visit Others Links

Elasticsearch Introduction
Elasticsearch 6.0 Setup
Elasticsearch Indexing And Searching
Elasticsearch 6.0 indexing example using curl
Elasticsearch 6.0 searching example using curl
Elasticsearch 6.0 updating example using curl
Elasticsearch 6.0 updating example using curl when document does not exist
Elasticsearch 6.0 deleting example using curl
Elasticsearch 6.0 request body based searching
Elasticsearch 6.0 query component example
Elasticsearch 6.0 Analyze API example
Top Elasticsearch Interview Question
© 2019 PreparationForInterview.com