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
Create a Java console application that creates, loads, and queries a search index using [Visual Studio Code](https://code.visualstudio.com/), [Java 11 SDK](/java/azure/jdk/), and the [Azure Cognitive Search REST API](/rest/api/searchservice/). This article provides step-by-step instructions for creating the application. Alternatively, you can [download and run the complete application](https://github.com/Azure-Samples/azure-search-java-samples).
25
+
Create a Java console application that creates, loads, and queries a search index using [Visual Studio Code](https://code.visualstudio.com/), [Java 11 SDK](/java/azure/jdk/), and the [Azure.Search.Documents client library in the Azure SDK for Java.](/java/api/overview/azure/search). This article provides step-by-step instructions for creating the application. Alternatively, you can [download and run the complete application](https://github.com/Azure-Samples/azure-search-java-samples).
26
26
27
27
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
28
28
29
29
## Prerequisites
30
30
31
31
We used the following software and services to build and test this quickstart:
32
32
33
-
+[Visual Studio Code](https://www.jetbrains.com/idea/)
33
+
+[Visual Studio Code](https://code.visualstudio.com/)
34
+
35
+
+[Java extension for Visual Studio Code](https://vscode.trafficmanager.net/docs/java/extensions)
34
36
35
37
+[Java 11 SDK](/java/azure/jdk/)
36
38
@@ -52,12 +54,12 @@ Every request sent to your service requires an API key. Having a valid key estab
52
54
53
55
## Set up your environment
54
56
55
-
Begin by opening Visual Studio Code and setting up a new project
57
+
Begin by opening Visual Studio Code and setting up a new project.
56
58
57
59
### Create the project
58
60
59
-
1. Open Visual Studio Code
60
-
1. Install the [Extension Pack For Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack)
61
+
1. Open Visual Studio Code.
62
+
1. Install the [Extension Pack For Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack).
61
63
1. Open the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)**Ctrl+Shift+P**. Search for **Create Java Project**.
62
64
63
65
:::image type="content" source="media/search-get-started-java/java-quickstart-create-project.png" alt-text="Screenshot of a create a java project." border="true":::
@@ -84,7 +86,7 @@ Begin by opening Visual Studio Code and setting up a new project
84
86
85
87
1. Select the folder to create the project in.
86
88
87
-
1. Finish project creation in the [terminal](https://code.visualstudio.com/docs/terminal/basics). Press enter, then type **y** and press enter again
89
+
1. Finish project creation in the [integrated terminal](https://code.visualstudio.com/docs/terminal/basics). Press enter to accept the default for "1.0-SNAPSHOT" and then type "y" to confirm the properties for your project.
88
90
89
91
:::image type="content" source="media/search-get-started-java/java-quickstart-finish-setup-terminal.png" alt-text="Screenshot of a finish setup in terminal." border="true":::
90
92
@@ -106,6 +108,12 @@ Begin by opening Visual Studio Code and setting up a new project
106
108
<artifactId>azure-core</artifactId>
107
109
<version>1.34.0</version>
108
110
</dependency>
111
+
<dependency>
112
+
<groupId>junit</groupId>
113
+
<artifactId>junit</artifactId>
114
+
<version>4.11</version>
115
+
<scope>test</scope>
116
+
</dependency>
109
117
</dependencies>
110
118
```
111
119
@@ -143,7 +151,7 @@ Begin by opening Visual Studio Code and setting up a new project
1. Create two clients: [SearchIndexClient](/java/api/com.azure.search.documents.indexes.searchindexclient) creates the index, and [SearchClient](/java/api/com.azure.search.documents.searchclient) loads and queries an existing index. Both need the service endpoint and an admin API key for authentication with create/delete rights.
154
+
1. The following example includes placeholders for a search service name, admin API key that grants create and delete permissions, and index name. Substitute valid values for all three placeholders. Create two clients: [SearchIndexClient](/java/api/com.azure.search.documents.indexes.searchindexclient) creates the index, and [SearchClient](/java/api/com.azure.search.documents.searchclient) loads and queries an existing index. Both need the service endpoint and an admin API key for authentication with create and delete rights.
147
155
148
156
149
157
```java
@@ -281,7 +289,7 @@ In this example, synchronous methods of the azure-search-documents library are u
281
289
}
282
290
```
283
291
284
-
In the azure-search-documents client library, you can use [SearchableField](/java/api/com.azure.search.documents.indexes.searchablefield) and [SimpleField](/java/api/com.azure.search.documents.indexes.simplefield) to streamline field definitions.
292
+
In the Azure.Search.Documents client library, you can use [SearchableField](/java/api/com.azure.search.documents.indexes.searchablefield) and [SimpleField](/java/api/com.azure.search.documents.indexes.simplefield) to streamline field definitions.
285
293
286
294
* `SimpleField` can be any data type, is always non-searchable (it's ignored for full text search queries), and is retrievable (it's not hidden). Other attributes are off by default, but can be enabled. You might use a SimpleField for document IDs or fields used only in filters, facets, or scoring profiles. If so, be sure to apply any attributes that are necessary for the scenario, such as IsKey = true for a document ID.
287
295
* `SearchableField` must be a string, and is always searchable and retrievable. Other attributes are off by default, but can be enabled. Because this field type is searchable, it supports synonyms and the full complement of analyzer properties.
@@ -611,21 +619,21 @@ The previous queries show multiple ways of matching terms in a query: full-text
611
619
612
620
Full text search and filters are performed using the [SearchClient.search](/java/api/com.azure.search.documents.searchclient#com-azure-search-documents-searchclient-search(java-lang-string)) method. A search query can be passed in the `searchText` string, while a filter expression can be passed in the `filter` property of the [SearchOptions](/java/api/com.azure.search.documents.models.searchoptions) class. To filter without searching, just pass "*" for the `searchText` parameter of the `search` method. To search without filtering, leave the `filter` property unset, or don't pass in a `SearchOptions` instance at all.
613
621
614
-
### Run the program
622
+
## Run the program
615
623
616
624
Press F5 to rebuild the app and run the program in its entirety.
617
625
618
626
Output includes messages from System.out.println, with the addition of query information and results.
619
627
620
-
### Clean up resources
628
+
## Clean up resources
621
629
622
630
When you're working in your own subscription, it's a good idea at the end of a project to identify whether you still need the resources you created. Resources left running can cost you money. You can delete resources individually or delete the resource group to delete the entire set of resources.
623
631
624
632
You can find and manage resources in the portal, using the **All resources** or **Resource groups** link in the left-navigation pane.
625
633
626
634
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.
627
635
628
-
### Next Steps
636
+
## Next Steps
629
637
630
638
In this Java quickstart, you worked through a set of tasks to create an index, load it with documents, and run queries. At different stages, we took shortcuts to simplify the code for readability and comprehension. Now that you're familiar with the basic concepts, try the next tutorial to call Cognitive Search APIs in the context of a web app.
0 commit comments