# How to remove invalid document from index

**URL:** <https://discuss.elastic.co/t/how-to-remove-invalid-document-from-index/65523>\
**Category:** Elasticsearch\
**Created:** [November 9, 2016, 4:01pm UTC](https://discuss.elastic.co/t/how-to-remove-invalid-document-from-index/65523 "2016-11-09T16:01:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRetep](https://avatars.discourse-cdn.com/v4/letter/p/aca169/32.png) [@PRetep](https://discuss.elastic.co/u/PRetep)\
**Post date:** [November 9, 2016, 4:01pm UTC](https://discuss.elastic.co/t/how-to-remove-invalid-document-from-index/65523/1 "2016-11-09T16:01:36Z")

</div>

Hello,

I accidently added a document to my index which contains an invalid character. How can I identify and corect/delete the invalid document?

```auto
curl http://192.168.2.105:9200/directory/_search?pretty -d'{query:{match_all{}}}'
{
  "error" : {
    "root_cause" : [ {
      "type" : "query_parsing_exception",
      "reason" : "Failed to parse",
      "index" : "directory"
    } ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [ {
      "shard" : 0,
      "index" : "directory",
      "node" : "kvd1OZj1SRCaENPaVX9Yvw",
      "reason" : {
        "type" : "query_parsing_exception",
        "reason" : "Failed to parse",
        "index" : "directory",
        "caused_by" : {
          "type" : "json_parse_exception",
          "reason" : "Unexpected character ('{' (code 123)): was expecting a colon to separate field name and value\n at [Source: [B@14b93ab; line: 1, column: 19]"
        }
      }
    } ]
  },
  "status" : 400
}

```

Thanks for help in advance!

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 9, 2016, 4:15pm UTC](https://discuss.elastic.co/t/how-to-remove-invalid-document-from-index/65523/2 "2016-11-09T16:15:50Z")

</div>

That snippet you posted is an invalid query. It has one too many trailing `}`s.

You can [delete](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html) documents with `curl -XDELETE localhost:9200/index/type/id`. You can use the [search API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html) to find the document to delete.

---

<div class="post-metadata">

**Author:** ![PRetep](https://avatars.discourse-cdn.com/v4/letter/p/aca169/32.png) [@PRetep](https://discuss.elastic.co/u/PRetep)\
**Post date:** [November 11, 2016, 7:20pm UTC](https://discuss.elastic.co/t/how-to-remove-invalid-document-from-index/65523/3 "2016-11-11T19:20:58Z")

</div>

My mistake!

Thanx a lot for support!!!

---

<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:** [December 9, 2016, 7:21pm UTC](https://discuss.elastic.co/t/how-to-remove-invalid-document-from-index/65523/4 "2016-12-09T19:21:25Z")

</div>

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