# How to run a DSL query in scripted filed

**URL:** <https://discuss.elastic.co/t/how-to-run-a-dsl-query-in-scripted-filed/260359>\
**Category:** Kibana\
**Created:** [January 6, 2021, 3:15pm UTC](https://discuss.elastic.co/t/how-to-run-a-dsl-query-in-scripted-filed/260359 "2021-01-06T15:15:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![learn\_and\_try](https://avatars.discourse-cdn.com/v4/letter/l/eada6e/32.png) [@learn\_and\_try](https://discuss.elastic.co/u/learn_and_try)\
**Post date:** [January 6, 2021, 3:15pm UTC](https://discuss.elastic.co/t/how-to-run-a-dsl-query-in-scripted-filed/260359/1 "2021-01-06T15:15:16Z")

</div>

I am tried to create a scripted filed that return me a number with all the executed queries  
I try to execute my query in **scripted filed** in **kibana**  
help me plz to fix it or something else how to do that

> "query": {  
> "bool": {  
> "must": {  
> "match\_all": {}  
> },  
> "filter": [  
> {  
> "geo\_distance": {  
> "distance": "1000km",  
> "geoLocation": {  
> "lat": "doc['Latitude'].value",  
> "lon": "doc['Longitude'].value"  
> }  
> }  
> },  
> {  
> "range": {  
> "map\_date": {  
> "gte": "now-3w/w",  
> "lte": "now/w"  
> }  
> }  
> }  
> ]  
> }  
> }

I can't run it in the DSL console because I don't know how to access the filed values like this: doc['filed'].value  
any Suggestions?

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [January 6, 2021, 3:24pm UTC](https://discuss.elastic.co/t/how-to-run-a-dsl-query-in-scripted-filed/260359/2 "2021-01-06T15:24:34Z")

</div>

Are you trying to create a scripted field with a DSL query? If so that can't be done. You can only use Painless in the scripting box.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/6/f6f44422bbcb32f9c9e0630b30b3f8a5d9c17832.png)

Or did you create a scripted field and trying to utilize it in a DSL query? If so then you just use the field name you gave it when you created the field.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/e/5e87b4e1aaf5cfd505259deccca269e889a3936d.png)

---

<div class="post-metadata">

**Author:** ![learn\_and\_try](https://avatars.discourse-cdn.com/v4/letter/l/eada6e/32.png) [@learn\_and\_try](https://discuss.elastic.co/u/learn_and_try)\
**Post date:** [January 6, 2021, 4:54pm UTC](https://discuss.elastic.co/t/how-to-run-a-dsl-query-in-scripted-filed/260359/3 "2021-01-06T16:54:03Z")

</div>

in the scripted filed I can access to exist fields value like this: doc['filed'].value  
how can I do this In normal DSL ?  
I tried for each point in my fields to execute the geo\_distance and the range query and count it to a  
new field.  
any suggestion how to do it? 🙏

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [January 6, 2021, 5:17pm UTC](https://discuss.elastic.co/t/how-to-run-a-dsl-query-in-scripted-filed/260359/4 "2021-01-06T17:17:32Z")

</div>

Ahh ok.

Short answer is you can't. If you read the [scripted fields documentation](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html) you can use these in Discover, KQL, and Visualizations.

If you do a normal DSL query you will see the scripted field does not exist.

---

<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:** [February 3, 2021, 5:17pm UTC](https://discuss.elastic.co/t/how-to-run-a-dsl-query-in-scripted-filed/260359/5 "2021-02-03T17:17:34Z")

</div>

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