# Delete docs via JDBC importer

**URL:** <https://discuss.elastic.co/t/delete-docs-via-jdbc-importer/79875>\
**Category:** Elasticsearch\
**Created:** [March 24, 2017, 10:56am UTC](https://discuss.elastic.co/t/delete-docs-via-jdbc-importer/79875 "2017-03-24T10:56:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gang/32/15413_2.png) [@Gang](https://discuss.elastic.co/u/Gang)\
**Post date:** [March 24, 2017, 10:56am UTC](https://discuss.elastic.co/t/delete-docs-via-jdbc-importer/79875/1 "2017-03-24T10:56:09Z")

</div>

Hi everyone. Would anyone advise how to delete a document through the jdbc importer? I use it to download documents from the Database. But when the object in the database is marked as deleted, it should no longer fall into the search. I certainly can add conditions to the search, but it will be a constantly working additional filter. So I'm looking for the possibility of deleting such documents. Can you help?

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 24, 2017, 12:56pm UTC](https://discuss.elastic.co/t/delete-docs-via-jdbc-importer/79875/2 "2017-03-24T12:56:23Z")

</div>

Note, this is not really Elasticsearch related, you could also open an issue at my project page [http://github.com/jprante/elasticsearch-jdbc](http://github.com/jprante/elasticsearch-jdbc)

In JDBC importer, you can use the pseduo-column name `_optype` and set it to `delete`.

Example:

```auto
select ..., "delete" as _optype from ...

```

I do not recommend this in general because it may have dramatic effects on index segment organization, and because of deleted document markers in the segments, it mostly will require extra segment compaction from time to time via the forcemerge operation.

If there are many deleted documents, reindexing or timestamp-based index organization is much better.

Search filter are greatly optimized. It is not slower and more convenient to use a search filter.

---

<div class="post-metadata">

**Author:** ![Gang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gang/32/15413_2.png) [@Gang](https://discuss.elastic.co/u/Gang)\
**Post date:** [March 24, 2017, 1:05pm UTC](https://discuss.elastic.co/t/delete-docs-via-jdbc-importer/79875/3 "2017-03-24T13:05:31Z")

</div>

Thanks for the answer. I remember the query filter as a last resort. But I have few such documents, so I'm not afraid of fragmentation. For me, the bigger problem is the appearance of these documents in the sample.

---

<div class="post-metadata">

**Author:** ![Gang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gang/32/15413_2.png) [@Gang](https://discuss.elastic.co/u/Gang)\
**Post date:** [March 29, 2017, 11:00am UTC](https://discuss.elastic.co/t/delete-docs-via-jdbc-importer/79875/4 "2017-03-29T11:00:39Z")

</div>

> [@jprante](#):
>
> In JDBC importer, you can use the pseduo-column name \_optype and set it to delete.

Hello again! Can you please tell me where I can read about other options for \_optype and how they work.

Btw faced with problem [fix the number of threads continue to grow problem by cxfly · Pull Request #944 · jprante/elasticsearch-jdbc · GitHub](https://github.com/jprante/elasticsearch-jdbc/pull/944) last night. It was cool to have a patch for it, but dont you paln to update the release. It seems pretty dated for now.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 29, 2017, 10:31pm UTC](https://discuss.elastic.co/t/delete-docs-via-jdbc-importer/79875/5 "2017-03-29T22:31:09Z")

</div>

The pull request is just a small work around, there is a 5.x branch of JDBC importer with completely rewritten code, which is half ready, and not feature complete.

You are correct, release state for 2.x is pretty dated. I don't have enough time to spend on my leisure time projects, only from time to time. Currently I do not plan to do any 2.x based releases any more, instead I want to focus on 5.x. Maybe a last bug fix release.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 29, 2017, 10:42pm UTC](https://discuss.elastic.co/t/delete-docs-via-jdbc-importer/79875/6 "2017-03-29T22:42:02Z")

</div>

> [@Gang](#):
>
> Can you please tell me where I can read about other options for \_optype and how they work.

I did not document it. The reason is that mixing `_optype` in ES 2.x bulk actions does not always work well, you may lose data in ES index unintentionally etc. so I really do not recommend using it. If JDBC importer was a tool to lose data, I could be made responsible for data loss and this would be dramatic. I also tried to block SQL delete statements by making it difficult to not use a read-only DB connection etc. for good reason, only to protect existing data.

---

<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 26, 2017, 10:42pm UTC](https://discuss.elastic.co/t/delete-docs-via-jdbc-importer/79875/7 "2017-04-26T22:42:06Z")

</div>

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