Salil
Salil

Reputation: 47532

Painless script to iterate over the geopoint field

I have a field geocoordinate of geopoint datatype, I am trying to access all the data having latitude equals to the 45.34567 using PAINLESS script, but following code is not returning the correct data.

GET /places/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "script": {
            "script": {
              "source": """
              boolean has_geocoordinate = doc['geocoordinate'].size() != 0;
              boolean has_latitude = doc['latitude'].size() != 0;
              boolean has_longitude = doc['longitude'].size() != 0;
              boolean invalid_geo = false;
              if (has_geocoordinate && has_latitude && has_longitude) {
                invalid_geo = (doc['geocoordinate'].lat == 45.34567)
              }
              return invalid_geo;
              """,
              "lang": "painless"
            }
          }
        }
      ]
    }
  }
}

Upvotes: 0

Views: 55

Answers (0)

Related Questions