Search by distance and getting the actual distance


(Matthias Nothhaft) #1

Hi,

I'm trying to use elasticsearch for geo location search. It works fine so
using a filtered query and the geo_distance filter. What I miss in the
search result is the distance between "my location" and each of the results.
Is it possible somehow to add the distance to the result? Can someone give
me an example or point me to some docs how to make it?

regards,
Matthias


(Kaspars Sprogis) #2

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias Nothhaft wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It works fine so
using a filtered query and the geo_distance filter. What I miss in the
search result is the distance between "my location" and each of the
results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Peter Schröder) #3

have a look at this
posting http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias Nothhaft wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It works fine so
using a filtered query and the geo_distance filter. What I miss in the
search result is the distance between "my location" and each of the
results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Kaspars Sprogis) #4

I look at that posting already, and i am already sorting by _geo_distance
but no actual distance value is returned (using latest 0.9.2)

Then only in once place somewhere on stackoverflow i found that we need to
use script_fields to get distance to the results and i am wondering why in
many places it is mentioned that distance should be in results if you are
sorting by _geo_distance if it is not?! Maybe i am doing something wrong,
but i tested thousand times.

Only way i could get distance is like this:

"fields": [
"_source"
],
"script_fields": {
"distance": {
"params": {
"lat": 56.959942,
"lon": 24.113656
},
"script": "doc['location'].arcDistanceInKm(lat, lon)"
}
}

On Tuesday, April 24, 2012 9:50:07 PM UTC+3, Peter Schröder wrote:

have a look at this posting
http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias Nothhaft wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It works fine
so using a filtered query and the geo_distance filter. What I miss in the
search result is the distance between "my location" and each of the
results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Igor Motov) #5

Take a look at this example: https://gist.github.com/2483149

The value in the "sort" field is the distance:

  "sort" : [ 114.81801790248922 ]

On Tuesday, April 24, 2012 2:55:58 PM UTC-4, Kaspars Sprogis wrote:

I look at that posting already, and i am already sorting by _geo_distance
but no actual distance value is returned (using latest 0.9.2)

Then only in once place somewhere on stackoverflow i found that we need to
use script_fields to get distance to the results and i am wondering why in
many places it is mentioned that distance should be in results if you are
sorting by _geo_distance if it is not?! Maybe i am doing something wrong,
but i tested thousand times.

Only way i could get distance is like this:

"fields": [
"_source"
],
"script_fields": {
"distance": {
"params": {
"lat": 56.959942,
"lon": 24.113656
},
"script": "doc['location'].arcDistanceInKm(lat, lon)"
}
}

On Tuesday, April 24, 2012 9:50:07 PM UTC+3, Peter Schröder wrote:

have a look at this posting
http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias Nothhaft
wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It works fine
so using a filtered query and the geo_distance filter. What I miss in the
search result is the distance between "my location" and each of the
results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Kaspars Sprogis) #6

Since in my test case all returned "sort" fields were almost identical
(event if distance is different) i decided sort key is something different,
some value of inner calculations.

So i think there is a bug somewhere with geo-search, so i reported whole
test case to github issues

Because if you look at my test case: https://gist.github.com/2483009
You will see that returned "sort" values are almost identical and also
returned sort order is wrong...

Thanks, it is good to know "sort" actually should return distance, let's
hope there is some explanation why problems in my test case appears.

On Tuesday, April 24, 2012 11:01:23 PM UTC+3, Igor Motov wrote:

Take a look at this example: https://gist.github.com/2483149

The value in the "sort" field is the distance:

  "sort" : [ 114.81801790248922 ]

On Tuesday, April 24, 2012 2:55:58 PM UTC-4, Kaspars Sprogis wrote:

I look at that posting already, and i am already sorting by _geo_distance
but no actual distance value is returned (using latest 0.9.2)

Then only in once place somewhere on stackoverflow i found that we need
to use script_fields to get distance to the results and i am wondering why
in many places it is mentioned that distance should be in results if you
are sorting by _geo_distance if it is not?! Maybe i am doing something
wrong, but i tested thousand times.

Only way i could get distance is like this:

"fields": [
"_source"
],
"script_fields": {
"distance": {
"params": {
"lat": 56.959942,
"lon": 24.113656
},
"script": "doc['location'].arcDistanceInKm(lat, lon)"
}
}

