# Search by GeoDistance(DESC) and another field "created\_date"(DESC)

**URL:** <https://discuss.elastic.co/t/search-by-geodistance-desc-and-another-field-created-date-desc/229686>\
**Category:** Elasticsearch\
**Created:** [April 24, 2020, 3:47pm UTC](https://discuss.elastic.co/t/search-by-geodistance-desc-and-another-field-created-date-desc/229686 "2020-04-24T15:47:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edgar\_Adrian\_Munoz\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edgar_adrian_munoz_m/32/51479_2.png) [@Edgar\_Adrian\_Munoz\_M](https://discuss.elastic.co/u/Edgar_Adrian_Munoz_M)\
**Post date:** [April 24, 2020, 3:47pm UTC](https://discuss.elastic.co/t/search-by-geodistance-desc-and-another-field-created-date-desc/229686/1 "2020-04-24T15:47:00Z")

</div>

Hi, I'm doing a search that will return to me through the location of the closest point to the furthest point. And to that include the date of creation from the most current to the oldest

I am using the REST API

```auto
searchSourceBuilder.sort(new FieldSortBuilder("created_at").order(SortOrder.DESC));
searchSourceBuilder.sort(new GeoDistanceSortBuilder("location",geoPoint).sortMode(SortMode.MIN).order(SortOrder.DESC));

```

But doesnt work

---

<div class="post-metadata">

**Author:** ![Edgar\_Adrian\_Munoz\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edgar_adrian_munoz_m/32/51479_2.png) [@Edgar\_Adrian\_Munoz\_M](https://discuss.elastic.co/u/Edgar_Adrian_Munoz_M)\
**Post date:** [April 24, 2020, 4:10pm UTC](https://discuss.elastic.co/t/search-by-geodistance-desc-and-another-field-created-date-desc/229686/2 "2020-04-24T16:10:56Z")

</div>

Btw I test with this curl but i dont kwon its the same of the API REST

```auto
curl -X GET "http://localhost:5443/index/_doc/_search" -H 'Content-Type: application/json' -d'
{
    "sort" : [
        {
            "_geo_distance" : {
                "location" : [-99.20600069999999,19.6149315],
                "order": "asc",
                "mode": "min"
            }
        },
        {"created_at" : {"order" : "desc"}}
    ],
	"size": 150
}
'

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 22, 2020, 4:10pm UTC](https://discuss.elastic.co/t/search-by-geodistance-desc-and-another-field-created-date-desc/229686/3 "2020-05-22T16:10:59Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
