Is it possible to use a painless script?

Is it possible to use a painless script for search?
I’m thinking to move from ES to Mongo Atlas, but i kind of need some flexibility with my queries.

One example is:
I need to find nearby stores to my customers, but the store has the possibility to define the max distance it will delivery.
And i’m using this script in ES for it.
Is it possible to do that with atlas search?

script: {

          script: {

            source: "doc['location'].arcDistance(params.lat, params.lon) / 1000 < doc['marketplace.distanceRadius'].value",

            lang: 'painless',

            params: {

              lat: Number(body.lat),

              lon: Number(body.lon),

            }

          }

        }

Hi Rodrigo,

Painless is a scripting language designed specifically for Elasticsearch, which lets you write inline/stored scripts and use them in ES (reference: documentation here). As far as I know, there is no way to use Painless scripts within Atlas Search.

However, what the Painless script in question is doing might be achievable in Atlas Search as well. Please refer to this Atlas Search Tutorial: How to Run a Compound Geo JSON Query that discusses how to retrieve documents within a specified polygon using coordinates. Also, you may find the documentation on the Atlas Search geoWithin, geoShape, and near operators useful and relevant.

Hope this helps.

Thanks,
Harshad

2 Likes

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