Skip to content

Commit 4f0ed34

Browse files
Merge pull request #210710 from HeidiSteen/heidist-js
[azure search] Freshness pass on JS quickstart
2 parents f339366 + 384cb04 commit 4f0ed34

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

articles/search/search-data-sources-terms-of-use.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.author: heidist
88

99
ms.service: cognitive-search
1010
ms.topic: conceptual
11-
ms.date: 05/29/2021
11+
ms.date: 09/07/2022
1212

1313
---
1414

articles/search/search-get-started-javascript.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: delegenz
77
ms.devlang: javascript
88
ms.service: cognitive-search
99
ms.topic: quickstart
10-
ms.date: 07/08/2021
10+
ms.date: 09/09/2022
1111
ms.custom: devx-track-js, mode-api
1212
---
1313

@@ -20,7 +20,6 @@ ms.custom: devx-track-js, mode-api
2020
> * [Python](search-get-started-python.md)
2121
> * [REST](search-get-started-rest.md)
2222
23-
2423
Use the [JavaScript/TypeScript SDK for Azure Cognitive Search](/javascript/api/overview/azure/search-documents-readme) to create a Node.js application in JavaScript that creates, loads, and queries a search index.
2524

2625
This article demonstrates how to create the application step by step. Alternatively, you can [download the source code and data](https://github.com/Azure-Samples/azure-search-javascript-samples/tree/master/quickstart/v11) and run the application from the command line.
@@ -33,30 +32,29 @@ Before you begin, have the following tools and services:
3332

3433
+ An Azure Cognitive Search service. [Create a service](search-create-service-portal.md) or [find an existing service](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Search%2FsearchServices). You can use a free service for this quickstart.
3534

36-
+ [Node.js](https://nodejs.org) and [NPM](https://www.npmjs.com)
35+
+ [Node.js](https://nodejs.org) and [npm](https://www.npmjs.com)
3736

3837
+ [Visual Studio Code](https://code.visualstudio.com) or another IDE
3938

40-
4139
## Set up your project
4240

43-
Start by getting the endpoint and key for your search service. Then create a new project with NPM as outlined below.
41+
Start by getting the endpoint and key for your search service. Then create a new project with npm as outlined below.
4442

4543
<a name="get-service-info"></a>
4644

4745
### Copy a key and endpoint
4846

49-
Calls to the service require a URL endpoint and an access key on every request. As a first step, find the API key and URL to add to your project. You will specify both values when creating the client in a later step.
47+
Calls to the service require a URL endpoint and an access key on every request. As a first step, find the API key and URL to add to your project. You'll specify both values when creating the client in a later step.
5048

5149
1. [Sign in to the Azure portal](https://portal.azure.com/), and in your search service **Overview** page, get the URL. An example endpoint might look like `https://mydemo.search.windows.net`.
5250

53-
2. In **Settings** > **Keys**, get an admin key for full rights on the service, required if you are creating or deleting objects. There are two interchangeable primary and secondary keys. You can use either one.
51+
2. In **Settings** > **Keys**, get an admin key for full rights on the service, required if you're creating or deleting objects. There are two interchangeable primary and secondary keys. You can use either one.
5452

5553
![Get an HTTP endpoint and access key](media/search-get-started-rest/get-url-key.png "Get an HTTP endpoint and access key")
5654

5755
All requests require an api-key on every request sent to your service. Having a valid key establishes trust, on a per request basis, between the application sending the request and the service that handles it.
5856

59-
### Create a new NPM project
57+
### Create a new npm project
6058

6159
Begin by opening VS Code and its [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal) or another terminal such as the Node.js command prompt.
6260

@@ -67,20 +65,20 @@ Begin by opening VS Code and its [integrated terminal](https://code.visualstudio
6765
cd quickstart
6866
```
6967
70-
2. Initialize an empty project with NPM by running
68+
2. Initialize an empty project with npm by running the following command. To fully initialize the project, press Enter multiple times to accept the default values, except for the License, which you should set to "MIT".
7169
7270
```cmd
7371
npm init
7472
```
75-
Accept the default values, except for the License, which you should set to "MIT".
76-
77-
3. Install `@azure/search-documents`, the [JavaScript/TypeScript SDK for Azure Cognitive Search](/javascript/api/overview/azure/search-documents-readme).
73+
74+
3. Install `@azure/search-documents`, the [JavaScript/TypeScript SDK for Azure Cognitive Search](/javascript/api/overview/azure/search-documents-readme).
7875
7976
```cmd
8077
npm install @azure/search-documents
8178
```
8279
83-
4. Install `dotenv`, which is used to import the environment variables such as our service name and API key.
80+
4. Install `dotenv`, which is used to import the environment variables such as your search service name and API key.
81+
8482
```cmd
8583
npm install dotenv
8684
```
@@ -103,8 +101,8 @@ Begin by opening VS Code and its [integrated terminal](https://code.visualstudio
103101
"author": "Your Name",
104102
"license": "MIT",
105103
"dependencies": {
106-
"@azure/search-documents": "^11.2.0",
107-
"dotenv": "^8.2.0"
104+
"@azure/search-documents": "^11.3.0",
105+
"dotenv": "^16.0.2"
108106
}
109107
}
110108
```
@@ -165,7 +163,7 @@ With that in place, we're ready to create an index.
165163

166164
Create a file **hotels_quickstart_index.json**. This file defines how Azure Cognitive Search works with the documents you'll be loading in the next step. Each field will be identified by a `name` and have a specified `type`. Each field also has a series of index attributes that specify whether Azure Cognitive Search can search, filter, sort, and facet upon the field. Most of the fields are simple data types, but some, like `AddressType` are complex types that allow you to create rich data structures in your index. You can read more about [supported data types](/rest/api/searchservice/supported-data-types) and index attributes described in [Create Index (REST)](/rest/api/searchservice/create-index).
167165

168-
Add the following to **hotels_quickstart_index.json** or [download the file](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/master/quickstart/v11/hotels_quickstart_index.json).
166+
Add the following content to **hotels_quickstart_index.json** or [download the file](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/master/quickstart/v11/hotels_quickstart_index.json).
169167

170168
```json
171169
{
@@ -311,7 +309,7 @@ Within the main function, we then create a `SearchIndexClient`, which is used to
311309
const indexClient = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
312310
```
313311

314-
Next, we want to delete the index if it already exists. This is a common practice for test/demo code.
312+
Next, we want to delete the index if it already exists. This operation is a common practice for test/demo code.
315313

316314
We do this by defining a simple function that tries to delete the index.
317315

@@ -356,7 +354,7 @@ If you [downloaded the source code](https://github.com/Azure-Samples/azure-searc
356354

357355
You should see a series of messages describing the actions being taken by the program.
358356

359-
Open the **Overview** of your search service in the Azure portal. Select the **Indexes** tab. You should see something like the following:
357+
Open the **Overview** of your search service in the Azure portal. Select the **Indexes** tab. You should see something like the following example:
360358

361359
:::image type="content" source="media/search-get-started-javascript/create-index-no-data.png" alt-text="Screenshot of Azure portal, search service Overview, Indexes tab" border="false":::
362360

@@ -504,7 +502,7 @@ The queries are written in a `sendQueries()` function that we'll call in the mai
504502
await sendQueries(searchClient);
505503
```
506504

507-
Queries are sent using the `search()` method of `searchClient`. The first parameter is the search text and the second parameter is any additional search options.
505+
Queries are sent using the `search()` method of `searchClient`. The first parameter is the search text and the second parameter specifies search options.
508506

509507
The first query searches `*`, which is equivalent to searching everything and selects three of the fields in the index. It's a best practice to only `select` the fields you need because pulling back unnecessary data can add latency to your queries.
510508

@@ -528,7 +526,7 @@ async function sendQueries(searchClient) {
528526
}
529527
```
530528

531-
The remaining queries outlined below should also be added to the `sendQueries()` function. They are separated here for readability.
529+
The remaining queries outlined below should also be added to the `sendQueries()` function. They're separated here for readability.
532530

533531
In the next query, we specify the search term `"wifi"` and also include a filter to only return results where the state is equal to `'FL'`. Results are also ordered by the Hotel's `Rating`.
534532

@@ -547,7 +545,7 @@ for await (const result of searchResults.results) {
547545
}
548546
```
549547

550-
Next, the search is limited to a single searchable field using the `searchFields` parameter. This is a great option to make your query more efficient if you know you're only interested in matches in certain fields.
548+
Next, the search is limited to a single searchable field using the `searchFields` parameter. This approach is a great option to make your query more efficient if you know you're only interested in matches in certain fields.
551549

552550
```javascript
553551
console.log('Query #3 - Limit searchFields:');
@@ -597,7 +595,7 @@ When you're working in your own subscription, it's a good idea at the end of a p
597595

598596
You can find and manage resources in the portal, using the **All resources** or **Resource groups** link in the left-navigation pane.
599597

600-
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.
598+
If you're using a free service, remember the limit of three indexes, indexers, and data sources. You can delete individual items in the portal to stay under the limit.
601599

602600
## Next steps
603601

0 commit comments

Comments
 (0)