You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/search-get-started-rest.md
+37-48Lines changed: 37 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,23 +9,21 @@ ms.author: heidist
9
9
ms.service: cognitive-search
10
10
ms.topic: quickstart
11
11
ms.devlang: rest-api
12
-
ms.date: 10/25/2022
12
+
ms.date: 01/27/2023
13
13
ms.custom: mode-api
14
14
---
15
15
16
16
# Quickstart: Create an Azure Cognitive Search index using REST APIs
17
17
18
-
This article explains how to formulate REST API requests interactively using the [Azure Cognitive Search REST APIs](/rest/api/searchservice) and an API client for sending and receiving requests.
19
-
20
-
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
18
+
This article explains how to formulate requests interactively using the [Azure Cognitive Search REST APIs](/rest/api/searchservice) and a REST client for sending and receiving requests.
21
19
22
20
The article uses the Postman desktop application. You can [download and import a Postman collection](https://github.com/Azure-Samples/azure-search-postman-samples/tree/master/Quickstart) if you prefer to use predefined requests.
23
21
24
-
## Prerequisites
22
+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
25
23
26
-
The following services and tools are required for this quickstart.
24
+
## Prerequisites
27
25
28
-
+[Postman desktop app](https://www.getpostman.com/) is used for sending requests to Azure Cognitive Search.
26
+
+[Postman desktop app](https://www.getpostman.com/), used for sending requests to Azure Cognitive Search.
29
27
30
28
+[Create an Azure Cognitive Search service](search-create-service-portal.md) or [find an existing service](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Search%2FsearchServices) under your current subscription. You can use a free service for this quickstart.
31
29
@@ -43,46 +41,43 @@ All requests require an api-key on every request sent to your service. Having a
43
41
44
42
## Connect to Azure Cognitive Search
45
43
46
-
In this section, use your web tool of choice to set up connections to Azure Cognitive Search. Each tool persists request header information for the session, which means you only have to enter the api-key and Content-Type once.
44
+
Connection information is specified in the URI endpoint. Collection variables are used to represent the search service name and API keys. A typical URI in this quickstart looks like this:
47
45
48
-
For either tool, you need to choose a command (GET, POST, PUT, and so forth), provide a URL endpoint, and for some tasks, provide JSON in the body of the request. Replace the search service name (YOUR-SEARCH-SERVICE-NAME) with a valid value. Add `$select=name` to return just the name of each index.
Notice the HTTPS prefix, the name of the service (variable, the name of an object (in this case, the name of an index in the indexes collection), and the [api-version](search-api-versions.md). The api-version is a required.
51
51
52
-
Notice the HTTPS prefix, the name of the service, the name of an object (in this case, the indexes collection), and the [api-version](search-api-versions.md). The api-version is a required, lowercase string specified as `?api-version=2020-06-30` for the current version. API versions are updated regularly. Including the api-version on each request gives you full control over which one is used.
52
+
Request header composition includes two elements: `Content-Type`and the `api-key` used to authenticate to Azure Cognitive Search. The `api-key` is specified as variable, and it's also required.
53
53
54
-
Request header composition includes two elements: `Content-Type` and the `api-key` used to authenticate to Azure Cognitive Search. Replace the admin API key (YOUR-AZURE-SEARCH-ADMIN-API-KEY) with a valid value.
54
+
For the requests to succeed, you'll need to provide the service name and api-key as collection variables.
55
55
56
-
```http
57
-
api-key: <YOUR-AZURE-SEARCH-ADMIN-API-KEY>
58
-
Content-Type: application/json
59
-
```
56
+
1. Open the Postman Desktop app and import the collection.
60
57
61
-
In Postman, formulate a request that looks like the following screenshot. Choose **GET** as the command, provide the URL, and click **Send**. This command connects to Azure Cognitive Search, reads the indexes collection, and returns HTTP status code 200 on a successful connection. If your service has indexes already, the response will also include index definitions.
58
+
1. Select the collection's access menu, select **Edit**, and provide the service name and key of your search service.
62
59
63
-

60
+
:::image type="content" source="media/search-get-started-rest/postman-collection-variables.png" lightbox="media/search-get-started-rest/postman-collection-variables.png"alt-text="Screenshot of the Postman collection variable page." border="true":::
64
61
65
62
## 1 - Create an index
66
63
67
64
In Azure Cognitive Search, you usually create the index before loading it with data. The [Create Index REST API](/rest/api/searchservice/create-index) is used for this task.
68
65
69
-
The URL is extended to include the `hotels` index name.
66
+
The URL is extended to include the `hotels-quickstart` index name.
70
67
71
-
To do this in Postman:
68
+
1. Set the verb to **PUT**.
72
69
73
-
1. Change the command to **PUT**.
70
+
2. Copy in this URL `https://{{service-name}}.search.windows.net/indexes/hotels-quickstart?api-version=2020-06-30`.
74
71
75
-
2. Copy in this URL `https://<YOUR-SEARCH-SERVICE-NAME>.search.windows.net/indexes/hotels-quickstart?api-version=2020-06-30`.
72
+
3. Provide the index definition (copy-ready code is provided next) in the body of the request.
76
73
77
-
3. Provide the index definition (copy-ready code is provided below) in the body of the request.
78
-
79
-
4. Click **Send**.
74
+
4. Select **Send**.
80
75
81
76

82
77
83
78
### Index definition
84
79
85
-
The fields collection defines document structure. Each document must have these fields, and each field must have a data type. String fields are used in full text search. If you need numeric data to be searchable, you will need to cast numeric data as strings.
80
+
The fields collection defines document structure. Each document must have these fields, and each field must have a data type. String fields are used in full text search. If you need numeric data to be searchable, you'll need to cast numeric data as strings.
86
81
87
82
Attributes on the field determine allowed action. The REST APIs allow many actions by default. For example, all strings are searchable, retrievable, filterable, and facetable by default. Often, you only have to set attributes when you need to turn off a behavior.
88
83
@@ -122,15 +117,13 @@ Creating the index and populating the index are separate steps. In Azure Cogniti
122
117
123
118
The URL is extended to include the `docs` collections and `index` operation.
124
119
125
-
To do this in Postman:
126
-
127
-
1. Change the command to **POST**.
120
+
1. Set the verb to **POST**.
128
121
129
-
2. Copy in this URL `https://<YOUR-SEARCH-SERVICE-NAME>.search.windows.net/indexes/hotels-quickstart/docs/index?api-version=2020-06-30`.
122
+
2. Copy in this URL `https://{{service-name}}.search.windows.net/indexes/hotels-quickstart/docs/index?api-version=2020-06-30`.
130
123
131
-
3. Provide the JSON documents (copy-ready code is below) in the body of the request.
124
+
3. Provide the JSON documents (copy-ready code is next) in the body of the request.
132
125
133
-
4.Click**Send**.
126
+
4.Select**Send**.
134
127
135
128

136
129
@@ -225,54 +218,50 @@ In a few seconds, you should see an HTTP 201 response in the session list. This
225
218
226
219
If you get a 207, at least one document failed to upload. If you get a 404, you have a syntax error in either the header or body of the request: verify you changed the endpoint to include `/docs/index`.
227
220
228
-
> [!Tip]
221
+
> [!TIP]
229
222
> For selected data sources, you can choose the alternative *indexer* approach which simplifies and reduces the amount of code required for indexing. For more information, see [Indexer operations](/rest/api/searchservice/indexer-operations).
230
223
231
-
232
224
## 3 - Search an index
233
225
234
226
Now that an index and document set are loaded, you can issue queries against them using [Search Documents REST API](/rest/api/searchservice/search-documents).
235
227
236
228
The URL is extended to include a query expression, specified using the search operator.
237
229
238
-
To do this in Postman:
239
-
240
-
1. Change the command to **GET**.
230
+
1. Set the verb to **GET**.
241
231
242
-
2. Copy in this URL `https://<YOUR-SEARCH-SERVICE-NAME>.search.windows.net/indexes/hotels-quickstart/docs?search=*&$count=true&api-version=2020-06-30`.
232
+
2. Copy in this URL `https://{{service-name}}.search.windows.net/indexes/hotels-quickstart/docs?search=*&$count=true&api-version=2020-06-30`.
243
233
244
-
3.Click**Send**.
234
+
3.Select**Send**.
245
235
246
-
This query is an empty and returns a count of the documents in the search results. The request and response should look similar to the following screenshot for Postman after you click**Send**. The status code should be 200.
236
+
This query is an empty and returns a count of the documents in the search results. The request and response should look similar to the following screenshot for Postman after you select**Send**. The status code should be 200.
247
237
248
238

249
239
250
240
Try a few other query examples to get a feel for the syntax. You can do a string search, verbatim $filter queries, limit the results set, scope the search to specific fields, and more.
251
241
252
-
Swap out the current URL with the ones below, clicking **Send** each time to view the results.
253
242
254
243
```
255
244
# Query example 1 - Search on restaurant and wifi
256
245
# Return only the HotelName, Description, and Tags fields
Adding `/stats` to your URL returns index information. In Postman, your request should look similar to the following, and the response includes a document count and space used in bytes.
@@ -287,11 +276,11 @@ When you're working in your own subscription, it's a good idea at the end of a p
287
276
288
277
You can find and manage resources in the portal, using the **All resources** or **Resource groups** link in the left-navigation pane.
289
278
290
-
If you are using a free service, remember that you are limited to three indexes, indexers, and data sources. You can delete individual items in the portal to stay under the limit.
279
+
If you're using a free service, remember that you're limited to three indexes, indexers, and data sources. You can delete individual items in the portal to stay under the limit.
291
280
292
281
## Next steps
293
282
294
-
Now that you know how to perform core tasks, you can move forward with additional REST API calls for more advanced features, such as indexers or [setting up an enrichment pipeline](cognitive-search-tutorial-blob.md) that adds content transformations to indexing. For your next step, we recommend the following link:
283
+
Now that you know how to perform core tasks, you can move forward with more REST API calls for advanced features, such as indexers or [setting up an enrichment pipeline](cognitive-search-tutorial-blob.md) that adds content transformations to indexing. For your next step, we recommend the following link:
295
284
296
285
> [!div class="nextstepaction"]
297
286
> [Tutorial: Use REST and AI to generate searchable content from Azure blobs](cognitive-search-tutorial-blob.md)
0 commit comments