# Need a way to check if field is null

**URL:** <https://discuss.elastic.co/t/need-a-way-to-check-if-field-is-null/362636>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 5, 2024, 11:35pm UTC](https://discuss.elastic.co/t/need-a-way-to-check-if-field-is-null/362636 "2024-07-05T23:35:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mg77345](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@mg77345](https://discuss.elastic.co/u/mg77345)\
**Post date:** [July 5, 2024, 11:35pm UTC](https://discuss.elastic.co/t/need-a-way-to-check-if-field-is-null/362636/1 "2024-07-05T23:35:38Z")

</div>

New to elasticsearch.

I'm trying to re-index old data into a new index to push it through an updated ingest pipeline. This includes data that's already been through that pipeline, which i want to add to the new index to combine with older data.

I get this error when trying to re-index that data:  
"cannot access method/field [empty] from a null def reference"

the field in question being "message", my pipeline deletes message at the end.

Is there a way in painless to skip or exit the execution of the script if "message" doesn't exist?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [July 8, 2024, 1:56pm UTC](https://discuss.elastic.co/t/need-a-way-to-check-if-field-is-null/362636/2 "2024-07-08T13:56:11Z")

</div>

Hi @mg77345

Did you try with [conditionally run processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html#conditionally-run-processor)?

Try like this: { "if" : "ctx.containsKey('field1')" }

---

<div class="post-metadata">

**Author:** ![mg77345](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@mg77345](https://discuss.elastic.co/u/mg77345)\
**Post date:** [August 1, 2024, 9:00pm UTC](https://discuss.elastic.co/t/need-a-way-to-check-if-field-is-null/362636/3 "2024-08-01T21:00:56Z")

</div>

Thanks, i ended up using:  
if ctx['field'].empty. That seemed to work.
