# Delete by query - Error invalid\_type\_name\_exception

**URL:** <https://discuss.elastic.co/t/delete-by-query-error-invalid-type-name-exception/119629>\
**Category:** Elasticsearch\
**Created:** [February 13, 2018, 12:20pm UTC](https://discuss.elastic.co/t/delete-by-query-error-invalid-type-name-exception/119629 "2018-02-13T12:20:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdujaparov](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@abdujaparov](https://discuss.elastic.co/u/abdujaparov)\
**Post date:** [February 13, 2018, 12:20pm UTC](https://discuss.elastic.co/t/delete-by-query-error-invalid-type-name-exception/119629/1 "2018-02-13T12:20:32Z")

</div>

Hi,  
I am trying to delete some elements with delete\_by\_query.  
I should remove 5 elements:  
curl -XGET 'localhost:9200/product\_metadata/\_count?pretty' -d '{"query": {"match":{"type.identifier": "plastic"}}}'

If I executed the delete by query I receive and error:

-bash-4.2$ curl -XPOST 'localhost:9200/product\_metadata/_delete\_by\_query?pretty' -d '{"query": {"match":{"type.identifier": "plastic"}}}'  
{  
"error" : {  
"root\_cause" : [  
{  
"type" : "invalid\_type\_name\_exception",  
"reason" : "Document mapping type name can't start with '_', found: [_delete\_by\_query]"  
}  
],  
"type" : "invalid\_type\_name\_exception",  
"reason" : "Document mapping type name can't start with '_', found: [\_delete\_by\_query]"  
},  
"status" : 400  
}

This is one of the element I found with the search:

{  
"\_index" : "product\_metadata",  
"\_type" : "product\_metadata",  
"\_id" : "a234255e-bedb-40f6-95b8-1dab5504e8f7",  
"\_score" : 5.5263844,  
"\_source" : {  
"@class" : "it.altecspace.asdp.productmanager.curator.CuratedProduct",  
"name" : "STA\_LB\_PLA\_BROWSE\_20180208\_V12.cdf",  
"id" : {  
"uuid" : "a234255e-bedb-40f6-95b8-1dab5504e8f7"  
},  
"type" : {  
"@class" : "it.altecspace.asdp.core.api.product.ProductType",  
"identifier" : "lasco/plastic+ahead",  
"description" : "Plastic product"  
},  
"metadata" : {  
"asdp" : {  
"product" : {  
"ingested\_on" : "20180213053542923"  
}  
}  
},  
"location" : {  
"@class" : "it.altecspace.asdp.productmanager.archivist.ProductLocation",  
"archive" : "default",  
"location" : "file:///asdp-data/data/fsarchive/archive/a234255e-bedb-40f6-95b8-1dab5504e8f7/"  
}  
}  
}

Where do I make a mistake?

I am able to delete each element specifying index and type:

curl -XDELETE [http://localhost:9200/product\_metadata/product\_metadata/810ee996-6d45-4cb5-964e-f205b4a94431/?pretty](http://localhost:9200/product_metadata/product_metadata/810ee996-6d45-4cb5-964e-f205b4a94431/?pretty)

But I need to use delete by query.

If I specify index and type I receive this:

-bash-4.2$ curl -XPOST 'localhost:9200/product\_metadata/product\_metadata/\_delete\_by\_query?pretty' -d '{"query": {"match":{"type.identifier": "plastic"}}}'  
{  
"\_index" : "product\_metadata",  
"\_type" : "product\_metadata",  
"\_id" : "\_delete\_by\_query",  
"\_version" : 8,  
"result" : "updated",  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"created" : false  
}

Bye

---

<div class="post-metadata">

**Author:** ![eason\_Lai](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@eason\_Lai](https://discuss.elastic.co/u/eason_Lai)\
**Post date:** [March 12, 2018, 6:38am UTC](https://discuss.elastic.co/t/delete-by-query-error-invalid-type-name-exception/119629/2 "2018-03-12T06:38:59Z")

</div>

I think your ES is in an older version and not supporting **plugin** delete\_by\_query.  
In your return from" curl -XPOST 'localhost:9200/product\_metadata/product\_metadata/\_delete\_by\_query?pretty' -d '{"query": {"match":{"type.identifier": "plastic"}}}' ", it shows you have build up a new doc with ID "\_delete\_by\_query".  
In another word, you were actually executing a "creating" instead of "delete by query".  
Solution: 1.check your version, old version do not support "delete by query"  
2. check plugin list to see if "delete by query" is installed  
Tips: "delete\_by\_query" is not a function in ES anymore. **It is a plugin.**

---

<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:** [April 9, 2018, 6:39am UTC](https://discuss.elastic.co/t/delete-by-query-error-invalid-type-name-exception/119629/3 "2018-04-09T06:39:21Z")

</div>

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