On Tuesday, April 24, 2012 9:50:07 PM UTC+3, Peter Schröder wrote:

have a look at this posting
http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias Nothhaft
wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It works fine
so using a filtered query and the geo_distance filter. What I miss in the
search result is the distance between "my location" and each of the
results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Igor Motov) #7

Yeah, it's one of these gotchas that many people run into. When you specify
location as an array, it follows GeoJson format [lon, lat], instead of lat,
lon. So, if you will flip the numbers in _geo_distance sort location, it
will work as expected:

"_geo_distance": {
"location": [
24.113656,
56.959942
],
"order": "asc",
"unit": "km"
}

On Tuesday, April 24, 2012 4:19:53 PM UTC-4, Kaspars Sprogis wrote:

Since in my test case all returned "sort" fields were almost identical
(event if distance is different) i decided sort key is something different,
some value of inner calculations.

So i think there is a bug somewhere with geo-search, so i reported whole
test case to github issues
https://github.com/elasticsearch/elasticsearch/issues/1885

Because if you look at my test case: https://gist.github.com/2483009
You will see that returned "sort" values are almost identical and also
returned sort order is wrong...

Thanks, it is good to know "sort" actually should return distance, let's
hope there is some explanation why problems in my test case appears.

On Tuesday, April 24, 2012 11:01:23 PM UTC+3, Igor Motov wrote:

Take a look at this example: https://gist.github.com/2483149

The value in the "sort" field is the distance:

  "sort" : [ 114.81801790248922 ]

On Tuesday, April 24, 2012 2:55:58 PM UTC-4, Kaspars Sprogis wrote:

I look at that posting already, and i am already sorting by
_geo_distance but no actual distance value is returned (using latest 0.9.2)

Then only in once place somewhere on stackoverflow i found that we need
to use script_fields to get distance to the results and i am wondering why
in many places it is mentioned that distance should be in results if you
are sorting by _geo_distance if it is not?! Maybe i am doing something
wrong, but i tested thousand times.

Only way i could get distance is like this:

"fields": [
"_source"
],
"script_fields": {
"distance": {
"params": {
"lat": 56.959942,
"lon": 24.113656
},
"script": "doc['location'].arcDistanceInKm(lat, lon)"
}
}

On Tuesday, April 24, 2012 9:50:07 PM UTC+3, Peter Schröder wrote:

have a look at this posting
http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias Nothhaft
wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It works
fine so using a filtered query and the geo_distance filter. What I miss in
the search result is the distance between "my location" and each of the
results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Kaspars Sprogis) #8

Wow, thanks. I spent half a day running tests, googling and finally decided
it could be a bug and even reported.
There should be some warning or exclamation marks like "Important notice" on
docs where it mentions format changes :slight_smile: it too easy to mis-read lat, lon
vs lon, lat.

Thanks a lot.

On Wednesday, April 25, 2012 12:02:44 AM UTC+3, Igor Motov wrote:

Yeah, it's one of these gotchas that many people run into. When you
specify location as an array, it follows GeoJson format [lon, lat], instead
of lat, lon. So, if you will flip the numbers in _geo_distance sort
location, it will work as expected:

"_geo_distance": {
"location": [
24.113656,
56.959942
],
"order": "asc",
"unit": "km"
}

On Tuesday, April 24, 2012 4:19:53 PM UTC-4, Kaspars Sprogis wrote:

Since in my test case all returned "sort" fields were almost identical
(event if distance is different) i decided sort key is something different,
some value of inner calculations.

So i think there is a bug somewhere with geo-search, so i reported whole
test case to github issues
https://github.com/elasticsearch/elasticsearch/issues/1885

Because if you look at my test case: https://gist.github.com/2483009
You will see that returned "sort" values are almost identical and also
returned sort order is wrong...

Thanks, it is good to know "sort" actually should return distance, let's
hope there is some explanation why problems in my test case appears.

On Tuesday, April 24, 2012 11:01:23 PM UTC+3, Igor Motov wrote:

Take a look at this example: https://gist.github.com/2483149

The value in the "sort" field is the distance:

  "sort" : [ 114.81801790248922 ]

On Tuesday, April 24, 2012 2:55:58 PM UTC-4, Kaspars Sprogis wrote:

