elasticsearch 6.0 indexing example using curl

Elasticsearch indexing example using curl with simple steps.

In our example we will learn how can we index 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.So to execute cURL command from cygwin first go to folder that have curl.exe and execute below command.

  • curl -XPUT 'localhost:9200/preparationforinterview/elasticsearch/2?pretty' -H 'Content-Type: application/json' -d '{ "name" : "sam", "profession" : "engineer"}'

  • Explain

    syntax of cURL command is


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

  • After executing above cURL command, we get following output

  • Explain

    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 can view mapping of type by following command.
  • curl 'localhost:9200/preparationforinterview/_mapping/elasticsearch?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