Access field document in an elasticsearch query

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 ?

Hi,
How about using Geo-Shape Datatype datatype (cirle) and GeoShape Query (point)?

1 Like

Hi,

Eventhough I will still need to access the value in the field 'radius'.

GET index_name/location/_search
{
    "query": {
        "geo_shape": {
            "location": { 
                "shape": { 
                    "type":   "circle", 
                    "radius": $radius, <-- (here I want to get the radius stored in each document while 
                                                           searching)
                    "coordinates": [ 
                        2.352222, 
                        48.999
                    ]
                }
            }
        }
    }
}

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"
                         }
                     }
                  }
             ]
         }
     }
 }

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