I look at that posting already, and i am already sorting by
_geo_distance but no actual distance value is returned (using latest 0.9.2)

Then only in once place somewhere on stackoverflow i found that we need
to use script_fields to get distance to the results and i am wondering why
in many places it is mentioned that distance should be in results if you
are sorting by _geo_distance if it is not?! Maybe i am doing something
wrong, but i tested thousand times.

Only way i could get distance is like this:

"fields": [
"_source"
],
"script_fields": {
"distance": {
"params": {
"lat": 56.959942,
"lon": 24.113656
},
"script": "doc['location'].arcDistanceInKm(lat, lon)"
}
}

On Tuesday, April 24, 2012 9:50:07 PM UTC+3, Peter Schröder wrote:

have a look at this posting
http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias Nothhaft
wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It works
fine so using a filtered query and the geo_distance filter. What I miss in
the search result is the distance between "my location" and each of the
results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Igor Motov) #9

I totally agree with you. It's quite confusing. By the way, docs are in
https://github.com/elasticsearch/elasticsearch.github.com Care to submit a
pull request? :wink:

On Tuesday, April 24, 2012 5:19:50 PM UTC-4, Kaspars Sprogis wrote:

Wow, thanks. I spent half a day running tests, googling
and finally decided it could be a bug and even reported.
There should be some warning or exclamation marks like *"Important notice"

  • on docs where it mentions format changes :slight_smile: it too easy to mis-read
    lat, lon vs lon, lat.

Thanks a lot.

On Wednesday, April 25, 2012 12:02:44 AM UTC+3, Igor Motov wrote:

Yeah, it's one of these gotchas that many people run into. When you
specify location as an array, it follows GeoJson format [lon, lat], instead
of lat, lon. So, if you will flip the numbers in _geo_distance sort
location, it will work as expected:

"_geo_distance": {
"location": [
24.113656,
56.959942
],
"order": "asc",
"unit": "km"
}

On Tuesday, April 24, 2012 4:19:53 PM UTC-4, Kaspars Sprogis wrote:

Since in my test case all returned "sort" fields were almost identical
(event if distance is different) i decided sort key is something different,
some value of inner calculations.

So i think there is a bug somewhere with geo-search, so i reported whole
test case to github issues
https://github.com/elasticsearch/elasticsearch/issues/1885

Because if you look at my test case: https://gist.github.com/2483009
You will see that returned "sort" values are almost identical and also
returned sort order is wrong...

Thanks, it is good to know "sort" actually should return distance, let's
hope there is some explanation why problems in my test case appears.

On Tuesday, April 24, 2012 11:01:23 PM UTC+3, Igor Motov wrote:

Take a look at this example: https://gist.github.com/2483149

The value in the "sort" field is the distance:

  "sort" : [ 114.81801790248922 ]

On Tuesday, April 24, 2012 2:55:58 PM UTC-4, Kaspars Sprogis wrote:

I look at that posting already, and i am already sorting by
_geo_distance but no actual distance value is returned (using latest 0.9.2)

Then only in once place somewhere on stackoverflow i found that we
need to use script_fields to get distance to the results and i am wondering
why in many places it is mentioned that distance should be in results if
you are sorting by _geo_distance if it is not?! Maybe i am doing something
wrong, but i tested thousand times.

Only way i could get distance is like this:

"fields": [
"_source"
],
"script_fields": {
"distance": {
"params": {
"lat": 56.959942,
"lon": 24.113656
},
"script": "doc['location'].arcDistanceInKm(lat, lon)"
}
}

On Tuesday, April 24, 2012 9:50:07 PM UTC+3, Peter Schröder wrote:

have a look at this posting
http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias Nothhaft
wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It works
fine so using a filtered query and the geo_distance filter. What I miss in
the search result is the distance between "my location" and each of the
results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Kaspars Sprogis) #10

I'll explore how the docs are built and see what i can do. As i already
have all the test data for geo search probably tutorial on geo search could
be a help too. As i did lot of search yesterday, i noticed all the same
questions all around about geo search. As kimchy added support for Latvian
stemming after one day i wrote an issue (which was essential one for us
choosing ES) and released this feature in a week in new version i think i
owe this community some help too :slight_smile:

On Wednesday, April 25, 2012 12:34:35 AM UTC+3, Igor Motov wrote:

