# Perform CRUD Operation on Elasticsearch With REST API

**URL:** <https://discuss.elastic.co/t/perform-crud-operation-on-elasticsearch-with-rest-api/340329>\
**Category:** Elasticsearch\
**Created:** [August 8, 2023, 7:07am UTC](https://discuss.elastic.co/t/perform-crud-operation-on-elasticsearch-with-rest-api/340329 "2023-08-08T07:07:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Debasis\_Mallick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debasis_mallick/32/123723_2.png) [@Debasis\_Mallick](https://discuss.elastic.co/u/Debasis_Mallick)\
**Post date:** [August 8, 2023, 7:07am UTC](https://discuss.elastic.co/t/perform-crud-operation-on-elasticsearch-with-rest-api/340329/1 "2023-08-08T07:07:10Z")

</div>

Hi Team,

Could anyone share how to perform CRUD operation in Elastic search with REST API. I had tried the below one with the curl command but getting error as "curl: (52) Empty reply from server" . Could you please guide me.

```auto
[root@prestovm1 ~]# curl -XPUT http://localhost:9200/my_index/my_type -curl -H 'Content-Type: application/json' -d '{"user": "Phil","message":"Hello World!"}'*
curl: (52) Empty reply from server*

```

Thanks,  
Debasis

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 8, 2023, 8:12am UTC](https://discuss.elastic.co/t/perform-crud-operation-on-elasticsearch-with-rest-api/340329/2 "2023-08-08T08:12:50Z")

</div>

If you are using a recent version of Elasticsearch, like 8.x, most likely you need to run something like:

```auto
curl -XPUT https://localhost:9200/my_index/my_type \
    --user elastic \
    -k \
    -H 'Content-Type: application/json' \
    -d '
{ 
  "user": "Phil",
  "message":"Hello World!"
}'

```

---

<div class="post-metadata">

**Author:** ![Debasis\_Mallick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debasis_mallick/32/123723_2.png) [@Debasis\_Mallick](https://discuss.elastic.co/u/Debasis_Mallick)\
**Post date:** [August 8, 2023, 9:17am UTC](https://discuss.elastic.co/t/perform-crud-operation-on-elasticsearch-with-rest-api/340329/3 "2023-08-08T09:17:45Z")

</div>

Hi @dadoonet thanks for your quick response. Still I am getting below error.  
Could you please assist.

\*[root@prestovm1 ~]# curl -XPUT [http://localhost:9200/my\_index/my\_type](http://localhost:9200/my_index/my_type) \*  
\*\> --user elastic \*  
\*\> -k \*  
\*\> -H 'Content-Type: application/json' \*  
_\> -d '_  
_\> {_  
_\> "user": "Phil",_  
_\> "message":"Hello World!"_  
_\> }'_  
_Enter host password for user 'elastic':_  
_curl: (52) Empty reply from server_  
_[root@prestovm1 ~]#_

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 8, 2023, 9:18am UTC](https://discuss.elastic.co/t/perform-crud-operation-on-elasticsearch-with-rest-api/340329/4 "2023-08-08T09:18:56Z")

</div>

You did not read correctly my code.  
See `http` vs `https`.

And please don't format your code with `*` and/or `>` but use the `</>` icon instead.

---

<div class="post-metadata">

**Author:** ![Debasis\_Mallick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debasis_mallick/32/123723_2.png) [@Debasis\_Mallick](https://discuss.elastic.co/u/Debasis_Mallick)\
**Post date:** [August 8, 2023, 9:24am UTC](https://discuss.elastic.co/t/perform-crud-operation-on-elasticsearch-with-rest-api/340329/5 "2023-08-08T09:24:41Z")

</div>

Initially, it throws an incorrect HTTP method as below.

```auto
[root@prestovm1 ~]# curl -XPUT https://localhost:9200/my_index/my_type \
> --user elastic \
> -k \
> -H 'Content-Type: application/json' \
> -d '
> {
> "user": "Phil",
> "message":"Hello World!"
> }'
Enter host password for user 'elastic':
{"error":"Incorrect HTTP method for uri [/my_index/my_type] and method [PUT], allowed: [POST]","status":405}[

```

Thanks,  
Debasis

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 8, 2023, 9:48am UTC](https://discuss.elastic.co/t/perform-crud-operation-on-elasticsearch-with-rest-api/340329/6 "2023-08-08T09:48:37Z")

</div>

Replace `-XPUT` by `-XPOST`.  
And use `_doc` instead of `my_type`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 5, 2023, 9:49am UTC](https://discuss.elastic.co/t/perform-crud-operation-on-elasticsearch-with-rest-api/340329/7 "2023-09-05T09:49:38Z")

</div>

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