OData $select syntax in Azure Cognitive Search
You can use the OData $select parameter to choose which fields to include in search results from Azure Cognitive Search. This article describes the syntax of $select in detail. For more general information about how to use $select when presenting search results, see How to work with search results in Azure Cognitive Search.
Syntax
The $select parameter determines which fields for each document are returned in the query result set. The following EBNF (Extended Backus-Naur Form) defines the grammar for the $select parameter:
select_expression ::= '*' | field_path(',' field_path)*
field_path ::= identifier('/'identifier)*
An interactive syntax diagram is also available:
Note
See OData expression syntax reference for Azure Cognitive Search for the complete EBNF.
The $select parameter comes in two forms:
- A single star (
*), indicating that all retrievable fields should be returned, or - A comma-separated list of field paths, identifying which fields should be returned.
When using the second form, you may only specify retrievable fields in the list.
If you list a complex field without specifying its sub-fields explicitly, all retrievable sub-fields will be included in the query result set. For example, assume your index has an Address field with Street, City, and Country sub-fields that are all retrievable. If you specify Address in $select, the query results will include all three sub-fields.
Examples
Include the HotelId, HotelName, and Rating top-level fields in the results, as well as the City sub-field of Address:
$select=HotelId, HotelName, Rating, Address/City
An example result might look like this:
{
"HotelId": "1",
"HotelName": "Secret Point Motel",
"Rating": 4,
"Address": {
"City": "New York"
}
}
Include the HotelName top-level field in the results, as well as all sub-fields of Address, and the Type and BaseRate sub-fields of each object in the Rooms collection:
$select=HotelName, Address, Rooms/Type, Rooms/BaseRate
An example result might look like this:
{
"HotelName": "Secret Point Motel",
"Rating": 4,
"Address": {
"StreetAddress": "677 5th Ave",
"City": "New York",
"StateProvince": "NY",
"Country": "USA",
"PostalCode": "10022"
},
"Rooms": [
{
"Type": "Budget Room",
"BaseRate": 9.69
},
{
"Type": "Budget Room",
"BaseRate": 8.09
}
]
}
Next steps
Tilbakemeldinger
Send inn og vis tilbakemelding for