I totally agree with you. It's quite confusing. By the way, docs are in
https://github.com/elasticsearch/elasticsearch.github.com Care to submit
a pull request? :wink:

On Tuesday, April 24, 2012 5:19:50 PM UTC-4, Kaspars Sprogis wrote:

Wow, thanks. I spent half a day running tests, googling
and finally decided it could be a bug and even reported.
There should be some warning or exclamation marks like "Important
notice"
on docs where it mentions format changes :slight_smile: it too easy to
mis-read lat, lon vs lon, lat.

Thanks a lot.

On Wednesday, April 25, 2012 12:02:44 AM UTC+3, Igor Motov wrote:

Yeah, it's one of these gotchas that many people run into. When you
specify location as an array, it follows GeoJson format [lon, lat], instead
of lat, lon. So, if you will flip the numbers in _geo_distance sort
location, it will work as expected:

"_geo_distance": {
"location": [
24.113656,
56.959942
],
"order": "asc",
"unit": "km"
}

On Tuesday, April 24, 2012 4:19:53 PM UTC-4, Kaspars Sprogis wrote:

Since in my test case all returned "sort" fields were almost identical
(event if distance is different) i decided sort key is something different,
some value of inner calculations.

So i think there is a bug somewhere with geo-search, so i reported
whole test case to github issues
https://github.com/elasticsearch/elasticsearch/issues/1885

Because if you look at my test case: https://gist.github.com/2483009
You will see that returned "sort" values are almost identical and also
returned sort order is wrong...

Thanks, it is good to know "sort" actually should return distance,
let's hope there is some explanation why problems in my test case appears.

On Tuesday, April 24, 2012 11:01:23 PM UTC+3, Igor Motov wrote:

Take a look at this example: https://gist.github.com/2483149

The value in the "sort" field is the distance:

  "sort" : [ 114.81801790248922 ]

On Tuesday, April 24, 2012 2:55:58 PM UTC-4, Kaspars Sprogis wrote:

I look at that posting already, and i am already sorting by
_geo_distance but no actual distance value is returned (using latest 0.9.2)

Then only in once place somewhere on stackoverflow i found that we
need to use script_fields to get distance to the results and i am wondering
why in many places it is mentioned that distance should be in results if
you are sorting by _geo_distance if it is not?! Maybe i am doing something
wrong, but i tested thousand times.

Only way i could get distance is like this:

"fields": [
"_source"
],
"script_fields": {
"distance": {
"params": {
"lat": 56.959942,
"lon": 24.113656
},
"script": "doc['location'].arcDistanceInKm(lat, lon)"
}
}

On Tuesday, April 24, 2012 9:50:07 PM UTC+3, Peter Schröder wrote:

have a look at this posting
http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias Nothhaft
wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It works
fine so using a filtered query and the geo_distance filter. What I miss in
the search result is the distance between "my location" and each of the
results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Shay Banon) #11

Heya, the formatting is specified here for example:
http://www.elasticsearch.org/guide/reference/api/search/sort.html. Its hard
to find, I know..., and to be honest its confusing (the order) for me as
well, it used to be the other way around, but we changed it to match the
geojson spec.

On Wed, Apr 25, 2012 at 7:51 AM, Kaspars Sprogis darklow@gmail.com wrote:

I'll explore how the docs are built and see what i can do. As i already
have all the test data for geo search probably tutorial on geo search could
be a help too. As i did lot of search yesterday, i noticed all the same
questions all around about geo search. As kimchy added support for Latvian
stemming after one day i wrote an issue (which was essential one for us
choosing ES) and released this feature in a week in new version i think i
owe this community some help too :slight_smile:

On Wednesday, April 25, 2012 12:34:35 AM UTC+3, Igor Motov wrote:

I totally agree with you. It's quite confusing. By the way, docs are in
https://github.com/**elasticsearch/elasticsearch.**github.comhttps://github.com/elasticsearch/elasticsearch.github.comCare to submit a pull request? :wink:

On Tuesday, April 24, 2012 5:19:50 PM UTC-4, Kaspars Sprogis wrote:

Wow, thanks. I spent half a day running tests, googling
and finally decided it could be a bug and even reported.
There should be some warning or exclamation marks like "Important
notice"
on docs where it mentions format changes :slight_smile: it too easy to
mis-read lat, lon vs lon, lat.

