# In logstash, How can we check if a data exists another elastic search index?

**URL:** <https://discuss.elastic.co/t/in-logstash-how-can-we-check-if-a-data-exists-another-elastic-search-index/254709>\
**Category:** Logstash\
**Created:** [November 9, 2020, 6:34am UTC](https://discuss.elastic.co/t/in-logstash-how-can-we-check-if-a-data-exists-another-elastic-search-index/254709 "2020-11-09T06:34:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![meghavinam](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@meghavinam](https://discuss.elastic.co/u/meghavinam)\
**Post date:** [November 9, 2020, 6:34am UTC](https://discuss.elastic.co/t/in-logstash-how-can-we-check-if-a-data-exists-another-elastic-search-index/254709/1 "2020-11-09T06:34:52Z")

</div>

I want to sync set of data from mysql to elastic search. That time i need to remove if same data exists in another index

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [November 9, 2020, 6:53am UTC](https://discuss.elastic.co/t/in-logstash-how-can-we-check-if-a-data-exists-another-elastic-search-index/254709/2 "2020-11-09T06:53:37Z")

</div>

Hi,

Welcome to this forum! 🥳

You can create a LogStash pipeline with the [jdbc-input](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html) to read the data from mysql and then use the [elasticsearch-filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-elasticsearch.html) to query ElasticSearch if it exists already.

Based on this information you can use the [action setting](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-action) of the [elasticsearch-output](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html) to either `index` or `delete` the document from your target index.

Best regards  
Wolfram

---

<div class="post-metadata">

**Author:** ![meghavinam](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@meghavinam](https://discuss.elastic.co/u/meghavinam)\
**Post date:** [November 9, 2020, 6:58am UTC](https://discuss.elastic.co/t/in-logstash-how-can-we-check-if-a-data-exists-another-elastic-search-index/254709/3 "2020-11-09T06:58:05Z")

</div>

Is there any example for this?  
How can use the result in output?

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [November 9, 2020, 7:00am UTC](https://discuss.elastic.co/t/in-logstash-how-can-we-check-if-a-data-exists-another-elastic-search-index/254709/4 "2020-11-09T07:00:57Z")

</div>

There is - as far as I know - no exact example for what you want but you can check the links above to get a general direction: You can store the results of you query in a field and use an `if` clause to switch between the output for creating and the output for deletion.

---

<div class="post-metadata">

**Author:** ![meghavinam](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@meghavinam](https://discuss.elastic.co/u/meghavinam)\
**Post date:** [November 9, 2020, 8:26am UTC](https://discuss.elastic.co/t/in-logstash-how-can-we-check-if-a-data-exists-another-elastic-search-index/254709/5 "2020-11-09T08:26:47Z")

</div>

I got the solution

mutate { add\_field =\> { "data\_occure" =\> "" } }  
elasticsearch {  
hosts =\> ["localhost:9200"]  
index =\> ["active\_users\_%{[domain\_alias]}"]  
query =\> "\_id:%{[email]}"  
result\_size =\> 1  
fields =\> {"email" =\>"data\_occure"}  
}

output {

```
    if [data_occure]=="" {
  stdout { codec => json }

```

}

}

---

<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 7, 2020, 8:26am UTC](https://discuss.elastic.co/t/in-logstash-how-can-we-check-if-a-data-exists-another-elastic-search-index/254709/6 "2020-12-07T08:26:52Z")

</div>

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