1

For example suppose we have this mapping :

{
    "location":{
        "dynamic":"false",
        "properties":{
            "locality":{"type":"text"},
            "country":{"type":"text"},
            "postalCode":{"type":"text"},
            "coordinates":{"type":"geo_point"},
            "radius":{"type":"double"}
        }
    }
}

And this is my query :

GET index_name/location/_search
{
    "query": {
        "bool": {
            "filter": {
                "geo_distance": {
                    "coordinates": [
                        2.352222, 
                        48.999
                    ],
                    "distance": $radius <--- *(here I want to access the
                                               value of radius in document)*
                 }
            }
        }
    }
}

Is there a mean to access a field document value in an Elasticsearch query ?

Is it feasible using Script Query ? doc here

1
  • The docs you linked do just that, so I don't see why it wouldn't be feasible.. Commented Feb 9, 2018 at 17:04

1 Answer 1

1

Yes actually the Script Query does the trick :

GET index_name/location/_search
{
    "query": {
        "bool": {
            "must": [
                {
                    "script": {
                        "script": {
                            "inline": "doc['coordinates'].planeDistance(48.856614 , 2.37959999) <= doc['radius'].value",
                            "lang": "painless"
                        }
                    }
                 }
            ]
        }
    }
}

thanks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.