{"action":"created","issue":{"url":"https://api.github.com/repos/sksamuel/elastic4s/issues/375","labels_url":"https://api.github.com/repos/sksamuel/elastic4s/issues/375/labels{/name}","comments_url":"https://api.github.com/repos/sksamuel/elastic4s/issues/375/comments","events_url":"https://api.github.com/repos/sksamuel/elastic4s/issues/375/events","html_url":"https://github.com/sksamuel/elastic4s/issues/375","id":99603128,"number":375,"title":"Geo distance filter - swapped latitude and longitude","user":{"login":"sejkorat","id":3884120,"avatar_url":"https://avatars.githubusercontent.com/u/3884120?v=3","gravatar_id":"","url":"https://api.github.com/users/sejkorat","html_url":"https://github.com/sejkorat","followers_url":"https://api.github.com/users/sejkorat/followers","following_url":"https://api.github.com/users/sejkorat/following{/other_user}","gists_url":"https://api.github.com/users/sejkorat/gists{/gist_id}","starred_url":"https://api.github.com/users/sejkorat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sejkorat/subscriptions","organizations_url":"https://api.github.com/users/sejkorat/orgs","repos_url":"https://api.github.com/users/sejkorat/repos","events_url":"https://api.github.com/users/sejkorat/events{/privacy}","received_events_url":"https://api.github.com/users/sejkorat/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-07T08:15:19Z","updated_at":"2015-08-07T11:07:53Z","closed_at":null,"body":"Hi,\r\n\r\nI was playing with geoDistance filter and I found that latitude and longitude are swapped in output query:\r\n\r\n`val req = search ....... \r\n      postFilter(geoDistance(\"adresa.souradnice.geopoint\") \r\n      lat souradnice.getLatitude.doubleValue() \r\n      lon souradnice.getLongitude.doubleValue()           \r\n      distance(30, DistanceUnit.KILOMETERS))\r\n\r\nprintln(req)\r\nprintln(\"lon =  \" + s.getLongitude.doubleValue() )\r\nprintln(\"lat =  \" + s.getLatitude.doubleValue() )\r\n`\r\nresults in \r\n\r\n  \"post_filter\" : {\r\n    \"geo_distance\" : {\r\n      \"adresa.souradnice.geopoint\" : [ 16.3074883, 49.86739129999999 ] ,\r\n      \"distance\" : \"30.0km\"\r\n    }\r\n\r\n   lon =  16.3074883\r\n   lat =  49.86739129999999\r\n\r\nAnd it's incorrect because result should be \"adresa.souradnice.geopoint\" :  [ 49.86739129999999, 16.3074883 ]. Please swap lat and lon.\r\n\r\nThanks,\r\nTomas"},"comment":{"url":"https://api.github.com/repos/sksamuel/elastic4s/issues/comments/128674917","html_url":"https://github.com/sksamuel/elastic4s/issues/375#issuecomment-128674917","issue_url":"https://api.github.com/repos/sksamuel/elastic4s/issues/375","id":128674917,"user":{"login":"sejkorat","id":3884120,"avatar_url":"https://avatars.githubusercontent.com/u/3884120?v=3","gravatar_id":"","url":"https://api.github.com/users/sejkorat","html_url":"https://github.com/sejkorat","followers_url":"https://api.github.com/users/sejkorat/followers","following_url":"https://api.github.com/users/sejkorat/following{/other_user}","gists_url":"https://api.github.com/users/sejkorat/gists{/gist_id}","starred_url":"https://api.github.com/users/sejkorat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sejkorat/subscriptions","organizations_url":"https://api.github.com/users/sejkorat/orgs","repos_url":"https://api.github.com/users/sejkorat/repos","events_url":"https://api.github.com/users/sejkorat/events{/privacy}","received_events_url":"https://api.github.com/users/sejkorat/received_events","type":"User","site_admin":false},"created_at":"2015-08-07T11:07:53Z","updated_at":"2015-08-07T11:07:53Z","body":"Hi,\r\n\r\nThere is more complete example: \r\n\r\ndef findSimilar(id: String, type :String, typPozadavku: Option[String], town: Option[String], point: GeoPoint): Future[SearchResponse] = {\r\n    client.execute{\r\n       val q = new BoolQueryDefinition {\r\n         must(\r\n          morelikeThisQuery(\"desc\") ids (id)\r\n         ) \r\n         if(!town.isEmpty) {\r\n           must(matchQuery(field = \"town\", value = town.get))\r\n         }\r\n       }\r\n       val req =search in s\"index/${type}\" query q sourceInclude(\"adress.town\", \"address.street\")       postFilter(geoDistance(\"adresss.geopoint\") lat point.getLatitude lon point.getLongitude distance(20,   DistanceUnit.KILOMETERS))\r\n       println(req)\r\n       req\r\n    }\r\n  }\r\n\r\nand this method prints ES query :\r\n\r\n{\r\n  \"query\" : {\r\n    \"bool\" : {\r\n      \"must\" : [ {\r\n        \"mlt\" : {\r\n          \"fields\" : [ \"desc\" ],\r\n          \"like_text\" : null,\r\n          \"ids\" : [ \"H-5965723\" ]\r\n        }\r\n      }, {\r\n        \"match\" : {\r\n          \"town\" : {\r\n            \"query\" : \"TestTwon\"\r\n          }\r\n        }\r\n      } ]\r\n    }\r\n  },\r\n  \"post_filter\" : {\r\n    \"geo_distance\" : {\r\n      \"adresss.geopoint\" : [ 16.311062, 49.870523 ],\r\n      \"distance\" : \"20.0km\"\r\n    }\r\n  },\r\n  \"_source\" : {\r\n    \"includes\" : [ \"adress.town\", \"address.street\" ],\r\n    \"excludes\" : [ ]\r\n  }\r\n}\r\n\r\nPproblem is in geo_distance filter. There is incorrect order of latitude and longitude: (in our case GeoPoint contains latitude = 49.870523 and longitude 16.311062 )\r\nFirst should be latitude and then longitude but the current order is [lon, lat] in our case \"adresss.geopoint\" should contain [ 49.870523, 16.311062 ]\r\n\r\nI hope this helps.\r\n\r\nThanks,\r\nTomas "}}