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
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.
@@ -95,30 +95,30 @@ To connect to your search service:
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.
98
+
1. Run `Invoke-RestMethod` to send a GET request to your search service. Include `ConvertTo-Json` to view responses from the service.
If your service is empty and has no indexes, the response is similar to the following example. Otherwise, you see a JSON representation of index definitions.
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).
117
+
Before you add content to Azure AI Search, you must create an index to define how the content is stored and structured. An index is conceptually similar to a table in a relational database, but it's specifically designed for search operations, such as full-text search.
118
118
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).
119
+
Run the following commands in the same PowerShell session you started in the previous section.
120
120
121
-
To create, load, and query an index:
121
+
To create an index:
122
122
123
123
1. Create a `$body` object to define the index schema.
124
124
@@ -149,20 +149,42 @@ To create, load, and query an index:
149
149
"@
150
150
```
151
151
152
-
1. Update the `$url` object to target the new index.
152
+
2. Update the `$url` object to target the new index. Replace `<YOUR-SEARCH-SERVICE>` with the value you obtained in [Get endpoint](#get-endpoint).
The response should contain the JSON representation of the index schema.
165
165
166
+
### About the create index request
167
+
168
+
This quickstart calls [Indexes - Create (REST API)](/rest/api/searchservice/indexes/create) to build a search index named `hotels-quickstart` and its physical data structures on your search service.
169
+
170
+
Within the 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.
171
+
172
+
Key points about the index schema:
173
+
174
+
+ Use string fields (`Edm.String`) to make numeric data full-text searchable. Other [supported data types](/rest/api/searchservice/supported-data-types), such as `Edm.Int32`, are filterable, sortable, facetable, and retrievable but aren't searchable.
175
+
176
+
+ Most of our fields are simple data types, but you can define complex types to represent nested data, such as the `Address` field.
177
+
178
+
+ Field attributes determine allowed actions. The REST APIs allow [many actions by default](/rest/api/searchservice/indexes/create#request-body). For example, all strings are searchable and retrievable. With the REST APIs, you might only use attributes if you need to disable a behavior.
179
+
180
+
## Load the index
181
+
182
+
Newly created indexes are empty. To populate an index and make it searchable, you must upload JSON documents that conform to the index schema.
183
+
184
+
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).
185
+
186
+
To upload documents to your index:
187
+
166
188
1. Create a `$body` object to store the JSON payload of four sample documents.
167
189
168
190
```powershell
@@ -250,163 +272,73 @@ To create, load, and query an index:
250
272
"@
251
273
```
252
274
253
-
1. Update the `$url` object to target the `docs/index` endpoint of your index.
275
+
2. Update the `$url` object to target the indexing endpoint. Replace `<YOUR-SEARCH-SERVICE>` with the value you obtained in [Get endpoint](#get-endpoint).
The response should contain the document that matched your query, its relevance score, and its selected fields.
280
-
281
-
## Explaining the code
282
-
283
-
This section explains the REST API calls that you made to:
284
-
285
-
+ [Create an index](#create-an-index)
286
-
+ [Load documents into the index](#load-documents-into-the-index)
287
-
+ [Query the index](#query-the-index)
288
-
289
-
### Create an index
290
-
291
-
Before you add content to Azure AI Search, you must create an index to define how the content is stored and structured. An index is conceptually similar to a table in a relational database, but it's specifically designed for search operations, such as full-text search.
292
-
293
-
This quickstart calls [Indexes - Create (REST API)](/rest/api/searchservice/indexes/create) to build a search index named `hotels-quickstart` and its physical data structures on your search service.
This quickstart calls [Documents - Index (REST API)](/rest/api/searchservice/documents/) to add four sample hotel documents to your index. Compared to the previous request, the URI is extended to include the `docs` collection and `index` operation.
323
292
324
-
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.
293
+
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.
325
294
326
-
Key points about the index schema:
295
+
## Query the index
327
296
328
-
+ Use string fields (`Edm.String`) to make numeric data full-text searchable. Other [supported data types](/rest/api/searchservice/supported-data-types), such as `Edm.Int32`, are filterable, sortable, facetable, and retrievable but aren't searchable.
297
+
Now that documents are loaded into your index, you can use full-text search to find specific terms or phrases within their fields.
329
298
330
-
+ Most of our fields are simple data types, but you can define complex types to represent nested data, such as the `Address` field.
299
+
To run a full-text query against your index:
331
300
332
-
+ Field attributes determine allowed actions. The REST APIs allow [many actions by default](/rest/api/searchservice/indexes/create#request-body). For example, all strings are searchable and retrievable. With the REST APIs, you might only use attributes if you need to disable a behavior.
301
+
1. Update the `$url` object to specify search parameters. Replace `<YOUR-SEARCH-SERVICE>` with the value you obtained in [Get endpoint](#get-endpoint).
Newly created indexes are empty. To populate an index and make it searchable, you must upload JSON documents that conform to the index schema.
307
+
2. Run `Invoke-RestMethod` to send the query request to your search service.
337
308
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).
"Description": "This classic hotel is fully-refurbished and ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Times Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.",
"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.",
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.
374
-
375
-
### Query the index
376
-
377
-
Now that documents are loaded into your index, you can issue full-text queries against them.
329
+
```
378
330
379
-
This quickstart calls [Documents - Search Post (REST API)](/rest/api/searchservice/documents/search-post) to find hotel documents that match your search criteria.
This quickstart calls [Documents - Search Post (REST API)](/rest/api/searchservice/documents/search-post) to find hotel documents that match your search criteria. The URI still targets the `docs` collection but no longer includes the `index` operation.
384
334
385
335
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
336
387
337
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
338
389
-
The response should be similar to the following example, which shows one matching hotel document, its relevance score, and its selected fields.
"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
-
```
406
-
407
339
#### Other query examples
408
340
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.
341
+
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. Remember to replace `<YOUR-SEARCH-SERVICE>` with the value you obtained in [Get endpoint](#get-endpoint).
0 commit comments