Skip to content

Instantly share code, notes, and snippets.

@mschoch
Created May 4, 2017 19:08
Show Gist options
  • Save mschoch/141ec863fecd8e3ac29fe78c426002c3 to your computer and use it in GitHub Desktop.
Save mschoch/141ec863fecd8e3ac29fe78c426002c3 to your computer and use it in GitHub Desktop.

The simple case of sorting by a field:

      "sort": ["born"]

Equivalent way of sorting, using the object form.

      "sort": [
        {
          "by": "field",
          "field": "born",
          "missing": "first",
          "desc": false
        }
      ]

Mixing the two:

      "sort": [
        "name",
        {
          "by": "field",
          "field": "born",
          "missing": "first",
          "desc": false
        }
      ]

Sorting by geo distance:

      "sort": [
        {
          "by": "geo_distance",
          "field": "geo",
          "unit": "mi",
          "location": {
            "lon": -122.107799,
            "lat": 37.399285
          }
        }
      ]

Mixing geo distance with score and another field, _score uses string, other field uses object.

      "sort": [
        "-_score",
        {
          "by": "field",
          "field": "born",
          "missing": "first",
          "desc": false
        },
        {
          "by": "geo_distance",
          "field": "geo",
          "unit": "mi",
          "location": {
            "lon": -122.107799,
            "lat": 37.399285
          }
        }
      ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment