# No result when filter by scripted field

**URL:** <https://discuss.elastic.co/t/no-result-when-filter-by-scripted-field/197575>\
**Category:** Kibana\
**Created:** [August 30, 2019, 8:04pm UTC](https://discuss.elastic.co/t/no-result-when-filter-by-scripted-field/197575 "2019-08-30T20:04:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcaballero](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jcaballero](https://discuss.elastic.co/u/jcaballero)\
**Post date:** [August 30, 2019, 8:04pm UTC](https://discuss.elastic.co/t/no-result-when-filter-by-scripted-field/197575/1 "2019-08-30T20:04:11Z")

</div>

Hello,

using Kibana 5.4.1

My documents in ElasticSearch have 2 date fields: _start_ and _end_. Or only _start_ while the event is still happening.  
I have created a scripted field in Kibana, _length_, defined like this

```
if (!doc['end'].empty) { 
    return (doc['end'].value - doc['start'].value)/3600000.0
} else {
    return null;
}

```

I can see their values in the Discover page. However, if I try to filter in the query bar with something like this

```
length:<1

```

I only get a blank page, with a "No results found" message.  
Same with

```
_exists_:length

```

Even worse, if I filter by

```
!_exists_:length

```

I expected to see those documents with no value defined yet for the field. However, that is not always the result. Sometimes it returns documents with a valid value of the field.

**Is it OK to return "null" for a scripted field of type "number"?** Is that the issue?

---

<div class="post-metadata">

**Author:** ![mikecote](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikecote/32/58549_2.png) [@mikecote](https://discuss.elastic.co/u/mikecote)\
**Post date:** [August 30, 2019, 8:19pm UTC](https://discuss.elastic.co/t/no-result-when-filter-by-scripted-field/197575/2 "2019-08-30T20:19:14Z")

</div>

Hi @jcaballero,

Querying on scripted fields isn't something that is supported in 5.4. A more detailed explanation of how scripted fields work can be found here ([https://www.elastic.co/guide/en/kibana/5.4/scripted-fields.html](https://www.elastic.co/guide/en/kibana/5.4/scripted-fields.html)).

In the recent version of Kibana ([elastic.co/guide/en/kibana/7.3/scripted-fields.html](http://elastic.co/guide/en/kibana/7.3/scripted-fields.html)) there is a way to do this using the new experimental query language ([https://www.elastic.co/guide/en/kibana/7.3/kuery-query.html](https://www.elastic.co/guide/en/kibana/7.3/kuery-query.html)).

Hope this helps,  
Mike.

---

<div class="post-metadata">

**Author:** ![jcaballero](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jcaballero](https://discuss.elastic.co/u/jcaballero)\
**Post date:** [August 30, 2019, 8:24pm UTC](https://discuss.elastic.co/t/no-result-when-filter-by-scripted-field/197575/3 "2019-08-30T20:24:02Z")

</div>

Ah, I see. I guess I missed the part "Kibana cannot query scripted fields" 😛  
Thanks a lot!!

---

<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:** [September 27, 2019, 8:24pm UTC](https://discuss.elastic.co/t/no-result-when-filter-by-scripted-field/197575/4 "2019-09-27T20:24:10Z")

</div>

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