OData $select syntax in Azure AI Search

In Azure AI Search, the $select parameter specifies which fields to include in search results. This article describes the OData syntax of $select and provides examples.

Field path construction and constants are described in the OData language overview in Azure AI Search. For more information about search result composition, see How to work with search results in Azure AI 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:

The $select parameter comes in two forms:

  1. A single star (*), indicating that all retrievable fields should be returned, or
  2. 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 subfields explicitly, all retrievable subfields will be included in the query result set. For example, assume your index has an Address field with Street, City, and Country subfields that are all retrievable. If you specify Address in $select, the query results will include all three subfields.

Examples

Include the HotelId, HotelName, and Rating top-level fields in the results, and include the City subfield 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": "Beijing"
  }
}

Include the HotelName top-level field in the results. Include all subfields of Address. Include the Type and BaseRate subfields 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": "Beijing",
    "StateProvince": "NY",
    "Country": "USA",
    "PostalCode": "10022"
  },
  "Rooms": [
    {
      "Type": "Budget Room",
      "BaseRate": 9.69
    },
    {
      "Type": "Budget Room",
      "BaseRate": 8.09
    }
  ]
}

Next steps