Sorting search results
You can sort search results by one or multiple properties.
You can sort any number of results; however, if you plan to page through more than 100,000 total results you can't specify any sort order.
- Java
- Python
- Kotlin
- Raw REST API
SortOptions byUpdate = Asset.UPDATE_TIME.order(SortOrder.Desc); // (1)
SortOptions byCreation = Asset.CREATE_TIME.order(SortOrder.Asc); // (2)
-
For each property you can specify whether to sort the results in
descending order orascending order. In this example our first results would be the ones changed most recently.Equivalent sort option from ElasticSortOptions byUpdate = SortOptions.of(s -> s
.field(FieldSort.of(f -> f // (1)
.field("__modificationTimestamp")
.order(SortOrder.Desc)))); -
In this example, our first results would be the oldest ones (based on when they were created).
Equivalent sort option from ElasticSortOptions byCreation = SortOptions.of(s -> s
.field(FieldSort.of(f -> f // (2)
.field("__timestamp")
.order(SortOrder.Asc))));
IndexSearchRequest index = client.assets.select()
.where(...) // (1)
.sort(byUpdate) // (2)
.sort(byCreation) // (3)
.toRequest();
- You still need a query, to get some results to sort.
- Note that the sort itself is an array—hence we can add multiple sort options and they'll be evaluated in order (to sort by multiple properties). In this example our first results would be the ones changed most recently.
- For any results that have identical modification dates, we would then sort within those results to present the oldest (created) results first.
IndexSearchResponse response = index.search(client);
for (Asset result : response)
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.enums import SortOrder
from pyatlan.model.assets import Referenceable
from pyatlan.model.search import IndexSearchRequest, DSL
by_update = Referenceable.UPDATE_TIME.order(SortOrder.DESCENDING) # (1)
by_creation = Referenceable.CREATE_TIME.order(SortOrder.ASCENDING) # (2)
- For each property you can specify whether to sort the results in descending order or ascending order. In this example our first results would be the ones changed most recently.
- In this example, our first results would be the oldest ones (based on when they were created).
index = (
FluentSearch()
.where(...) # (1)
.sort(by_update) # (2)
.sort(by_creation) # (3)
).to_request()
- You still need a query, to get some results to sort.
- Note that the sort itself is an array—hence we can add multiple sort options and they'll be evaluated in order (to sort by multiple properties). In this example our first results would be the ones changed most recently.
- For any results that have identical modification dates, we would then sort within those results to present the oldest (created) results first.
client = AtlanClient();
response = client.asset.search(index)
for result in response:
# Do something with the ordered results...
val byUpdate = Asset.UPDATE_TIME.order(SortOrder.Desc) // (1)
val byCreation = Asset.CREATE_TIME.order(SortOrder.Asc) // (2)
-
For each property you can specify whether to sort the results in
descending order orascending order. In this example our first results would be the ones changed most recently.Equivalent sort option from Elasticval byUpdate = SortOptions.of(s -> s
.field(FieldSort.of(f -> f // (1)
.field("__modificationTimestamp")
.order(SortOrder.Desc)))) -
In this example, our first results would be the oldest ones (based on when they were created).
Equivalent sort option from Elasticval byCreation = SortOptions.of(s -> s
.field(FieldSort.of(f -> f // (2)
.field("__timestamp")
.order(SortOrder.Asc))))
val index = client.assets.select()
.where(...) // (1)
.sort(byUpdate) // (2)
.sort(byCreation) // (3)
.toRequest()
- You still need a query, to get some results to sort.
- Note that the sort itself is an array—hence we can add multiple sort options and they'll be evaluated in order (to sort by multiple properties). In this example our first results would be the ones changed most recently.
- For any results that have identical modification dates, we would then sort within those results to present the oldest (created) results first.
val response = index.search(client)
for (result in response)
{
"dsl": {
"query": {...}, // (1)
"sort": [ // (2)}, // (3)} // (4)
]
}
}
- You still need a query, to get some results to sort.
- Note that the sort itself is an array—hence you can sort by multiple properties.
- For each property you can specify whether to sort the results in
descending order orascending order. In this example our first results would be the ones changed most recently. - For any results that have identical modification dates, we would then sort within those results to present the oldest (created) results first.
The examples above should cover most scenarios. If you want to get fancy, see Elastic's documentation on sorting.