# Does AWS ElasticSearch v7.1 supports script\_fields in queries?

**URL:** <https://discuss.elastic.co/t/does-aws-elasticsearch-v7-1-supports-script-fields-in-queries/220569>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [February 24, 2020, 12:16am UTC](https://discuss.elastic.co/t/does-aws-elasticsearch-v7-1-supports-script-fields-in-queries/220569 "2020-02-24T00:16:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhnamaki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mhnamaki/32/61889_2.png) [@mhnamaki](https://discuss.elastic.co/u/mhnamaki)\
**Post date:** [February 24, 2020, 12:16am UTC](https://discuss.elastic.co/t/does-aws-elasticsearch-v7-1-supports-script-fields-in-queries/220569/1 "2020-02-24T00:16:18Z")

</div>

Hello,  
To return the distance information for each document and the query search origin, I'm using the following snippet:  
"script\_fields": {  
"distance": {  
"script": "doc['location\_lat\_lon'].arcDistance(40,-105)"  
}  
}

Does AWS ElasticSearch accept this kind of script field? If not, how can I modify this code to return the distance of each doc to the query search origin?

Best,

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 24, 2020, 4:07am UTC](https://discuss.elastic.co/t/does-aws-elasticsearch-v7-1-supports-script-fields-in-queries/220569/2 "2020-02-24T04:07:12Z")

</div>

Why not using sort by distance ?  
The sort key which is returned in the response object is the distance.

BTW did you look at [https://www.elastic.co/cloud](https://www.elastic.co/cloud) and [https://aws.amazon.com/marketplace/pp/B01N6YCISK](https://aws.amazon.com/marketplace/pp/B01N6YCISK) ?

Cloud by elastic is one way to have access to all features, all managed by us. Think about what is there yet like Security, Monitoring, Reporting, SQL, Canvas, APM, Logs UI, Infra UI, SIEM, Maps UI, AppSearch and what is coming next 🙂 ...

---

<div class="post-metadata">

**Author:** ![mhnamaki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mhnamaki/32/61889_2.png) [@mhnamaki](https://discuss.elastic.co/u/mhnamaki)\
**Post date:** [February 27, 2020, 6:18pm UTC](https://discuss.elastic.co/t/does-aws-elasticsearch-v7-1-supports-script-fields-in-queries/220569/3 "2020-02-27T18:18:12Z")

</div>

> [@dadoonet](#):
>
> loud by elastic is one way to have access to all features, all managed by us. Think about what is there yet like Security, Monitoring, Reporting, SQL, Canvas, APM, Logs UI, Infra UI, SIEM, Maps UI, AppSearch and what is coming ne

Thanks for your reply. Yeah, I can sort by distance and have that value in the response. However, if the order of sort keys are different then order of those values in the response is also different. Need to keep a mapping for it at the query time (it's doable), but this way was always robust no matter if we sort by distance or not, we always get a key-value for it in the response (easy to parse).

The reason is our other services are in AWS. However, sure, we'll think about it more ;).

Best,

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 27, 2020, 6:37pm UTC](https://discuss.elastic.co/t/does-aws-elasticsearch-v7-1-supports-script-fields-in-queries/220569/4 "2020-02-27T18:37:11Z")

</div>

I mentioned using the sort feature as it will be faster in my opinion than a painless script.

> [@mhnamaki](#):
>
> The reason is our other services are in AWS.

That's why our service runs also on AWS so you are always close to your application 😉

---

<div class="post-metadata">

**Author:** ![mhnamaki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mhnamaki/32/61889_2.png) [@mhnamaki](https://discuss.elastic.co/u/mhnamaki)\
**Post date:** [February 27, 2020, 7:10pm UTC](https://discuss.elastic.co/t/does-aws-elasticsearch-v7-1-supports-script-fields-in-queries/220569/5 "2020-02-27T19:10:40Z")

</div>

> [@dadoonet](#):
>
> That's why our service runs also on AWS so you are always close to your application 😉

This is very useful to me. So, you're saying we can purchase the service from ES, have all the features, but still host it in AWS?  
So, if we get it from this link, we have both benefits?

> **[AWS Marketplace: Elastic Cloud (Elasticsearch Service)](https://aws.amazon.com/marketplace/pp/prodview-voru33wi6xs7k)**

Thanks,

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 27, 2020, 7:22pm UTC](https://discuss.elastic.co/t/does-aws-elasticsearch-v7-1-supports-script-fields-in-queries/220569/6 "2020-02-27T19:22:49Z")

</div>

Exact. If you go directly to [cloud.elastic.co](http://cloud.elastic.co) you can have a 14 days free trial without any credit card to test it.  
Don't use the marketplace link as it won't be free using this link.

---

<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:** [March 26, 2020, 7:22pm UTC](https://discuss.elastic.co/t/does-aws-elasticsearch-v7-1-supports-script-fields-in-queries/220569/7 "2020-03-26T19:22:53Z")

</div>

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