# Sorting results using properties within a search

**URL:** <https://forum.weaviate.io/t/sorting-results-using-properties-within-a-search/10042>\
**Category:** Support\
**Tags:** integration, python, documentation\
**Created:** [February 7, 2025, 6:01pm UTC](https://forum.weaviate.io/t/sorting-results-using-properties-within-a-search/10042 "2025-02-07T18:01:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-barhouch](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/joe-barhouch/32/3498_2.png) [@joe-barhouch](https://forum.weaviate.io/u/joe-barhouch)\
**Post date:** [February 7, 2025, 6:01pm UTC](https://forum.weaviate.io/t/sorting-results-using-properties-within-a-search/10042/1 "2025-02-07T18:01:04Z")

</div>

Hello all,  
I’m using client v4, and i have added some documents as i usually do with no trouble.

This time around i have added a ‘release\_date’ property to my documents (i’m using Langchain, this is the Document Metadata which i believe is the object property here)  
I need to execute a similarity search using near\_text, but I also want to rank or sort my results using the relase\_date property so I can get the latest results first.

The sorting API seems like can only be included with fetch\_objects, and not near\_text or hybrid. So it’s no possible to search my db and sort the results

Doing something like:

```auto
collection.query.near_text(
    ...: query="test query",
    ...: limit=25,
    ...: return_metadata=MetadataQuery(distance=True),
    ...: sort=Sort.by_property(name='release_date', ascending=False)
    ...: )

```

This results in an error:  
`_NearTextQueryAsync.near_text() got an unexpected argument 'sort' `

Is it not possible to search with sorting?

Thanks

---

<div class="post-metadata">

**Author:** ![Shahin](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/shahin/32/7944_2.png) [@Shahin](https://forum.weaviate.io/u/Shahin)\
**Post date:** [February 10, 2025, 9:46am UTC](https://forum.weaviate.io/t/sorting-results-using-properties-within-a-search/10042/2 "2025-02-10T09:46:51Z")

</div>

**Good morning @joe-barhouch,**

Welcome to our community—it’s great to have you here!

Sorting isn’t **directly available** with vector searches. But you can use the **rerank** feature to kinda “sort” the results. I’m also looking into **improving the documentation** to clarify about sorting further so it does not cause confusion.

It’s important to note that **rerank** works **after** the initial search, meaning it **doesn’t sort the entire dataset** but instead **reorders the search results** based on relevance. However, it should still provide a **reasonable approximation** for sorting by attributes.

Regards,  
Mohamed Shahin  
Weaviate Support

---

<div class="post-metadata">

**Author:** ![sebawita](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/sebawita/32/5_2.png) [@sebawita](https://forum.weaviate.io/u/sebawita)\
**Post date:** [February 10, 2025, 11:36am UTC](https://forum.weaviate.io/t/sorting-results-using-properties-within-a-search/10042/3 "2025-02-10T11:36:05Z")

</div>

Rerank might be an overkill for sorting by date.

Maybe you could sort the result objects in python, like this:

```python
result = temp.query.near_text(
  query="test query",
  limit=25,
  return_metadata=MetadataQuery(distance=True),
)

sorted_results = sorted(result.objects, key=lambda x: x.properties["release_date"], reverse=True)

for item in sorted_results:
    print(item.properties)

```

---

<div class="post-metadata">

**Author:** ![joe-barhouch](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/joe-barhouch/32/3498_2.png) [@joe-barhouch](https://forum.weaviate.io/u/joe-barhouch)\
**Post date:** [February 10, 2025, 3:31pm UTC](https://forum.weaviate.io/t/sorting-results-using-properties-within-a-search/10042/4 "2025-02-10T15:31:43Z")

</div>

Thank you @Shahin and @sebawita

I agree with you guys, i ended up sorting the results after the search using something similar to what was showcased.

Thank you for considering updating the documentation. I think it’s important to see more relevant examples of what and how the additional operators work. The doc is good for now but it’s sometimes difficult to understand exactly what’s going on.

Additionally, the Ask Documentation bot you guys have is helpful, but it will mix details from client v3 and client v4 which just gives completely wrong answers. I tried to use it to get some form of reranking working, but the implementation given was wrong (but that’s not related to this task only)
