Stay organized with collections
Save and categorize content based on your preferences.
This page explains how to order the results of a search query made on structured
data stores and on unstructured data stores with metadata.
Supported data types for ordering the results
These are the field types that you can have your search results ordered by:
string
number
datetime
geolocation
Before you begin
Make sure that you have an app with a data store that contains structured data
or unstructured data with metadata.
Order your search results
To order the search results for a structured data store or for an unstructured
data store with metadata, follow these steps:
REST
To use the API to order your search results for an app with structured data or
unstructured data with metadata,
use the engines.servingConfigs.search method:
Find your app ID. If you already have your app ID, skip to the next step.
In the Google Cloud console, go to the Agentspace page.
ORDER_BY: the order in which the results are arranged. The
default sort order is ascending. For example, specifying date
returns results from the oldest to the newest. To get descending sort
order, append desc to the date value—for example,
date desc. For more examples, see orderBy examples.
In this example, the documents that contain the word "hotel" are ordered by
rating, from the Serenity Springs Hotel with a 4.6 rating to the Ocean Breeze
Hotel with a 4.1 rating.
orderBy examples
To order on a string field called title:
"orderBy": "title" to return the documents in ascending alphabetic order
according to title.
"orderBy": "title desc" to return the documents sorted in reverse
alphabetic order (from Z to A) according to the title.
To order on a number field called rating:
"orderBy": "rating" to order from the lowest to the highest rated
documents.
"orderBy": "rating desc" to order from the highest to the lowest rated
documents.
To order on a datetime field called available_date:
"orderBy": "available_date" to order from the soonest available document
to the farthest out.
"orderBy": "available_date desc" to order from the document with the
farthest out available date to the one soonest available.
To order according to geolocation on a field called location:
"orderBy": "GEO_DISTANCE(location, \"Mountain View, CA\")" sorts the
documents in order from those nearest to Mountain View to
those farthest from Mountain View.
"orderBy": "GEO_DISTANCE(location, 37.38, -122.08) desc" sorts the
documents in order from farthest to nearest to the location 37.38°N and
122.08°W.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-05 UTC."],[[["This feature allows users to order search results from both structured and unstructured data stores with metadata using the `engines.servingConfigs.search` API method."],["Search results can be ordered by `string`, `number`, `datetime`, or `geolocation` field types, enabling sorting based on criteria like title, rating, availability, or distance."],["The `orderBy` field within the API request can be used to specify the sorting field and direction, with options for both ascending (default) and descending order by appending `desc`."],["Geolocation-based sorting is supported, allowing results to be ordered by their distance from a specified location, either by address or latitude/longitude coordinates."],["The API call example demonstrates how to make a search query and order results, returning a set of results sorted by rating in descending order, from highest to lowest."]]],[]]