@@ -161,35 +161,8 @@ SearchAsyncClient searchAsyncClient = new SearchClientBuilder()
161161
162162### Send your first search query
163163
164- To get running immediately, we're going to connect to a well-known sandbox Search service provided by Microsoft. This
165- means you do not need an Azure subscription or Azure Cognitive Search service to try out this query.
166-
167- <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L122-L144 -->
168- ``` java
169- // We'll connect to the Azure Cognitive Search public sandbox and send a
170- // query to its "nycjobs" index built from a public dataset of available jobs
171- // in New York.
172- String serviceName = " azs-playground" ;
173- String indexName = " nycjobs" ;
174- String apiKey = " 252044BE3886FE4A8E3BAA4F595114BB" ;
175-
176- // Create a SearchClient to send queries
177- String serviceEndpoint = String . format(" https://%s.search.windows.net/" , serviceName);
178- AzureKeyCredential credential = new AzureKeyCredential (apiKey);
179- SearchClient client = new SearchClientBuilder ()
180- .endpoint(serviceEndpoint)
181- .credential(credential)
182- .indexName(indexName)
183- .buildClient();
184-
185- // Let's get the top 5 jobs related to Microsoft
186- client. search(" Microsoft" , new SearchOptions (). setTop(5 ), Context . NONE ). forEach(searchResult - > {
187- SearchDocument document = searchResult. getDocument(SearchDocument . class);
188- String title = (String ) document. get(" business_title" );
189- String description = (String ) document. get(" job_description" );
190- System . out. printf(" The business title is %s, and here is the description: %s.%n" , title, description);
191- });
192- ```
164+ To get running with Azure Cognitive Search first create an index following this [ guide] [ search-get-started-portal ] .
165+ With an index created you can use the following samples to begin using the SDK.
193166
194167## Key concepts
195168
@@ -244,7 +217,7 @@ Let's explore them with a search for a "luxury" hotel.
244217` SearchDocument ` is the default type returned from queries when you don't provide your own. Here we perform the search,
245218enumerate over the results, and extract data using ` SearchDocument ` 's dictionary indexer.
246219
247- <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L148-L153 -->
220+ <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L122-L127 -->
248221``` java
249222for (SearchResult searchResult : searchClient. search(" luxury" )) {
250223 SearchDocument doc = searchResult. getDocument(SearchDocument . class);
@@ -258,7 +231,7 @@ for (SearchResult searchResult : searchClient.search("luxury")) {
258231
259232Define a ` Hotel ` class.
260233
261- <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L156-L177 -->
234+ <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L130-L151 -->
262235``` java
263236public class Hotel {
264237 private String id;
@@ -286,7 +259,7 @@ public class Hotel {
286259
287260Use it in place of ` SearchDocument ` when querying.
288261
289- <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L180-L185 -->
262+ <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L154-L159 -->
290263``` java
291264for (SearchResult searchResult : searchClient. search(" luxury" )) {
292265 Hotel doc = searchResult. getDocument(Hotel . class);
@@ -304,7 +277,7 @@ The `SearchOptions` provide powerful control over the behavior of our queries.
304277
305278Let's search for the top 5 luxury hotels with a good rating.
306279
307- <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L189-L194 -->
280+ <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L163-L168 -->
308281``` java
309282SearchOptions options = new SearchOptions ()
310283 .setFilter(" rating ge 4" )
@@ -324,15 +297,15 @@ There are multiple ways of preparing search fields for a search index. For basic
324297` List<SearchField> ` . There are three annotations ` SimpleFieldProperty ` , ` SearchFieldProperty ` and ` FieldBuilderIgnore `
325298to configure the field of model class.
326299
327- <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L268-L269 -->
300+ <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L242-L243 -->
328301``` java
329302List<SearchField > searchFields = SearchIndexClient . buildSearchFields(Hotel . class, null );
330303searchIndexClient. createIndex(new SearchIndex (" index" , searchFields));
331304```
332305
333306For advanced scenarios, we can build search fields using ` SearchField ` directly.
334307
335- <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L218-L264 -->
308+ <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L192-L238 -->
336309``` java
337310List<SearchField > searchFieldList = new ArrayList<> ();
338311searchFieldList. add(new SearchField (" hotelId" , SearchFieldDataType . STRING )
@@ -389,7 +362,7 @@ In addition to querying for documents using keywords and optional filters, you c
389362your index if you already know the key. You could get the key from a query, for example, and want to show more
390363information about it or navigate your customer to that document.
391364
392- <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L206-L207 -->
365+ <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L180-L181 -->
393366``` java
394367Hotel hotel = searchClient. getDocument(" 1" , Hotel . class);
395368System . out. printf(" This is hotelId %s, and this is hotel name %s.%n" , hotel. getId(), hotel. getName());
@@ -401,7 +374,7 @@ You can `Upload`, `Merge`, `MergeOrUpload`, and `Delete` multiple documents from
401374There are [ a few special rules for merging] ( https://docs.microsoft.com/rest/api/searchservice/addupdate-or-delete-documents#document-actions )
402375to be aware of.
403376
404- <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L211-L214 -->
377+ <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L185-L188 -->
405378``` java
406379IndexDocumentsBatch<Hotel > batch = new IndexDocumentsBatch<> ();
407380batch. addUploadActions(Collections . singletonList(new Hotel (). setId(" 783" ). setName(" Upload Inn" )));
@@ -418,7 +391,7 @@ to `false` to get a successful response with an `IndexDocumentsResult` for inspe
418391The examples so far have been using synchronous APIs, but we provide full support for async APIs as well. You'll need
419392to use [ SearchAsyncClient] ( #create-a-searchclient ) .
420393
421- <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L198-L202 -->
394+ <!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L172-L176 -->
422395``` java
423396searchAsyncClient. search(" luxury" )
424397 .subscribe(result - > {
@@ -509,5 +482,6 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m
509482[ create_search_service_cli ] : https://docs.microsoft.com/cli/azure/search/service?view=azure-cli-latest#az-search-service-create
510483[ HttpResponseException ] : https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core/src/main/java/com/azure/core/exception/HttpResponseException.java
511484[ status_codes ] : https://docs.microsoft.com/rest/api/searchservice/http-status-codes
485+ [ search-get-started-portal ] : https://docs.microsoft.com/azure/search/search-get-started-portal
512486
513487![ Impressions] ( https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fsearch%2Fazure-search-documents%2FREADME.png )
0 commit comments