Getting started - where and how to use POST command example?

Just recently installed Elasticsearch in Windows 10.
Trying to follow "getting started" tutorial.

Can you provide working version of curl command or equivalent whereby I can execute this step?

I do not have Kibana installed yet.

Simple GET works from Windows CMD window.

C:\Users\debasisc>curl -X GET localhost:9200
{
  "name" : "CDDMLW008",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "ENU01Xf1T5-sZRyF-jF7Vw",
  "version" : {
    "number" : "7.5.2",
    "build_flavor" : "default",
    "build_type" : "zip",
    "build_hash" : "8bec50e1e0ad29dad5653712cf3bb580cd1afcdf",
    "build_date" : "2020-01-15T12:11:52.313576Z",
    "build_snapshot" : false,
    "lucene_version" : "8.3.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}


Thank you

POST localhost:9200/accounts/person/1 
{
    "name" : "John",
    "lastname" : "Doe",
    "job_description" : "Systems administrator and Linux specialit"
}

Getting started shows example PUT - but looks like that is not supported.

I then tried to create separate file with input. And used POST. Even then I get error.

C:\Elasticsearch\elasticsearch-7.5.2\bin>type try1.txt
{
"name": "John Doe"
}
C:\Elasticsearch\elasticsearch-7.5.2\bin>curl -X POST -d try1.txt localhost:9200/accounts/person/1
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
C:\Elasticsearch\elasticsearch-7.5.2\bin>

Okay, after several tries - this command works -

My command is in separate file "try1.txt"
C:\Elasticsearch\elasticsearch-7.5.2\bin>type try1.txt

{

"name": "John Doe"

}

C:\Elasticsearch\elasticsearch-7.5.2\bin>curl -X POST -d @try1.txt -H "Content-Type: application/json" localhost:9200/accounts/person/1

{"_index":"accounts","_type":"person","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}

Hi @debasisc,

glad that you found a solution. Notice that all examples in the elasticsearch docs have a "Copy as cURL" option, making it easy to go from the examples to pasting them into a terminal. See for instance this example.

Thanks. Indeed the link "Copy as cURL" is very useful.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.