Skip to content

Commit 8dbb869

Browse files
committed
Updated REST and PowerShell pivots
1 parent 88c35dc commit 8dbb869

File tree

3 files changed

+86
-65
lines changed

3 files changed

+86
-65
lines changed

articles/search/includes/quickstarts/full-text-intro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ author: haileytap
44
ms.author: haileytapia
55
ms.service: azure-ai-search
66
ms.topic: include
7-
ms.date: 06/23/2025
7+
ms.date: 06/26/2025
88
---
99

1010
In this quickstart, you use the Azure.Search.Documents client library to create, load, and query a search index with sample data for [full-text search](../../search-lucene-query-architecture.md). Full-text search uses Apache Lucene for indexing and queries and the BM25 ranking algorithm for scoring results.
1111

12-
This quickstart creates and queries a small index containing data about four fictional hotels.
12+
This quickstart uses fictional hotel data from the [azure-search-sample-data](https://github.com/Azure-Samples/azure-search-sample-data/tree/main/hotels/hotel-json-documents) repo to populate the index.

articles/search/includes/quickstarts/full-text-powershell.md

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.date: 06/26/2025
99

1010
In this quickstart, you use PowerShell and the [Azure AI Search REST APIs](/rest/api/searchservice/) to create, load, and query a search index for [full-text search](../../search-lucene-query-architecture.md). Full-text search uses Apache Lucene for indexing and queries and the BM25 ranking algorithm for scoring results.
1111

12-
This quickstart creates and queries a small index containing data about four fictional hotels.
12+
This quickstart uses fictional hotel data from the [azure-search-sample-data](https://github.com/Azure-Samples/azure-search-sample-data/tree/main/hotels/hotel-json-documents) repo to populate the index.
1313

1414
> [!TIP]
1515
> You can download the [source code](https://github.com/Azure-Samples/azure-search-powershell-samples/tree/main/Quickstart) to start with a finished project or follow these steps to create your own.
@@ -22,7 +22,7 @@ This quickstart creates and queries a small index containing data about four fic
2222

2323
+ The [Azure CLI](/cli/azure/install-azure-cli) for keyless authentication with Microsoft Entra ID.
2424

25-
+ [PowerShell 7.3](https://github.com/PowerShell/PowerShell) or later. This quickstart uses the [Invoke-RestMethod](/powershell/module/Microsoft.PowerShell.Utility/Invoke-RestMethod) cmdlet to make REST API calls.
25+
+ [PowerShell 7.3](https://github.com/PowerShell/PowerShell) or later. This quickstart uses [Invoke-RestMethod](/powershell/module/Microsoft.PowerShell.Utility/Invoke-RestMethod) to make REST API calls.
2626

2727
## Configure access
2828

@@ -46,37 +46,35 @@ To configure the recommended role-based access:
4646

4747
For more information, see [Connect to Azure AI Search using roles](../../search-security-rbac.md).
4848

49-
## Get resource name
49+
## Get endpoint
5050

5151
In the next section, you specify the following endpoint to establish a connection to your Azure AI Search service. These steps assume that you [configured role-based access](#configure-access).
5252

53-
To get your resource name:
53+
To get your service endpoint:
5454

5555
1. Sign in to the [Azure portal](https://portal.azure.com/) and select your search service.
5656

5757
1. From the left pane, select **Overview**.
5858

59-
1. Take note of the name before `.search.windows.net` in the URL, such as `my-service` in `https://my-service.search.windows.net`.
59+
1. Make a note of the URL, which should be similar to `https://my-service.search.windows.net`.
6060

6161
## Connect to Azure AI Search
6262

63-
Before you can make REST API calls to Azure AI Search, you must authenticate and connect to your search service.
64-
65-
You start by using the Azure CLI to sign in to Azure and obtain your Microsoft Entra token. You then configure the HTTP header and service URL used in subsequent requests. To maintain authentication throughout this quickstart, all of these commands are run in the same PowerShell session.
63+
Before you can make REST API calls to your Azure AI Search service, you must authenticate and connect to the service. You perform the following steps in PowerShell, which supports the Azure CLI commands used in steps two and three.
6664

6765
To connect to your search service:
6866

6967
1. On your local system, open PowerShell.
7068

7169
1. Sign in to your Azure subscription. If you have multiple subscriptions, select the one that contains your search service.
7270

73-
```powershell
71+
```azurecli
7472
az login
7573
```
7674
7775
1. Create a `$token` object to store your access token.
7876
79-
```powershell
77+
```azurecli
8078
$token = az account get-access-token --resource https://search.azure.com/ --query accessToken --output tsv
8179
```
8280
@@ -91,10 +89,10 @@ To connect to your search service:
9189
9290
You only need to set the header once per session, but you must add it to each request.
9391
94-
1. Create a `$url` object that targets the indexes collection on your search service. Replace `<YOUR-SEARCH-SERVICE>` with the value you obtained in [Get resource name](#get-resource-name).
92+
1. Create a `$url` object that targets the indexes collection on your search service. Replace `<YOUR-SEARCH-SERVICE>` with the value you obtained in [Get endpoint](#get-endpoint).
9593
9694
```powershell
97-
$url = "https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes?api-version=2024-07-01&`$select=name"
95+
$url = "<YOUR-SEARCH-SERVICE>/indexes?api-version=2024-07-01&`$select=name"
9896
```
9997
10098
1. Run `Invoke-RestMethod` to send a GET request to your search service and verify the connection. Include `ConvertTo-Json` to view responses from the service.
@@ -116,13 +114,13 @@ To connect to your search service:
116114
117115
## Create, load, and query a search index
118116
119-
In this section, you run PowerShell commands to create a search index, upload documents to the index, and query the indexed documents. Responses to the `Invoke-RestMethod` commands are displayed in the PowerShell console. For more information about each step, see [Explaining the code](#explaining-the-code).
117+
In this section, you make REST API calls to create a search index, upload documents to the index, and query the indexed documents. Responses to `Invoke-RestMethod` are displayed in the PowerShell console. For more information about each step, see [Explaining the code](#explaining-the-code).
120118
121-
For each command that updates the `$url` object, replace `<YOUR-SEARCH-SERVICE>` with the value you obtained in [Get resource name](#get-resource-name).
119+
Run the following commands in the same PowerShell session you started in the previous section. For each command that updates the `$url` object, replace `<YOUR-SEARCH-SERVICE>` with the value you obtained in [Get endpoint](#get-endpoint).
122120
123121
To create, load, and query an index:
124122
125-
1. Define the index schema in a `$body` object.
123+
1. Create a `$body` object to define the index schema.
126124
127125
```powershell
128126
$body = @"
@@ -154,18 +152,18 @@ To create, load, and query an index:
154152
1. Update the `$url` object to target the new index.
155153
156154
```powershell
157-
$url = "https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes/hotels-quickstart?api-version=2024-07-01"
155+
$url = "<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart?api-version=2024-07-01"
158156
```
159157
160-
1. Run `Invoke-RestMethod` with `$url`, `$headers`, and `$body` to create the index on your search service.
158+
1. Run `Invoke-RestMethod` to create the index on your search service.
161159
162160
```powershell
163161
Invoke-RestMethod -Uri $url -Headers $headers -Method Put -Body $body | ConvertTo-Json
164162
```
165163
166164
The response should contain the JSON representation of the index schema.
167165
168-
1. Create a `$body` object that contains sample documents to upload to your index.
166+
1. Create a `$body` object to store the JSON payload of four sample documents.
169167
170168
```powershell
171169
$body = @"
@@ -195,7 +193,7 @@ To create, load, and query an index:
195193
"HotelId": "2",
196194
"HotelName": "Old Century Hotel",
197195
"Description": "The hotel is situated in a nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts. The hotel also regularly hosts events like wine tastings, beer dinners, and live music.",
198-
"Category": "Boutique",
196+
"Category": "Boutique",
199197
"Tags": [ "pool", "free wifi", "concierge" ],
200198
"ParkingIncluded": false,
201199
"LastRenovationDate": "2019-02-18T00:00:00Z",
@@ -233,6 +231,7 @@ To create, load, and query an index:
233231
"HotelId": "4",
234232
"HotelName": "Sublime Palace Hotel",
235233
"Description": "Sublime Palace Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 19th century resort, updated for every modern convenience.",
234+
"Category": "Boutique",
236235
"Tags": [ "concierge", "view", "air conditioning" ],
237236
"ParkingIncluded": true,
238237
"LastRenovationDate": "2020-02-06T00:00:00Z",
@@ -254,34 +253,34 @@ To create, load, and query an index:
254253
1. Update the `$url` object to target the `docs/index` endpoint of your index.
255254
256255
```powershell
257-
$url = "https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes/hotels-quickstart/docs/index?api-version=2024-07-01"
256+
$url = "<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart/docs/index?api-version=2024-07-01"
258257
```
259258
260-
1. Run `Invoke-RestMethod` with `$url`, `$headers`, and `$body` to upload the documents to your index.
259+
1. Run `Invoke-RestMethod` to upload the documents to your index.
261260
262261
```powershell
263262
Invoke-RestMethod -Uri $url -Headers $headers -Method Post -Body $body | ConvertTo-Json
264263
```
265264
266265
The response should contain the key and status of each uploaded document.
267266
268-
1. Update the `$url` object to target the `docs` endpoint of your index and specify a query string in a `search` parameter.
267+
1. Update the `$url` object to target the `docs` endpoint of your index and specify a query.
269268
270269
```powershell
271-
$url = 'https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=*&$count=true'
270+
$url = '<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=attached restaurant&searchFields=Description,Tags&$select=HotelId,HotelName,Tags,Description&$count=true'
272271
```
273272
274-
1. Run `Invoke-RestMethod` with `$url` and `$headers` to query the documents in your index.
273+
1. Run `Invoke-RestMethod` to query the documents in your index.
275274
276275
```powershell
277276
Invoke-RestMethod -Uri $url -Headers $headers | ConvertTo-Json
278277
```
279278
280-
The response should contain the total count of documents and an array of the documents themselves.
279+
The response should contain the document that matched your query, its relevance score, and its selected fields.
281280
282281
## Explaining the code
283282
284-
This section explains the PowerShell commands that you ran to:
283+
This section explains the REST API calls that you made to:
285284
286285
+ [Create an index](#create-an-index)
287286
+ [Load documents into the index](#load-documents-into-the-index)
@@ -319,7 +318,7 @@ $body = @"
319318
}
320319
"@
321320
322-
$url = "https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes/hotels-quickstart?api-version=2024-07-01"
321+
$url = "<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart?api-version=2024-07-01"
323322
```
324323

325324
Within our index schema, the `fields` collection defines the structure of hotel documents. Each field has a `name`, data `type`, and attributes that determine its behavior during indexing and queries. The `HotelId` field is marked as the key, which Azure AI Search requires to uniquely identify each document in an index.
@@ -336,9 +335,9 @@ Key points about the index schema:
336335

337336
Newly created indexes are empty. To populate an index and make it searchable, you must upload JSON documents that conform to the index schema.
338337

339-
In Azure AI Search, documents serve as both inputs for indexing and outputs for queries. For simplicity, this quickstart provides sample hotel documents as inline JSON. In production scenarios, however, content is typically pulled from connected data sources and transformed into JSON using [indexers](../../search-indexer-overview.md).
338+
In Azure AI Search, documents serve as both inputs for indexing and outputs for queries. For simplicity, this quickstart provides sample hotel documents as inline JSON. In production scenarios, however, content is often pulled from connected data sources and transformed into JSON using [indexers](../../search-indexer-overview.md).
340339

341-
This quickstart calls [Documents - Index (REST API)](/rest/api/searchservice/documents/index) to add four sample hotel documents to your index.
340+
This quickstart calls [Documents - Index (REST API)](/rest/api/searchservice/documents/) to add four sample hotel documents to your index.
342341

343342
```powershell
344343
$body = @"
@@ -368,45 +367,65 @@ $body = @"
368367
}
369368
"@
370369
371-
$url = "https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes/hotels-quickstart/docs/index?api-version=2024-07-01"
370+
$url = "<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart/docs/index?api-version=2024-07-01"
372371
```
373372

374373
Each document in the `value` array represents a hotel and contains fields that match the index schema. The `@search.action` parameter specifies the operation to perform for each document. Our example uses `upload`, which adds the document if it doesn't exist or updates the document if it does exist.
375374

376375
### Query the index
377376

378-
Now that documents are loaded into the index, you can issue full-text queries against them using PowerShell commands.
377+
Now that documents are loaded into your index, you can issue full-text queries against them.
379378

380-
This quickstart calls [Documents - Search Post (REST API)](/rest/api/searchservice/documents/search-post) to find hotel documents in your index based on the search criteria.
379+
This quickstart calls [Documents - Search Post (REST API)](/rest/api/searchservice/documents/search-post) to find hotel documents that match your search criteria.
381380

382381
```powershell
383-
$url = 'https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=*&$count=true'
382+
$url = '<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=attached restaurant&searchFields=Description,Tags&$select=HotelId,HotelName,Tags,Description&$count=true'
384383
```
385384

386-
Full-text search requests always include a `search` parameter that contains the query text. The query text can include one or more terms, phrases, or operators. You can also specify parameters to refine the search behavior and results.
385+
Full-text search requests always include a `search` parameter that contains the query text. The query text can include one or more terms, phrases, or operators. In addition to `search`, you can specify other parameters to refine the search behavior and results.
386+
387+
Our query searches for the terms "attached restaurant" in the `Description` and `Tags` fields of each hotel document. The `$select` parameter limits the fields returned in the response to `HotelId`, `HotelName`, `Tags`, and `Description`. The `$count` parameter requests the total number of matching documents.
388+
389+
The response should be similar to the following example, which shows one matching hotel document, its relevance score, and its selected fields.
387390

388-
Our example performs an empty search (`search=*`) that returns all documents in the index. The `$count=true` parameter includes the total number of matching documents in the response.
391+
```
392+
{
393+
"@odata.context": "https://my-service.search.windows.net/indexes('hotels-quickstart')/$metadata#docs(*)",
394+
"@odata.count": 1,
395+
"value": [
396+
{
397+
"@search.score": 0.5575875,
398+
"HotelId": "3",
399+
"HotelName": "Gastronomic Landscape Hotel",
400+
"Description": "The Gastronomic Hotel stands out for its culinary excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services.",
401+
"Tags": "restaurant bar continental breakfast"
402+
}
403+
]
404+
}
405+
```
389406

390407
#### Other query examples
391408

392-
Try some other query examples to explore the syntax. You can perform string searches, use `$filter` expressions, limit result sets, select specific fields, and more.
409+
Run the following commands to explore the query syntax. You can perform string searches, use `$filter` expressions, limit result sets, select specific fields, and more.
393410

394411
```powershell
395412
# Query example 1
396-
# Search the entire index for the terms 'restaurant' and 'wifi'
413+
# Search the index for the terms 'restaurant' and 'wifi'
397414
# Return only the HotelName, Description, and Tags fields
398-
$url = 'https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=restaurant wifi&$count=true&$select=HotelName,Description,Tags'
415+
$url = '<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=restaurant wifi&$count=true&$select=HotelName,Description,Tags'
399416
400417
# Query example 2
401-
# Apply a filter to the index to find hotels rated 4 or higher
402-
# Returns the HotelName and Rating. Two documents match.
403-
$url = 'https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=*&$filter=Rating gt 4&$select=HotelName,Rating'
418+
# Use a filter to find hotels rated 4 or higher
419+
# Return only the HotelName and Rating fields
420+
$url = '<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=*&$filter=Rating gt 4&$select=HotelName,Rating'
404421
405422
# Query example 3
406-
# Take the top two results, and show only HotelName and Category in the results
407-
$url = 'https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=boutique&$top=2&$select=HotelName,Category'
423+
# Take the top two results
424+
# Return only the HotelName and Category fields
425+
$url = '<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=boutique&$top=2&$select=HotelName,Category'
408426
409427
# Query example 4
410428
# Sort by a specific field (Address/City) in ascending order
411-
$url = 'https://<YOUR-SEARCH-SERVICE>.search.windows.net/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=pool&$orderby=Address/City asc&$select=HotelName, Address/City, Tags, Rating'
429+
# Return only the HotelName, Address/City, Tags, and Rating fields
430+
$url = '<YOUR-SEARCH-SERVICE>/indexes/hotels-quickstart/docs?api-version=2024-07-01&search=pool&$orderby=Address/City asc&$select=HotelName, Address/City, Tags, Rating'
412431
```

0 commit comments

Comments
 (0)