# How to check if a field exists in the Ruby plugin?

**URL:** <https://discuss.elastic.co/t/how-to-check-if-a-field-exists-in-the-ruby-plugin/43354>\
**Category:** Logstash\
**Created:** [March 3, 2016, 9:03am UTC](https://discuss.elastic.co/t/how-to-check-if-a-field-exists-in-the-ruby-plugin/43354 "2016-03-03T09:03:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gunay](https://avatars.discourse-cdn.com/v4/letter/g/d6d6ee/32.png) [@gunay](https://discuss.elastic.co/u/gunay)\
**Post date:** [March 3, 2016, 9:03am UTC](https://discuss.elastic.co/t/how-to-check-if-a-field-exists-in-the-ruby-plugin/43354/1 "2016-03-03T09:03:33Z")

</div>

Hi,

I am trying to find how to check if a field exist in the ruby filter.

To check the existence of a field in Ruby, I tried the following three, seems that none of them work

if event['duration']['time'] =~ /.+/  
if event['duration']['time'] != nil  
if(event['duration']['time'])

Any suggestions?

My code is like:

filter {  
json {  
source =\> "message"  
}  
if [profiling][method] =~ /.+/ {  
ruby {  
code =\> "  
if(event['duration']['time'])  
event['timeStart'] = event['timeEnd'] - event['duration']['time']   
end"  
}  
}  
}

---

<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:** [July 6, 2017, 5:08am UTC](https://discuss.elastic.co/t/how-to-check-if-a-field-exists-in-the-ruby-plugin/43354/2 "2017-07-06T05:08:38Z")

</div>


