title: In elasticsearch, how to group results by location proximity?
body: <p>I have a bunch of documents with a location field, and for a given search query with given coordinates, I would like to group results by whether their location is within 25 miles of the given coordinates. However within each group I would like the results sorted not by location proximity. Is there any elegant way to do this?</p>
  
  <p>As an example, imagine I have the following documents:</p>
  
  <pre><code>[
    { id: "1", price: 13.5, coords: $c1 },
    { id: "2", price: 10, coords: $c2 },
    { id: "3", price: 15, coords: $c3 },
    { id: "4", price: 5, coords: $c4 },
    { id: "5", price: 1, coords: $c5 },
  ]
  </code></pre>
  
  <p>where $c1, $c2, $c3 are within 25 miles of $c, and $c4, $c5 are farther than 25 miles from $c. The order by proximity to $c is $c3, $c2, $c1, $c5, $c4. When handling a query of sorting by price low to high, I would like to return as</p>
  
  <pre><code>[
    [
      { id: "2", price: 10, coords: $c2 },
      { id: "1", price: 13.5, coords: $c1 },
      { id: "3", price: 15, coords: $c3 },
    ],
    [
      { id: "5", price: 1, coords: $c5 },
      { id: "4", price: 5, coords: $c4 },
    ]
  ]
  </code></pre>