Thanks a lot.

On Wednesday, April 25, 2012 12:02:44 AM UTC+3, Igor Motov wrote:

Yeah, it's one of these gotchas that many people run into. When you
specify location as an array, it follows GeoJson format [lon, lat], instead
of lat, lon. So, if you will flip the numbers in _geo_distance sort
location, it will work as expected:

"_geo_distance": {
"location": [
24.113656,
56.959942
],
"order": "asc",
"unit": "km"
}

On Tuesday, April 24, 2012 4:19:53 PM UTC-4, Kaspars Sprogis wrote:

Since in my test case all returned "sort" fields were almost identical
(event if distance is different) i decided sort key is something different,
some value of inner calculations.

So i think there is a bug somewhere with geo-search, so i reported
whole test case to github issues
https://github.com/**elasticsearch/elasticsearch/**issues/1885https://github.com/elasticsearch/elasticsearch/issues/1885

Because if you look at my test case: https://gist.github.com/**
2483009 https://gist.github.com/2483009
You will see that returned "sort" values are almost identical and also
returned sort order is wrong...

Thanks, it is good to know "sort" actually should return distance,
let's hope there is some explanation why problems in my test case appears.

On Tuesday, April 24, 2012 11:01:23 PM UTC+3, Igor Motov wrote:

Take a look at this example: https://gist.github.**com/2483149https://gist.github.com/2483149

The value in the "sort" field is the distance:

  "sort" : [ 114.81801790248922 ]

On Tuesday, April 24, 2012 2:55:58 PM UTC-4, Kaspars Sprogis wrote:

I look at that posting already, and i am already sorting by
_geo_distance but no actual distance value is returned (using latest 0.9.2)

Then only in once place somewhere on stackoverflow i found that we
need to use script_fields to get distance to the results and i am wondering
why in many places it is mentioned that distance should be in results if
you are sorting by _geo_distance if it is not?! Maybe i am doing something
wrong, but i tested thousand times.

Only way i could get distance is like this:

"fields": [
"_source"
],
"script_fields": {
"distance": {
"params": {
"lat": 56.959942,
"lon": 24.113656
},
"script": "doc['location'].**arcDistanceInKm(lat, lon)"
}
}

On Tuesday, April 24, 2012 9:50:07 PM UTC+3, Peter Schröder wrote:

