question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support for _geo_distance sorting

See original GitHub issue

Hi guys, First of all thanks for the library… really nice one.

I cannot find a way to do the geo_distance sorting https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-request-sort.html#geo-sorting

Anything I am missing? or is not supported in the current version?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
up73kcommented, Oct 3, 2019

Another corner case like in this topic it is script based sorting https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#_script_based_sorting

Please add “_script” like “_geo_distance”.

0reactions
ferronrsmithcommented, Oct 3, 2019
bodybuilder()
  .rawOption('sort', [{
      "_script": {
        "type": "number",
        "script": {
          "lang": "painless",
          "source": "doc['field_name'].value * params.factor",
          "params": {
            "factor": 1.1
          }
        },
        "order": "asc"
      }
    },
    {
      "_geo_distance": {
        "a.pin.location": [-70, 40],
        "order": "asc",
        "unit": "km",
        "mode": "min",
        "distance_type": "sloppy_arc"
      }
    },
    {
      "_geo_distance": {
        "b.pin.location": [-70, 40],
        "order": "asc",
        "unit": "km",
        "mode": "min",
        "distance_type": "sloppy_arc"
      }
    }
  ])
  .sort([{
      "categories": "desc"
    },
    {
      "content": "asc"
    }
  ])
  .build()

=>

{
  "sort": [
    {
      "_script": {
        "type": "number",
        "script": {
          "lang": "painless",
          "source": "doc['field_name'].value * params.factor",
          "params": {
            "factor": 1.1
          }
        },
        "order": "asc"
      }
    },
    {
      "_geo_distance": {
        "a.pin.location": [
          -70,
          40
        ],
        "order": "asc",
        "unit": "km",
        "mode": "min",
        "distance_type": "sloppy_arc"
      }
    },
    {
      "_geo_distance": {
        "b.pin.location": [
          -70,
          40
        ],
        "order": "asc",
        "unit": "km",
        "mode": "min",
        "distance_type": "sloppy_arc"
      }
    },
    {
      "categories": {
        "order": "desc"
      }
    },
    {
      "content": {
        "order": "asc"
      }
    }
  ]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Support for many-to-many geo distance sort · Issue #3926
What we'd like to see: Ability to specify many geo points in geo distance sort, like this: { "sort": [ { "_geo_distance": ...
Read more >
Geo_point sort by distance - Elasticsearch - Elastic Discuss
I would like to know what would be the best way to perform a search and performing a sorting by distance, today _geo_distance...
Read more >
Elasticsearch geo distance sorting not exactly / wrong order
The results should be sorted by distance. My search query works, but the order of the results is not correct. The results should...
Read more >
Efficient sorting of geo distances in Elasticsearch - Bonsai.io
Here's more info on the efficient sorting of geo distances in elasticsearch, helping you calculate the distance between geographic points.
Read more >
RE: Geodistance sorting in liferay DXP - Forums
Hi everyone, I am trying to sort the contents, based on their geolocations. I am trying this as following: GeoDistanceSort distanceSort = new ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found