# Validate document before sending to elasticsearch

**URL:** <https://discuss.elastic.co/t/validate-document-before-sending-to-elasticsearch/337859>\
**Category:** Logstash\
**Created:** [July 7, 2023, 7:01am UTC](https://discuss.elastic.co/t/validate-document-before-sending-to-elasticsearch/337859 "2023-07-07T07:01:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_Mightiev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a_mightiev/32/62186_2.png) [@A\_Mightiev](https://discuss.elastic.co/u/A_Mightiev)\
**Post date:** [July 7, 2023, 7:01am UTC](https://discuss.elastic.co/t/validate-document-before-sending-to-elasticsearch/337859/1 "2023-07-07T07:01:59Z")

</div>

Hi,  
I have a strict mapping in my ES cluster and send documents via Logstash, sometimes the documents get dropped because they don't conform the strict mapping, is there a way to check if the document conforms or not to the mapping before sending to elasticsearch and gets dropped?  
Thanks  
A

---

<div class="post-metadata">

**Author:** ![A\_Mightiev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a_mightiev/32/62186_2.png) [@A\_Mightiev](https://discuss.elastic.co/u/A_Mightiev)\
**Post date:** [July 28, 2023, 1:46pm UTC](https://discuss.elastic.co/t/validate-document-before-sending-to-elasticsearch/337859/2 "2023-07-28T13:46:30Z")

</div>

nothing?

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [July 28, 2023, 3:19pm UTC](https://discuss.elastic.co/t/validate-document-before-sending-to-elasticsearch/337859/3 "2023-07-28T15:19:00Z")

</div>

You would need to check every field in the document to see if they are in your mapping or not, you could do that writing a ruby script with the `ruby` filter that will compare the field name with a list of allowed fields.

Not sure how this script would like because I do not know ruby enough, but it probably can be done using the ruby script.

You could also use the `prune` filter to only allow the mapped fields.

---

<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:** [August 25, 2023, 3:19pm UTC](https://discuss.elastic.co/t/validate-document-before-sending-to-elasticsearch/337859/4 "2023-08-25T15:19:16Z")

</div>

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