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
Once you initialize the [IndexDocumentsBatch](/dotnet/api/azure.search.documents.models.indexdocumentsbatch-1) object, you can send it to the index by calling [IndexDocuments](/dotnet/api/azure.search.documents.searchclient.indexdocuments) on your [SearchClient](/dotnet/api/azure.search.documents.searchclient) object.
743
743
744
-
You load documents using SearchClient in`Main()`, but the operation also requires admin rights on the service, which is typically associated with SearchIndexClient. One way to set up this operation is to get SearchClient through `SearchIndexClient` (`adminClient`in this example).
744
+
You load documents using SearchClient in`Main()`, but the operation also requires admin rights on the service, which is typically associated with SearchIndexClient. One way to set up this operation is to get SearchClient through `SearchIndexClient` (`searchIndexClient`in this example).
Use the following tools to create this quickstart.
32
+
The sample in this quickstart works with the Java Runtime. Install a Java Development Kit such as [Azul Zulu OpenJDK](https://www.azul.com/downloads/?package=jdk). The [Microsoft Build of OpenJDK](https://www.microsoft.com/openjdk) or your preferred JDK should also work.
33
33
34
-
+[Visual Studio Code with the Java extension](https://code.visualstudio.com/docs/java/extensions)
34
+
1. Install [Apache Maven](https://maven.apache.org/install.html). Then run `mvn -v` to confirm successful installation.
35
+
1. Create a new `pom.xml` file in the root of your project, and copy the following code into it:
35
36
36
-
+[Java 11 SDK](/java/azure/jdk/)
37
-
38
-
## Create the project
39
-
40
-
1. Start Visual Studio Code.
41
-
42
-
1. Open the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) by using **Ctrl+Shift+P**. Search for **Create Java Project**.
:::image type="content" source="../../media/search-get-started-java/java-quickstart-create-project.png" alt-text="Screenshot of a Java project." border="true":::
82
+
1. Install the dependencies including the Azure AI Search client library ([Azure.Search.Documents](/java/api/overview/azure/search)) for Java and [Azure Identity client library for Java](https://mvnrepository.com/artifact/com.azure/azure-identity) with:
45
83
46
-
1. Select **Maven**.
84
+
```console
85
+
mvn clean dependency:copy-dependencies
86
+
```
47
87
48
-
:::image type="content" source="../../media/search-get-started-java/java-quickstart-select-maven.png" alt-text="Screenshot of a maven project." border="true":::
88
+
1. For the **recommended** keyless authentication with Microsoft Entra ID, sign in to Azure with the following command:
49
89
50
-
1. Select **maven-archetype-quickstart**.
90
+
```console
91
+
az login
92
+
```
51
93
52
-
:::image type="content" source="../../media/search-get-started-java/java-quickstart-select-maven-project-type.png" alt-text="Screenshot of a maven quickstart project." border="true":::
94
+
## Create, load, and query a search index
53
95
54
-
1. Select the latest version, currently **1.4**.
96
+
In the prior [set up](#set-up) section, you created a new console application and installed the Azure AI Search client library.
55
97
56
-
:::image type="content" source="../../media/search-get-started-java/java-quickstart-group-id.png" alt-text="Screenshot of the group ID location." border="true":::
98
+
In this section, you add code to create a search index, load it with documents, and run queries. You run the program to see the results in the console. For a detailed explanation of the code, see the [explaining the code](#explaining-the-code) section.
57
99
58
-
1. Enter **azure.search.sample** as the group ID.
100
+
The sample code in this quickstart uses Microsoft Entra ID for authentication. If you prefer to use an API key, you can replace the `DefaultAzureCredential` object with a `AzureKeyCredential` object.
59
101
60
-
:::image type="content" source="../../media/search-get-started-java/java-quickstart-group-id.png" alt-text="Screenshot of the group ID for search." border="true":::
102
+
#### [Microsoft Entra ID](#tab/keyless)
61
103
62
-
1. Enter **azuresearchquickstart** as the artifact ID.
104
+
```java
105
+
String searchServiceEndpoint = "https://<Put your search service NAME here>.search.windows.net/";
106
+
DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
107
+
```
63
108
64
-
:::image type="content" source="../../media/search-get-started-java/java-quickstart-artifact-id.png" alt-text="Screenshot of an artifact ID." border="true":::
109
+
#### [API key](#tab/api-key)
65
110
66
-
1. Select the folder to create the project in.
111
+
```java
112
+
String searchServiceEndpoint ="https://<Put your search service NAME here>.search.windows.net/";
113
+
AzureKeyCredential credential =newAzureKeyCredential("<Your search service admin key>");
114
+
```
115
+
---
67
116
68
-
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.
117
+
1. Create a new file named *App.java* in the same project root directory.
118
+
1. Copy and paste the following code into *App.java*:
69
119
70
-
:::image type="content" source="../../media/search-get-started-java/java-quickstart-finish-setup-terminal.png" alt-text="Screenshot of the finished project definition." border="true":::
120
+
```java
121
+
122
+
```
71
123
72
-
1. Open the folder you created the project in.
73
124
74
-
## Specify Maven dependencies
75
125
76
-
1.Open the *pom.xml* file and add the following dependencies. This includes the [Azure.Search.Documents](/java/api/overview/azure/search) library.
0 commit comments