have a look at this posting http://groups.google.**
com/a/elasticsearch.com/group/users/browse_thread/thread/
fab566d2a275456b/**2424d39029721e30?lnk=gst&q=+**distance&pli=1http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias
Nothhaft wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It works
fine so using a filtered query and the geo_distance filter. What I miss in
the search result is the distance between "my location" and each of the
results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Kaspars Sprogis) #12

The problem was not to found the correct guide page, but to notice that in
one place order of arguments differs from usual one (lat,lon, which uses
for storing, also google uses it) so it is very easy to mis-read it.
Yesterday i set up ES docs on ruby, so that i can contribute some guide
updates. Kimchy, do you agree that in place where lat, lon is way around
there should be some visually more noticeable Note element, so that users
really notice these changes? If you agree on that i can do that and
contribute.

On Friday, April 27, 2012 11:57:03 AM UTC+3, kimchy wrote:

Heya, the formatting is specified here for example:
http://www.elasticsearch.org/guide/reference/api/search/sort.html. Its
hard to find, I know..., and to be honest its confusing (the order) for me
as well, it used to be the other way around, but we changed it to match the
geojson spec.

On Wed, Apr 25, 2012 at 7:51 AM, Kaspars Sprogis wrote:

I'll explore how the docs are built and see what i can do. As i already
have all the test data for geo search probably tutorial on geo search could
be a help too. As i did lot of search yesterday, i noticed all the same
questions all around about geo search. As kimchy added support for Latvian
stemming after one day i wrote an issue (which was essential one for us
choosing ES) and released this feature in a week in new version i think i
owe this community some help too :slight_smile:

On Wednesday, April 25, 2012 12:34:35 AM UTC+3, Igor Motov wrote:

I totally agree with you. It's quite confusing. By the way, docs are in
https://github.com/**elasticsearch/elasticsearch.**github.comhttps://github.com/elasticsearch/elasticsearch.github.comCare to submit a pull request? :wink:

On Tuesday, April 24, 2012 5:19:50 PM UTC-4, Kaspars Sprogis wrote:

Wow, thanks. I spent half a day running tests, googling
and finally decided it could be a bug and even reported.
There should be some warning or exclamation marks like "Important
notice"
on docs where it mentions format changes :slight_smile: it too easy to
mis-read lat, lon vs lon, lat.

Thanks a lot.

On Wednesday, April 25, 2012 12:02:44 AM UTC+3, Igor Motov wrote:

Yeah, it's one of these gotchas that many people run into. When you
specify location as an array, it follows GeoJson format [lon, lat], instead
of lat, lon. So, if you will flip the numbers in _geo_distance sort
location, it will work as expected:

"_geo_distance": {
"location": [
24.113656,
56.959942
],
"order": "asc",
"unit": "km"
}

On Tuesday, April 24, 2012 4:19:53 PM UTC-4, Kaspars Sprogis wrote:

Since in my test case all returned "sort" fields were almost
identical (event if distance is different) i decided sort key is something
different, some value of inner calculations.

So i think there is a bug somewhere with geo-search, so i reported
whole test case to github issues
https://github.com/**elasticsearch/elasticsearch/**issues/1885https://github.com/elasticsearch/elasticsearch/issues/1885

Because if you look at my test case: https://gist.github.com/**
2483009 https://gist.github.com/2483009
You will see that returned "sort" values are almost identical and
also returned sort order is wrong...

Thanks, it is good to know "sort" actually should return distance,
let's hope there is some explanation why problems in my test case appears.

On Tuesday, April 24, 2012 11:01:23 PM UTC+3, Igor Motov wrote:

Take a look at this example: https://gist.github.**com/2483149https://gist.github.com/2483149

The value in the "sort" field is the distance:

  "sort" : [ 114.81801790248922 ]

On Tuesday, April 24, 2012 2:55:58 PM UTC-4, Kaspars Sprogis wrote:

I look at that posting already, and i am already sorting by
_geo_distance but no actual distance value is returned (using latest 0.9.2)

Then only in once place somewhere on stackoverflow i found that we
need to use script_fields to get distance to the results and i am wondering
why in many places it is mentioned that distance should be in results if
you are sorting by _geo_distance if it is not?! Maybe i am doing something
wrong, but i tested thousand times.

Only way i could get distance is like this:

"fields": [
"_source"
],
"script_fields": {
"distance": {
"params": {
"lat": 56.959942,
"lon": 24.113656
},
"script": "doc['location'].**arcDistanceInKm(lat, lon)"
}
}

On Tuesday, April 24, 2012 9:50:07 PM UTC+3, Peter Schröder wrote:

have a look at this posting http://groups.google.**
com/a/elasticsearch.com/group/users/browse_thread/thread/
fab566d2a275456b/**2424d39029721e30?lnk=gst&q=+**distance&pli=1http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias
Nothhaft wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It
works fine so using a filtered query and the geo_distance filter. What I
miss in the search result is the distance between "my location" and each of
the results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(Shay Banon) #13

Yes, I definitely agree that it should be noticeable. I thought that it is
(there is a special note in that format).

On Fri, Apr 27, 2012 at 12:03 PM, Kaspars Sprogis darklow@gmail.com wrote:

The problem was not to found the correct guide page, but to notice that in
one place order of arguments differs from usual one (lat,lon, which uses
for storing, also google uses it) so it is very easy to mis-read it.
Yesterday i set up ES docs on ruby, so that i can contribute some guide
updates. Kimchy, do you agree that in place where lat, lon is way around
there should be some visually more noticeable Note element, so that users
really notice these changes? If you agree on that i can do that and
contribute.

On Friday, April 27, 2012 11:57:03 AM UTC+3, kimchy wrote:

Heya, the formatting is specified here for example: http://www.**
elasticsearch.org/guide/**reference/api/search/sort.htmlhttp://www.elasticsearch.org/guide/reference/api/search/sort.html
**. Its hard to find, I know..., and to be honest its confusing (the
order) for me as well, it used to be the other way around, but we changed
it to match the geojson spec.

On Wed, Apr 25, 2012 at 7:51 AM, Kaspars Sprogis wrote:

I'll explore how the docs are built and see what i can do. As i already

have all the test data for geo search probably tutorial on geo search could
be a help too. As i did lot of search yesterday, i noticed all the same
questions all around about geo search. As kimchy added support for Latvian
stemming after one day i wrote an issue (which was essential one for us
choosing ES) and released this feature in a week in new version i think i
owe this community some help too :slight_smile:

On Wednesday, April 25, 2012 12:34:35 AM UTC+3, Igor Motov wrote:

I totally agree with you. It's quite confusing. By the way, docs are in
https://github.com/elasticsearch/elasticsearch.**github.comhttps://github.com/elasticsearch/elasticsearch.github.comCare to submit a pull request? :wink:

On Tuesday, April 24, 2012 5:19:50 PM UTC-4, Kaspars Sprogis wrote:

Wow, thanks. I spent half a day running tests, googling
and finally decided it could be a bug and even reported.
There should be some warning or exclamation marks like "Important
notice"
on docs where it mentions format changes :slight_smile: it too easy to
mis-read lat, lon vs lon, lat.

Thanks a lot.

On Wednesday, April 25, 2012 12:02:44 AM UTC+3, Igor Motov wrote:

Yeah, it's one of these gotchas that many people run into. When you
specify location as an array, it follows GeoJson format [lon, lat], instead
of lat, lon. So, if you will flip the numbers in _geo_distance sort
location, it will work as expected:

"_geo_distance": {
"location": [
24.113656,
56.959942
],
"order": "asc",
"unit": "km"
}

On Tuesday, April 24, 2012 4:19:53 PM UTC-4, Kaspars Sprogis wrote:

Since in my test case all returned "sort" fields were almost
identical (event if distance is different) i decided sort key is something
different, some value of inner calculations.

So i think there is a bug somewhere with geo-search, so i reported
whole test case to github issues
https://github.com/elasticsearch/elasticsearch/**issues/1885https://github.com/elasticsearch/elasticsearch/issues/1885

Because if you look at my test case: https://gist.github.com/**
248300**9 https://gist.github.com/2483009
You will see that returned "sort" values are almost identical and
also returned sort order is wrong...

Thanks, it is good to know "sort" actually should return distance,
let's hope there is some explanation why problems in my test case appears.

On Tuesday, April 24, 2012 11:01:23 PM UTC+3, Igor Motov wrote:

Take a look at this example: https://gist.github.com/2483149https://gist.github.com/2483149

The value in the "sort" field is the distance:

  "sort" : [ 114.81801790248922 ]

On Tuesday, April 24, 2012 2:55:58 PM UTC-4, Kaspars Sprogis wrote:

I look at that posting already, and i am already sorting by
_geo_distance but no actual distance value is returned (using latest 0.9.2)

Then only in once place somewhere on stackoverflow i found that we
need to use script_fields to get distance to the results and i am wondering
why in many places it is mentioned that distance should be in results if
you are sorting by _geo_distance if it is not?! Maybe i am doing something
wrong, but i tested thousand times.

Only way i could get distance is like this:

"fields": [
"_source"
],
"script_fields": {
"distance": {
"params": {
"lat": 56.959942,
"lon": 24.113656
},
"script": "doc['location'].arcDistanceInKm(lat, lon)"
}
}

On Tuesday, April 24, 2012 9:50:07 PM UTC+3, Peter Schröder wrote:

have a look at this posting http://groups.google.c
om/a/elasticsearch.com/group/users/browse_thread/thread/**
fab5**66d2a275456b/**2424d39029721e30?lnk=gst&q=+
distance&pli=1http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/fab566d2a275456b/2424d39029721e30?lnk=gst&q=+distance&pli=1

Am Dienstag, 24. April 2012 19:51:59 UTC+2 schrieb Kaspars
Sprogis:

I am also interested in this. Can anyone help? Thanks

On Wednesday, September 7, 2011 6:58:47 PM UTC+3, Matthias
Nothhaft wrote:

Hi,

I'm trying to use elasticsearch for geo location search. It
works fine so using a filtered query and the geo_distance filter. What I
miss in the search result is the distance between "my location" and each of
the results. Is it possible somehow to add the distance to the result? Can
someone give me an example or point me to some docs how to make it?

regards,
Matthias


(system) #14