I would like to know what would be the best way to perform a search and performing a sorting by distance, today _geo_distance filters and does not sort. What would be the best solution in which you need to perform two "should" queries and return sorted by distance.
This api of the sort "_geo_distance" does not sort but filters in all the tests I performed, I would like to perform the search in the fields informed in the search and sort by the search results.
What do you mean with filter? Could you provide an example? I would expect that the query bellow would apply the geo_distance and match filters and then it would sort those result by distance:
I'd also recommend filtering a bit by distance first.
I mean that if you have 10 million documents matching santa marta, it means that you have to sort 10 million points. That could take some time.
I did not test recently with all the optimizations that went into the geo part, but my experience has been to add a geo filter as well to narrow down the number of documents to sort on.
For example, if you know that you are not going to give results which are more than 10km away from -54.43,-27.87, you can add a filter of 10km range around this point.
This is what I described in this blog post. Have a look at " Searching by Geo Point" part.
HTH. @Ignacio_Vera correct me if this is not needed anymore with some internal optimizations.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.