mapper) {
+ return values.stream().map(mapper).collect(() -> new ArrayList<>(values.size()), List::add, List::addAll);
+ }
}
diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexAsyncClient.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexAsyncClient.java
index c3f380552e4d..4ca596caf885 100644
--- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexAsyncClient.java
+++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexAsyncClient.java
@@ -6,6 +6,7 @@
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.HttpPipeline;
+import com.azure.core.http.MatchConditions;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.Response;
@@ -27,6 +28,8 @@
import com.azure.search.documents.indexes.models.FieldBuilderOptions;
import com.azure.search.documents.indexes.models.IndexStatisticsSummary;
import com.azure.search.documents.indexes.models.KnowledgeAgent;
+import com.azure.search.documents.indexes.models.KnowledgeSource;
+import com.azure.search.documents.indexes.models.SearchAlias;
import com.azure.search.documents.indexes.models.SearchField;
import com.azure.search.documents.indexes.models.SearchIndex;
import com.azure.search.documents.indexes.models.SearchIndexStatistics;
@@ -62,7 +65,8 @@
*
*
* A synonym map is service-level object that contains user-defined synonyms. This object is maintained
- * independently from search indexes. Once uploaded, you can point any searchable field to the synonym map (one per field).
+ * independently of search indexes. Once uploaded, you can point any searchable field to the synonym map
+ * (one per field).
*
*
*
@@ -664,7 +668,7 @@ public PagedFlux listIndexes() {
public PagedFlux listIndexNames() {
try {
return new PagedFlux<>(() -> withContext(context -> this.listIndexesWithResponse("name", context))
- .map(MappingUtils::mappingPagingSearchIndexNames));
+ .map(MappingUtils::mapPagedSearchIndexNames));
} catch (RuntimeException ex) {
return pagedFluxError(LOGGER, ex);
}
@@ -852,7 +856,7 @@ private Mono> analyzeTextWithResponse(String in
return restClient.getIndexes()
.analyzeWithResponseAsync(indexName, AnalyzeRequestConverter.map(analyzeTextOptions), null, context)
.onErrorMap(MappingUtils::exceptionMapper)
- .map(MappingUtils::mappingTokenInfo);
+ .map(MappingUtils::mapPagedTokenInfos);
}
/**
@@ -999,7 +1003,7 @@ Mono> getSynonymMapWithResponse(String synonymMapName, Cont
public PagedFlux listSynonymMaps() {
try {
return new PagedFlux<>(() -> withContext(context -> listSynonymMapsWithResponse(null, context))
- .map(MappingUtils::mappingPagingSynonymMap));
+ .map(MappingUtils::mapPagedSynonymMaps));
} catch (RuntimeException ex) {
return pagedFluxError(LOGGER, ex);
}
@@ -1025,7 +1029,7 @@ public PagedFlux listSynonymMaps() {
public PagedFlux listSynonymMapNames() {
try {
return new PagedFlux<>(() -> withContext(context -> listSynonymMapsWithResponse("name", context))
- .map(MappingUtils::mappingPagingSynonymMapNames));
+ .map(MappingUtils::mapPagedSynonymMapNames));
} catch (RuntimeException ex) {
return pagedFluxError(LOGGER, ex);
}
@@ -1268,9 +1272,276 @@ PagedFlux getIndexStatsSummary(Context context) {
}
}
+ /**
+ * Creates a new Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Create the search alias named "my-alias".
+ *
+ *
+ *
+ * SEARCH_INDEX_ASYNC_CLIENT.createAlias(new SearchAlias("my-alias", Collections.singletonList("index-to-alias")))
+ * .subscribe(searchAlias -> System.out.printf("Created alias '%s' that aliases index '%s'.",
+ * searchAlias.getName(), searchAlias.getIndexes().get(0)));
+ *
+ *
+ *
+ * @param alias definition of the alias to create.
+ * @return the created alias.
+ */
+ public Mono createAlias(SearchAlias alias) {
+ return createAliasWithResponse(alias).flatMap(FluxUtil::toMono);
+ }
+
+ /**
+ * Creates a new Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Create the search alias named "my-alias".
+ *
+ *
+ *
+ * SEARCH_INDEX_ASYNC_CLIENT.createAliasWithResponse(new SearchAlias("my-alias",
+ * Collections.singletonList("index-to-alias")))
+ * .subscribe(response ->
+ * System.out.printf("Response status code %d. Created alias '%s' that aliases index '%s'.",
+ * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0)));
+ *
+ *
+ *
+ * @param alias definition of the alias to create.
+ * @return the created alias.
+ */
+ public Mono> createAliasWithResponse(SearchAlias alias) {
+ return withContext(context -> createAliasWithResponse(alias, context));
+ }
+
+ Mono> createAliasWithResponse(SearchAlias alias, Context context) {
+ try {
+ return restClient.getAliases().createWithResponseAsync(alias, null, context);
+ } catch (RuntimeException ex) {
+ return monoError(LOGGER, ex);
+ }
+ }
+
+ /**
+ * Creates or updates an Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Create then update the search alias named "my-alias".
+ *
+ *
+ *
+ * SEARCH_INDEX_ASYNC_CLIENT.createOrUpdateAlias(
+ * new SearchAlias("my-alias", Collections.singletonList("index-to-alias")))
+ * .flatMap(searchAlias -> {
+ * System.out.printf("Created alias '%s' that aliases index '%s'.", searchAlias.getName(),
+ * searchAlias.getIndexes().get(0));
+ *
+ * return SEARCH_INDEX_ASYNC_CLIENT.createOrUpdateAlias(new SearchAlias(searchAlias.getName(),
+ * Collections.singletonList("new-index-to-alias")));
+ * }).subscribe(searchAlias -> System.out.printf("Updated alias '%s' to aliases index '%s'.",
+ * searchAlias.getName(), searchAlias.getIndexes().get(0)));
+ *
+ *
+ *
+ * @param alias definition of the alias to create or update.
+ * @return the created or updated alias.
+ */
+ public Mono createOrUpdateAlias(SearchAlias alias) {
+ return createOrUpdateAliasWithResponse(alias, false).flatMap(FluxUtil::toMono);
+ }
+
+ /**
+ * Creates or updates an Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Create then update the search alias named "my-alias".
+ *
+ *
+ *
+ * SEARCH_INDEX_ASYNC_CLIENT.createOrUpdateAliasWithResponse(
+ * new SearchAlias("my-alias", Collections.singletonList("index-to-alias")), false)
+ * .flatMap(response -> {
+ * System.out.printf("Response status code %d. Created alias '%s' that aliases index '%s'.",
+ * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0));
+ *
+ * return SEARCH_INDEX_ASYNC_CLIENT.createOrUpdateAliasWithResponse(
+ * new SearchAlias(response.getValue().getName(), Collections.singletonList("new-index-to-alias"))
+ * .setETag(response.getValue().getETag()), true);
+ * }).subscribe(response ->
+ * System.out.printf("Response status code %d. Updated alias '%s' that aliases index '%s'.",
+ * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0)));
+ *
+ *
+ *
+ * @param alias definition of the alias to create or update.
+ * @param onlyIfUnchanged only update the alias if the eTag matches the alias on the service
+ * @return the created or updated alias.
+ */
+ public Mono> createOrUpdateAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged) {
+ if (alias == null) {
+ return monoError(LOGGER, new NullPointerException("'alias' cannot be null."));
+ }
+
+ return withContext(
+ context -> createOrUpdateAliasWithResponse(alias, onlyIfUnchanged ? alias.getETag() : null, context));
+ }
+
+ Mono> createOrUpdateAliasWithResponse(SearchAlias alias, String eTag, Context context) {
+ try {
+ return restClient.getAliases()
+ .createOrUpdateWithResponseAsync(alias.getName(), alias, eTag, null, null, context);
+ } catch (RuntimeException ex) {
+ return monoError(LOGGER, ex);
+ }
+ }
+
+ /**
+ * Gets the Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Get the search alias named "my-alias".
+ *
+ *
+ *
+ * SEARCH_INDEX_ASYNC_CLIENT.getAlias("my-alias")
+ * .subscribe(searchAlias -> System.out.printf("Retrieved alias '%s' that aliases index '%s'.",
+ * searchAlias.getName(), searchAlias.getIndexes().get(0)));
+ *
+ *
+ *
+ * @param aliasName name of the alias to get.
+ * @return the retrieved alias.
+ */
+ public Mono getAlias(String aliasName) {
+ return getAliasWithResponse(aliasName).flatMap(FluxUtil::toMono);
+ }
+
+ /**
+ * Gets the Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Get the search alias named "my-alias".
+ *
+ *
+ *
+ * SEARCH_INDEX_ASYNC_CLIENT.getAliasWithResponse("my-alias")
+ * .subscribe(response ->
+ * System.out.printf("Response status code %d. Retrieved alias '%s' that aliases index '%s'.",
+ * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0)));
+ *
+ *
+ *
+ * @param aliasName name of the alias to get.
+ * @return the retrieved alias.
+ */
+ public Mono> getAliasWithResponse(String aliasName) {
+ return withContext(context -> getAliasWithResponse(aliasName, context));
+ }
+
+ Mono> getAliasWithResponse(String aliasName, Context context) {
+ try {
+ return restClient.getAliases().getWithResponseAsync(aliasName, null, context);
+ } catch (RuntimeException ex) {
+ return monoError(LOGGER, ex);
+ }
+ }
+
+ /**
+ * Deletes the Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Delete the search alias named "my-alias".
+ *
+ *
+ *
+ * SEARCH_INDEX_ASYNC_CLIENT.deleteAlias("my-alias")
+ * .subscribe(ignored -> System.out.println("Deleted alias 'my-alias'."));
+ *
+ *
+ *
+ * @param aliasName name of the alias to delete.
+ * @return a reactive response indicating deletion has completed.
+ */
+ public Mono deleteAlias(String aliasName) {
+ return withContext(context -> deleteAliasWithResponse(aliasName, null, context)).flatMap(FluxUtil::toMono);
+ }
+
+ /**
+ * Deletes the Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Get the search alias named "my-alias".
+ *
+ *
+ *
+ * SEARCH_INDEX_ASYNC_CLIENT.getAlias("my-alias")
+ * .flatMap(searchAlias -> SEARCH_INDEX_ASYNC_CLIENT.deleteAliasWithResponse(searchAlias, true))
+ * .subscribe(response -> System.out.printf("Response status code %d. Deleted alias 'my-alias'.",
+ * response.getStatusCode()));
+ *
+ *
+ *
+ * @param alias the alias to delete.
+ * @param onlyIfUnchanged only delete the alias if the eTag matches the alias on the service
+ * @return a reactive response indicating deletion has completed.
+ */
+ public Mono> deleteAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged) {
+ if (alias == null) {
+ return monoError(LOGGER, new NullPointerException("'alias' cannot be null."));
+ }
+
+ return withContext(
+ context -> deleteAliasWithResponse(alias.getName(), onlyIfUnchanged ? alias.getETag() : null, context));
+ }
+
+ Mono> deleteAliasWithResponse(String aliasName, String eTag, Context context) {
+ try {
+ return restClient.getAliases().deleteWithResponseAsync(aliasName, eTag, null, null, context);
+ } catch (RuntimeException ex) {
+ return monoError(LOGGER, ex);
+ }
+ }
+
+ /**
+ * Lists all aliases in the Azure AI Search service.
+ *
+ * Code Sample
+ *
+ * List aliases
+ *
+ *
+ *
+ * SEARCH_INDEX_ASYNC_CLIENT.listAliases()
+ * .doOnNext(searchAlias -> System.out.printf("Listed alias '%s' that aliases index '%s'.",
+ * searchAlias.getName(), searchAlias.getIndexes().get(0)))
+ * .subscribe();
+ *
+ *
+ *
+ * @return a list of aliases in the service.
+ */
+ public PagedFlux listAliases() {
+ try {
+ return new PagedFlux<>(
+ () -> withContext(context -> restClient.getAliases().listSinglePageAsync(null, context)));
+ } catch (RuntimeException ex) {
+ return pagedFluxError(LOGGER, ex);
+ }
+ }
+
/**
* Creates a new agent.
- *
+ *
* @param knowledgeAgent The definition of the agent to create.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
@@ -1279,12 +1550,12 @@ PagedFlux getIndexStatsSummary(Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono createKnowledgeAgent(KnowledgeAgent knowledgeAgent) {
- return createKnowledgeAgentWithResponse(knowledgeAgent, Context.NONE).map(Response::getValue);
+ return createKnowledgeAgentWithResponse(knowledgeAgent).map(Response::getValue);
}
/**
* Creates a new agent.
- *
+ *
* @param knowledgeAgent The definition of the agent to create.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
@@ -1308,51 +1579,44 @@ Mono> createKnowledgeAgentWithResponse(KnowledgeAgent k
/**
* Creates a new agent or updates an agent if it already exists.
- *
- * @param agentName The name of the agent to create or update.
+ *
* @param knowledgeAgent The definition of the agent to create or update.
- * @param ifMatch Defines the If-Match condition. The operation will be performed only if the ETag on the server
- * matches this value.
- * @param ifNoneMatch Defines the If-None-Match condition. The operation will be performed only if the ETag on the
- * server does not match this value.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response body on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono createOrUpdateKnowledgeAgent(String agentName, KnowledgeAgent knowledgeAgent,
- String ifMatch, String ifNoneMatch) {
- return createOrUpdateKnowledgeAgentWithResponse(agentName, knowledgeAgent, ifMatch, ifNoneMatch, Context.NONE)
- .map(Response::getValue);
+ public Mono createOrUpdateKnowledgeAgent(KnowledgeAgent knowledgeAgent) {
+ return createOrUpdateKnowledgeAgentWithResponse(knowledgeAgent, null).map(Response::getValue);
}
/**
* Creates a new agent or updates an agent if it already exists.
- *
- * @param agentName The name of the agent to create or update.
+ *
* @param knowledgeAgent The definition of the agent to create or update.
- * @param ifMatch Defines the If-Match condition. The operation will be performed only if the ETag on the server
- * matches this value.
- * @param ifNoneMatch Defines the If-None-Match condition. The operation will be performed only if the ETag on the
- * server does not match this value.
+ * @param matchConditions Defining {@code If-Match} and {@code If-None-Match} conditions. If null is passed, no
+ * conditions will be applied.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response body along with {@link Response} on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> createOrUpdateKnowledgeAgentWithResponse(String agentName,
- KnowledgeAgent knowledgeAgent, String ifMatch, String ifNoneMatch) {
- return withContext(context -> createOrUpdateKnowledgeAgentWithResponse(agentName, knowledgeAgent, ifMatch,
- ifNoneMatch, context));
+ public Mono> createOrUpdateKnowledgeAgentWithResponse(KnowledgeAgent knowledgeAgent,
+ MatchConditions matchConditions) {
+ return withContext(
+ context -> createOrUpdateKnowledgeAgentWithResponse(knowledgeAgent, matchConditions, context));
}
- Mono> createOrUpdateKnowledgeAgentWithResponse(String agentName,
- KnowledgeAgent knowledgeAgent, String ifMatch, String ifNoneMatch, Context context) {
+ Mono> createOrUpdateKnowledgeAgentWithResponse(KnowledgeAgent knowledgeAgent,
+ MatchConditions matchConditions, Context context) {
try {
+ String ifMatch = matchConditions != null ? matchConditions.getIfMatch() : null;
+ String ifNoneMatch = matchConditions != null ? matchConditions.getIfNoneMatch() : null;
return restClient.getKnowledgeAgents()
- .createOrUpdateWithResponseAsync(agentName, knowledgeAgent, ifMatch, null, null, context)
+ .createOrUpdateWithResponseAsync(knowledgeAgent.getName(), knowledgeAgent, ifMatch, ifNoneMatch, null,
+ context)
.onErrorMap(MappingUtils::exceptionMapper);
} catch (RuntimeException ex) {
return monoError(LOGGER, ex);
@@ -1361,7 +1625,7 @@ Mono> createOrUpdateKnowledgeAgentWithResponse(String a
/**
* Retrieves an agent definition.
- *
+ *
* @param agentName The name of the agent to retrieve.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
@@ -1370,13 +1634,12 @@ Mono> createOrUpdateKnowledgeAgentWithResponse(String a
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getKnowledgeAgent(String agentName) {
- return getKnowledgeAgentWithResponse(agentName, Context.NONE).map(Response::getValue);
-
+ return getKnowledgeAgentWithResponse(agentName).map(Response::getValue);
}
/**
* Retrieves an agent definition.
- *
+ *
* @param agentName The name of the agent to retrieve.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
@@ -1400,7 +1663,7 @@ Mono> getKnowledgeAgentWithResponse(String agentName, C
/**
* Lists all agents available for a search service.
- *
+ *
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
@@ -1418,50 +1681,228 @@ public PagedFlux listKnowledgeAgents() {
/**
* Deletes an existing agent.
- *
+ *
* @param agentName The name of the agent to delete.
- * @param ifMatch Defines the If-Match condition. The operation will be performed only if the ETag on the server
- * matches this value.
- * @param ifNoneMatch Defines the If-None-Match condition. The operation will be performed only if the ETag on the
- * server does not match this value.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return A {@link Mono} that completes when a successful response is received.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono deleteKnowledgeAgent(String agentName, String ifMatch, String ifNoneMatch) {
- return deleteKnowledgeAgentWithResponse(agentName, ifMatch, ifNoneMatch, Context.NONE)
- .flatMap(FluxUtil::toMono);
+ public Mono deleteKnowledgeAgent(String agentName) {
+ return deleteKnowledgeAgentWithResponse(agentName, null).flatMap(FluxUtil::toMono);
}
/**
* Deletes an existing agent.
- *
+ *
* @param agentName The name of the agent to delete.
- * @param ifMatch Defines the If-Match condition. The operation will be performed only if the ETag on the server
- * matches this value.
- * @param ifNoneMatch Defines the If-None-Match condition. The operation will be performed only if the ETag on the
- * server does not match this value.
+ * @param matchConditions Defining {@code If-Match} and {@code If-None-Match} conditions. If null is passed, no
+ * conditions will be applied.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the {@link Response} on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> deleteKnowledgeAgentWithResponse(String agentName, String ifMatch, String ifNoneMatch) {
- return withContext(context -> deleteKnowledgeAgentWithResponse(agentName, ifMatch, ifNoneMatch, context));
+ public Mono> deleteKnowledgeAgentWithResponse(String agentName, MatchConditions matchConditions) {
+ return withContext(context -> deleteKnowledgeAgentWithResponse(agentName, matchConditions, context));
}
- Mono> deleteKnowledgeAgentWithResponse(String agentName, String ifMatch, String ifNoneMatch,
+ Mono> deleteKnowledgeAgentWithResponse(String agentName, MatchConditions matchConditions,
Context context) {
try {
+ String ifMatch = matchConditions != null ? matchConditions.getIfMatch() : null;
+ String ifNoneMatch = matchConditions != null ? matchConditions.getIfNoneMatch() : null;
return restClient.getKnowledgeAgents()
.deleteWithResponseAsync(agentName, ifMatch, ifNoneMatch, null, context)
.onErrorMap(MappingUtils::exceptionMapper);
} catch (RuntimeException ex) {
return monoError(LOGGER, ex);
}
+ }
+
+ /**
+ * Creates a new knowledge source.
+ *
+ * @param knowledgeSource The definition of the knowledge source to create.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Mono} that will produce the created knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono createKnowledgeSource(KnowledgeSource knowledgeSource) {
+ return createKnowledgeSourceWithResponse(knowledgeSource).map(Response::getValue);
+ }
+
+ /**
+ * Creates a new knowledge source.
+ *
+ * @param knowledgeSource The definition of the knowledge source to create.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Mono} that will produce a {@link Response} containing the created knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono> createKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource) {
+ return withContext(context -> createKnowledgeSourceWithResponse(knowledgeSource, context));
+ }
+
+ Mono> createKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource,
+ Context context) {
+ try {
+ return restClient.getKnowledgeSources()
+ .createWithResponseAsync(knowledgeSource, null, context)
+ .onErrorMap(MappingUtils::exceptionMapper);
+ } catch (RuntimeException ex) {
+ return monoError(LOGGER, ex);
+ }
+ }
+
+ /**
+ * Creates or updates a knowledge source.
+ *
+ * @param knowledgeSource The definition of the knowledge source to create or update.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Mono} that will produce the created or updated knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono createOrUpdateKnowledgeSource(KnowledgeSource knowledgeSource) {
+ return createOrUpdateKnowledgeSourceWithResponse(knowledgeSource, null).map(Response::getValue);
+ }
+
+ /**
+ * Creates or updates a knowledge source.
+ *
+ * @param knowledgeSource The definition of the knowledge source to create or update.
+ * @param matchConditions Defining {@code If-Match} and {@code If-None-Match} conditions. If null is passed, no
+ * conditions will be applied.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Mono} that produces a {@link Response} containing the created or updated knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono> createOrUpdateKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource,
+ MatchConditions matchConditions) {
+ return withContext(
+ context -> createOrUpdateKnowledgeSourceWithResponse(knowledgeSource, matchConditions, context));
+ }
+
+ Mono> createOrUpdateKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource,
+ MatchConditions matchConditions, Context context) {
+ try {
+ String ifMatch = matchConditions != null ? matchConditions.getIfMatch() : null;
+ String ifNoneMatch = matchConditions != null ? matchConditions.getIfNoneMatch() : null;
+ return restClient.getKnowledgeSources()
+ .createOrUpdateWithResponseAsync(knowledgeSource.getName(), knowledgeSource, ifMatch, ifNoneMatch, null,
+ context)
+ .onErrorMap(MappingUtils::exceptionMapper);
+ } catch (RuntimeException ex) {
+ return monoError(LOGGER, ex);
+ }
+ }
+
+ /**
+ * Retrieves a knowledge source.
+ *
+ * @param sourceName The name of the knowledge source to retrieve.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Mono} that will produce the retrieved knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono getKnowledgeSource(String sourceName) {
+ return getKnowledgeSourceWithResponse(sourceName).map(Response::getValue);
+ }
+
+ /**
+ * Retrieves a knowledge source.
+ *
+ * @param sourceName The name of the knowledge source to retrieve.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Mono} that will produce a {@link Response} containing the retrieved knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono> getKnowledgeSourceWithResponse(String sourceName) {
+ return withContext(context -> getKnowledgeSourceWithResponse(sourceName, context));
+ }
+
+ Mono> getKnowledgeSourceWithResponse(String sourceName, Context context) {
+ try {
+ return restClient.getKnowledgeSources()
+ .getWithResponseAsync(sourceName, null, context)
+ .onErrorMap(MappingUtils::exceptionMapper);
+ } catch (RuntimeException ex) {
+ return monoError(LOGGER, ex);
+ }
+ }
+
+ /**
+ * Lists all knowledge sources available for a search service.
+ *
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link PagedFlux} of knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.COLLECTION)
+ public PagedFlux listKnowledgeSources() {
+ try {
+ return restClient.getKnowledgeSources().listAsync(null, Context.NONE);
+ } catch (RuntimeException ex) {
+ RuntimeException mappedException = (RuntimeException) MappingUtils.exceptionMapper(ex);
+ return pagedFluxError(LOGGER, mappedException);
+ }
+ }
+ /**
+ * Deletes an existing knowledge source.
+ *
+ * @param sourceName The name of the knowledge source to delete.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Mono} that completes successfully if the knowledge source was deleted.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono deleteKnowledgeSource(String sourceName) {
+ return deleteKnowledgeSourceWithResponse(sourceName, null).flatMap(FluxUtil::toMono);
+ }
+
+ /**
+ * Deletes an existing knowledge source.
+ *
+ * @param sourceName The name of the knowledge source to delete.
+ * @param matchConditions Defining {@code If-Match} and {@code If-None-Match} conditions. If null is passed, no
+ * conditions will be applied.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Mono} that produces a {@link Response} if the knowledge source was deleted.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono> deleteKnowledgeSourceWithResponse(String sourceName, MatchConditions matchConditions) {
+ return withContext(context -> deleteKnowledgeSourceWithResponse(sourceName, matchConditions, context));
+ }
+
+ Mono> deleteKnowledgeSourceWithResponse(String sourceName, MatchConditions matchConditions,
+ Context context) {
+ try {
+ String ifMatch = matchConditions != null ? matchConditions.getIfMatch() : null;
+ String ifNoneMatch = matchConditions != null ? matchConditions.getIfNoneMatch() : null;
+ return restClient.getKnowledgeSources()
+ .deleteWithResponseAsync(sourceName, ifMatch, ifNoneMatch, null, context)
+ .onErrorMap(MappingUtils::exceptionMapper);
+ } catch (RuntimeException ex) {
+ return monoError(LOGGER, ex);
+ }
}
}
diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexClient.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexClient.java
index 79ab904d9f58..ee36c49b268d 100644
--- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexClient.java
+++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexClient.java
@@ -6,6 +6,7 @@
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.HttpPipeline;
+import com.azure.core.http.MatchConditions;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.Response;
@@ -25,8 +26,10 @@
import com.azure.search.documents.indexes.models.FieldBuilderOptions;
import com.azure.search.documents.indexes.models.IndexStatisticsSummary;
import com.azure.search.documents.indexes.models.KnowledgeAgent;
+import com.azure.search.documents.indexes.models.KnowledgeSource;
import com.azure.search.documents.indexes.models.LexicalAnalyzerName;
import com.azure.search.documents.indexes.models.LexicalTokenizerName;
+import com.azure.search.documents.indexes.models.SearchAlias;
import com.azure.search.documents.indexes.models.SearchField;
import com.azure.search.documents.indexes.models.SearchIndex;
import com.azure.search.documents.indexes.models.SearchIndexStatistics;
@@ -58,7 +61,8 @@
*
*
* A synonym map is service-level object that contains user-defined synonyms. This object is maintained
- * independently from search indexes. Once uploaded, you can point any searchable field to the synonym map (one per field).
+ * independently of search indexes. Once uploaded, you can point any searchable field to the synonym map
+ * (one per field).
*
*
*
@@ -689,7 +693,7 @@ public PagedIterable listIndexNames() {
public PagedIterable listIndexNames(Context context) {
try {
return new PagedIterable<>(
- () -> MappingUtils.mappingPagingSearchIndexNames(this.listIndexesWithResponse("name", context)));
+ () -> MappingUtils.mapPagedSearchIndexNames(this.listIndexesWithResponse("name", context)));
} catch (RuntimeException ex) {
throw LOGGER.logExceptionAsError(ex);
}
@@ -878,7 +882,7 @@ public PagedIterable analyzeText(String indexName, AnalyzeTex
private PagedResponse analyzeTextWithResponse(String indexName,
AnalyzeTextOptions analyzeTextOptions, Context context) {
return Utility.executeRestCallWithExceptionHandling(
- () -> MappingUtils.mappingTokenInfo(restClient.getIndexes()
+ () -> MappingUtils.mapPagedTokenInfos(restClient.getIndexes()
.analyzeWithResponse(indexName, AnalyzeRequestConverter.map(analyzeTextOptions), null, context)),
LOGGER);
}
@@ -1039,7 +1043,7 @@ public PagedIterable listSynonymMaps() {
public PagedIterable listSynonymMaps(Context context) {
try {
return new PagedIterable<>(
- () -> MappingUtils.mappingPagingSynonymMap(listSynonymMapsWithResponse(null, context)));
+ () -> MappingUtils.mapPagedSynonymMaps(listSynonymMapsWithResponse(null, context)));
} catch (RuntimeException ex) {
throw LOGGER.logExceptionAsError(ex);
}
@@ -1098,7 +1102,7 @@ public PagedIterable listSynonymMapNames() {
public PagedIterable listSynonymMapNames(Context context) {
try {
return new PagedIterable<>(
- () -> MappingUtils.mappingPagingSynonymMapNames(listSynonymMapsWithResponse("name", context)));
+ () -> MappingUtils.mapPagedSynonymMapNames(listSynonymMapsWithResponse("name", context)));
} catch (RuntimeException ex) {
throw LOGGER.logExceptionAsError(ex);
}
@@ -1310,9 +1314,276 @@ public static List buildSearchFields(Class> model, FieldBuilderOp
return SearchIndexAsyncClient.buildSearchFields(model, options);
}
+ /**
+ * Creates a new Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Create the search alias named "my-alias".
+ *
+ *
+ *
+ * SearchAlias searchAlias = SEARCH_INDEX_CLIENT.createAlias(new SearchAlias("my-alias",
+ * Collections.singletonList("index-to-alias")));
+ * System.out.printf("Created alias '%s' that aliases index '%s'.", searchAlias.getName(),
+ * searchAlias.getIndexes().get(0));
+ *
+ *
+ *
+ * @param alias definition of the alias to create.
+ * @return the created alias.
+ */
+ public SearchAlias createAlias(SearchAlias alias) {
+ return createAliasWithResponse(alias, Context.NONE).getValue();
+ }
+
+ /**
+ * Creates a new Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Create the search alias named "my-alias".
+ *
+ *
+ *
+ * Response<SearchAlias> response = SEARCH_INDEX_CLIENT.createAliasWithResponse(new SearchAlias("my-alias",
+ * Collections.singletonList("index-to-alias")), new Context(KEY_1, VALUE_1));
+ *
+ * System.out.printf("Response status code %d. Created alias '%s' that aliases index '%s'.",
+ * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0));
+ *
+ *
+ *
+ * @param alias definition of the alias to create.
+ * @param context additional context that is passed through the HTTP pipeline during the service call
+ * @return the created alias.
+ */
+ public Response createAliasWithResponse(SearchAlias alias, Context context) {
+ try {
+ return restClient.getAliases().createWithResponse(alias, null, context);
+ } catch (RuntimeException ex) {
+ throw LOGGER.logExceptionAsError(ex);
+ }
+ }
+
+ /**
+ * Creates or updates an Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Create then update the search alias named "my-alias".
+ *
+ *
+ *
+ * SearchAlias searchAlias = SEARCH_INDEX_CLIENT.createOrUpdateAlias(
+ * new SearchAlias("my-alias", Collections.singletonList("index-to-alias")));
+ *
+ * System.out.printf("Created alias '%s' that aliases index '%s'.", searchAlias.getName(),
+ * searchAlias.getIndexes().get(0));
+ *
+ * searchAlias = SEARCH_INDEX_CLIENT.createOrUpdateAlias(new SearchAlias(searchAlias.getName(),
+ * Collections.singletonList("new-index-to-alias")));
+ *
+ * System.out.printf("Updated alias '%s' to aliases index '%s'.", searchAlias.getName(),
+ * searchAlias.getIndexes().get(0));
+ *
+ *
+ *
+ * @param alias definition of the alias to create or update.
+ * @return the created or updated alias.
+ */
+ public SearchAlias createOrUpdateAlias(SearchAlias alias) {
+ return createOrUpdateAliasWithResponse(alias, false, Context.NONE).getValue();
+ }
+
+ /**
+ * Creates or updates an Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Create then update the search alias named "my-alias".
+ *
+ *
+ *
+ * Response<SearchAlias> response = SEARCH_INDEX_CLIENT.createOrUpdateAliasWithResponse(
+ * new SearchAlias("my-alias", Collections.singletonList("index-to-alias")), false, new Context(KEY_1, VALUE_1));
+ *
+ * System.out.printf("Response status code %d. Created alias '%s' that aliases index '%s'.",
+ * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0));
+ *
+ * response = SEARCH_INDEX_CLIENT.createOrUpdateAliasWithResponse(
+ * new SearchAlias(response.getValue().getName(), Collections.singletonList("new-index-to-alias"))
+ * .setETag(response.getValue().getETag()), true, new Context(KEY_1, VALUE_1));
+ *
+ * System.out.printf("Response status code %d. Updated alias '%s' that aliases index '%s'.",
+ * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0));
+ *
+ *
+ *
+ * @param alias definition of the alias to create or update.
+ * @param onlyIfUnchanged only update the alias if the eTag matches the alias on the service.
+ * @param context additional context that is passed through the HTTP pipeline during the service call
+ * @return the created or updated alias.
+ */
+ public Response createOrUpdateAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged,
+ Context context) {
+ return Utility.executeRestCallWithExceptionHandling(() -> restClient.getAliases()
+ .createOrUpdateWithResponse(alias.getName(), alias, onlyIfUnchanged ? alias.getETag() : null, null, null,
+ context),
+ LOGGER);
+ }
+
+ /**
+ * Gets the Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Get the search alias named "my-alias".
+ *
+ *
+ *
+ * SearchAlias searchAlias = SEARCH_INDEX_CLIENT.getAlias("my-alias");
+ *
+ * System.out.printf("Retrieved alias '%s' that aliases index '%s'.", searchAlias.getName(),
+ * searchAlias.getIndexes().get(0));
+ *
+ *
+ *
+ * @param aliasName name of the alias to get.
+ * @return the retrieved alias.
+ */
+ public SearchAlias getAlias(String aliasName) {
+ return getAliasWithResponse(aliasName, Context.NONE).getValue();
+ }
+
+ /**
+ * Gets the Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Get the search alias named "my-alias".
+ *
+ *
+ *
+ * Response<SearchAlias> response = SEARCH_INDEX_CLIENT.getAliasWithResponse("my-alias", new Context(KEY_1, VALUE_1));
+ *
+ * System.out.printf("Response status code %d. Retrieved alias '%s' that aliases index '%s'.",
+ * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0));
+ *
+ *
+ *
+ * @param aliasName name of the alias to get.
+ * @param context additional context that is passed through the HTTP pipeline during the service call
+ * @return the retrieved alias.
+ */
+ public Response getAliasWithResponse(String aliasName, Context context) {
+ return Utility.executeRestCallWithExceptionHandling(
+ () -> restClient.getAliases().getWithResponse(aliasName, null, context), LOGGER);
+ }
+
+ /**
+ * Deletes the Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Delete the search alias named "my-alias".
+ *
+ *
+ *
+ * SEARCH_INDEX_CLIENT.deleteAlias("my-alias");
+ *
+ * System.out.println("Deleted alias 'my-alias'.");
+ *
+ *
+ *
+ * @param aliasName name of the alias to delete.
+ */
+ public void deleteAlias(String aliasName) {
+ deleteAliasWithResponse(aliasName, null, Context.NONE);
+ }
+
+ /**
+ * Deletes the Azure AI Search alias.
+ *
+ * Code Sample
+ *
+ * Delete the search alias named "my-alias".
+ *
+ *
+ *
+ * SearchAlias searchAlias = SEARCH_INDEX_CLIENT.getAlias("my-alias");
+ *
+ * Response<Void> response = SEARCH_INDEX_CLIENT.deleteAliasWithResponse(searchAlias, true,
+ * new Context(KEY_1, VALUE_1));
+ *
+ * System.out.printf("Response status code %d. Deleted alias 'my-alias'.", response.getStatusCode());
+ *
+ *
+ *
+ * @param alias the alias to delete.
+ * @param onlyIfUnchanged only delete the alias if the eTag matches the alias on the service.
+ * @param context additional context that is passed through the HTTP pipeline during the service call
+ * @return a response indicating the alias has been deleted.
+ */
+ public Response deleteAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged, Context context) {
+ return deleteAliasWithResponse(alias.getName(), onlyIfUnchanged ? alias.getETag() : null, context);
+ }
+
+ Response deleteAliasWithResponse(String aliasName, String eTag, Context context) {
+ return Utility.executeRestCallWithExceptionHandling(
+ () -> restClient.getAliases().deleteWithResponse(aliasName, eTag, null, null, context), LOGGER);
+ }
+
+ /**
+ * Lists all aliases in the Azure AI Search service.
+ *
+ * Code Sample
+ *
+ * List aliases
+ *
+ *
+ *
+ * SEARCH_INDEX_CLIENT.listAliases()
+ * .forEach(searchAlias -> System.out.printf("Listed alias '%s' that aliases index '%s'.",
+ * searchAlias.getName(), searchAlias.getIndexes().get(0)));
+ *
+ *
+ *
+ * @return a list of aliases in the service.
+ */
+ public PagedIterable listAliases() {
+ return listAliases(Context.NONE);
+ }
+
+ /**
+ * Lists all aliases in the Azure AI Search service.
+ *
+ * Code Sample
+ *
+ * List aliases
+ *
+ *
+ *
+ * SEARCH_INDEX_CLIENT.listAliases(new Context(KEY_1, VALUE_1))
+ * .forEach(searchAlias -> System.out.printf("Listed alias '%s' that aliases index '%s'.",
+ * searchAlias.getName(), searchAlias.getIndexes().get(0)));
+ *
+ *
+ *
+ * @param context additional context that is passed through the HTTP pipeline during the service call
+ * @return a list of aliases in the service.
+ */
+ public PagedIterable listAliases(Context context) {
+ try {
+ return new PagedIterable<>(() -> restClient.getAliases().listSinglePage(null, context));
+ } catch (RuntimeException ex) {
+ throw LOGGER.logExceptionAsError(ex);
+ }
+ }
+
/**
* Creates a new agent.
- *
+ *
* @param knowledgeAgent The definition of the agent to create.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
@@ -1322,12 +1593,11 @@ public static List buildSearchFields(Class> model, FieldBuilderOp
@ServiceMethod(returns = ReturnType.SINGLE)
public KnowledgeAgent createKnowledgeAgent(KnowledgeAgent knowledgeAgent) {
return createKnowledgeAgentWithResponse(knowledgeAgent, Context.NONE).getValue();
-
}
/**
* Creates a new agent.
- *
+ *
* @param knowledgeAgent The definition of the agent to create.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
@@ -1339,39 +1609,28 @@ public KnowledgeAgent createKnowledgeAgent(KnowledgeAgent knowledgeAgent) {
public Response createKnowledgeAgentWithResponse(KnowledgeAgent knowledgeAgent, Context context) {
return Utility.executeRestCallWithExceptionHandling(
() -> restClient.getKnowledgeAgents().createWithResponse(knowledgeAgent, null, context), LOGGER);
-
}
/**
* Creates a new agent or updates an agent if it already exists.
- *
- * @param agentName The name of the agent to create or update.
+ *
* @param knowledgeAgent The definition of the agent to create or update.
- * @param ifMatch Defines the If-Match condition. The operation will be performed only if the ETag on the server
- * matches this value.
- * @param ifNoneMatch Defines the If-None-Match condition. The operation will be performed only if the ETag on the
- * server does not match this value.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public KnowledgeAgent createOrUpdateKnowledgeAgent(String agentName, KnowledgeAgent knowledgeAgent, String ifMatch,
- String ifNoneMatch) {
- return createOrUpdateKnowledgeAgentWithResponse(agentName, knowledgeAgent, ifMatch, ifNoneMatch, Context.NONE)
- .getValue();
+ public KnowledgeAgent createOrUpdateKnowledgeAgent(KnowledgeAgent knowledgeAgent) {
+ return createOrUpdateKnowledgeAgentWithResponse(knowledgeAgent, null, Context.NONE).getValue();
}
/**
* Creates a new agent or updates an agent if it already exists.
- *
- * @param agentName The name of the agent to create or update.
+ *
* @param knowledgeAgent The definition of the agent to create or update.
- * @param ifMatch Defines the If-Match condition. The operation will be performed only if the ETag on the server
- * matches this value.
- * @param ifNoneMatch Defines the If-None-Match condition. The operation will be performed only if the ETag on the
- * server does not match this value.
+ * @param matchConditions Defining {@code If-Match} and {@code If-None-Match} conditions. If null is passed, no
+ * conditions will be applied.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
@@ -1379,18 +1638,18 @@ public KnowledgeAgent createOrUpdateKnowledgeAgent(String agentName, KnowledgeAg
* @return the response body along with {@link Response}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Response createOrUpdateKnowledgeAgentWithResponse(String agentName,
- KnowledgeAgent knowledgeAgent, String ifMatch, String ifNoneMatch, Context context) {
- return Utility
- .executeRestCallWithExceptionHandling(
- () -> restClient.getKnowledgeAgents()
- .createOrUpdateWithResponse(agentName, knowledgeAgent, ifMatch, ifNoneMatch, null, context),
- LOGGER);
+ public Response createOrUpdateKnowledgeAgentWithResponse(KnowledgeAgent knowledgeAgent,
+ MatchConditions matchConditions, Context context) {
+ String ifMatch = matchConditions != null ? matchConditions.getIfMatch() : null;
+ String ifNoneMatch = matchConditions != null ? matchConditions.getIfNoneMatch() : null;
+ return Utility.executeRestCallWithExceptionHandling(() -> restClient.getKnowledgeAgents()
+ .createOrUpdateWithResponse(knowledgeAgent.getName(), knowledgeAgent, ifMatch, ifNoneMatch, null, context),
+ LOGGER);
}
/**
* Retrieves an agent definition.
- *
+ *
* @param agentName The name of the agent to retrieve.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
@@ -1405,7 +1664,7 @@ public KnowledgeAgent getKnowledgeAgent(String agentName) {
/**
* Retrieves an agent definition.
- *
+ *
* @param agentName The name of the agent to retrieve.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
@@ -1421,7 +1680,7 @@ public Response getKnowledgeAgentWithResponse(String agentName,
/**
* Lists all agents available for a search service.
- *
+ *
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
@@ -1434,7 +1693,7 @@ public PagedIterable listKnowledgeAgents() {
/**
* Lists all agents available for a search service.
- *
+ *
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
@@ -1449,29 +1708,23 @@ public PagedIterable listKnowledgeAgents(Context context) {
/**
* Deletes an existing agent.
- *
+ *
* @param agentName The name of the agent to delete.
- * @param ifMatch Defines the If-Match condition. The operation will be performed only if the ETag on the server
- * matches this value.
- * @param ifNoneMatch Defines the If-None-Match condition. The operation will be performed only if the ETag on the
- * server does not match this value.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public void deleteKnowledgeAgent(String agentName, String ifMatch, String ifNoneMatch) {
- deleteKnowledgeAgentWithResponse(agentName, ifMatch, ifNoneMatch, Context.NONE).getValue();
+ public void deleteKnowledgeAgent(String agentName) {
+ deleteKnowledgeAgentWithResponse(agentName, null, Context.NONE).getValue();
}
/**
* Deletes an existing agent.
- *
+ *
* @param agentName The name of the agent to delete.
- * @param ifMatch Defines the If-Match condition. The operation will be performed only if the ETag on the server
- * matches this value.
- * @param ifNoneMatch Defines the If-None-Match condition. The operation will be performed only if the ETag on the
- * server does not match this value.
+ * @param matchConditions Defining {@code If-Match} and {@code If-None-Match} conditions. If null is passed, no
+ * conditions will be applied.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorResponseException thrown if the request is rejected by server.
@@ -1479,11 +1732,174 @@ public void deleteKnowledgeAgent(String agentName, String ifMatch, String ifNone
* @return the {@link Response}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Response deleteKnowledgeAgentWithResponse(String agentName, String ifMatch, String ifNoneMatch,
+ public Response deleteKnowledgeAgentWithResponse(String agentName, MatchConditions matchConditions,
Context context) {
+ String ifMatch = matchConditions != null ? matchConditions.getIfMatch() : null;
+ String ifNoneMatch = matchConditions != null ? matchConditions.getIfNoneMatch() : null;
return Utility.executeRestCallWithExceptionHandling(
() -> restClient.getKnowledgeAgents().deleteWithResponse(agentName, ifMatch, ifNoneMatch, null, context),
LOGGER);
+ }
+ /**
+ * Creates a new knowledge source.
+ *
+ * @param knowledgeSource The definition of the knowledge source to create.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return The created knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public KnowledgeSource createKnowledgeSource(KnowledgeSource knowledgeSource) {
+ return createKnowledgeSourceWithResponse(knowledgeSource, Context.NONE).getValue();
+ }
+
+ /**
+ * Creates a new knowledge source.
+ *
+ * @param knowledgeSource The definition of the knowledge source to create.
+ * @param context The context to associate with this operation.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Response} containing the created knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Response createKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource,
+ Context context) {
+ return Utility.executeRestCallWithExceptionHandling(
+ () -> restClient.getKnowledgeSources().createWithResponse(knowledgeSource, null, context), LOGGER);
+ }
+
+ /**
+ * Creates or updates a knowledge source.
+ *
+ * @param knowledgeSource The definition of the knowledge source to create or update.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return The created or updated knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public KnowledgeSource createOrUpdateKnowledgeSource(KnowledgeSource knowledgeSource) {
+ return createOrUpdateKnowledgeSourceWithResponse(knowledgeSource, null, Context.NONE).getValue();
+ }
+
+ /**
+ * Creates or updates a knowledge source.
+ *
+ * @param knowledgeSource The definition of the knowledge source to create or update.
+ * @param matchConditions Defining {@code If-Match} and {@code If-None-Match} conditions. If null is passed, no
+ * conditions will be applied.
+ * @param context The context to associate with this operation.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Response} containing the created or updated knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Response createOrUpdateKnowledgeSourceWithResponse(KnowledgeSource knowledgeSource,
+ MatchConditions matchConditions, Context context) {
+ String ifMatch = matchConditions != null ? matchConditions.getIfMatch() : null;
+ String ifNoneMatch = matchConditions != null ? matchConditions.getIfNoneMatch() : null;
+ return Utility.executeRestCallWithExceptionHandling(() -> restClient.getKnowledgeSources()
+ .createOrUpdateWithResponse(knowledgeSource.getName(), knowledgeSource, ifMatch, ifNoneMatch, null,
+ context),
+ LOGGER);
+ }
+
+ /**
+ * Retrieves a knowledge source definition.
+ *
+ * @param sourceName The name of the knowledge source to retrieve.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return The retrieved knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public KnowledgeSource getKnowledgeSource(String sourceName) {
+ return getKnowledgeSourceWithResponse(sourceName, Context.NONE).getValue();
+
+ }
+
+ /**
+ * Retrieves a knowledge source definition.
+ *
+ * @param sourceName The name of the knowledge source to retrieve.
+ * @param context The context to associate with this operation.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Response} containing the retrieved knowledge source.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Response getKnowledgeSourceWithResponse(String sourceName, Context context) {
+ return Utility.executeRestCallWithExceptionHandling(
+ () -> restClient.getKnowledgeSources().getWithResponse(sourceName, null, context), LOGGER);
+ }
+
+ /**
+ * Lists all knowledge sources available for a search service.
+ *
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link PagedIterable} of knowledge sources.
+ */
+ @ServiceMethod(returns = ReturnType.COLLECTION)
+ public PagedIterable listKnowledgeSources() {
+ return listKnowledgeSources(Context.NONE);
+ }
+
+ /**
+ * Lists all knowledge sources available for a search service.
+ *
+ * @param context The context to associate with this operation.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link PagedIterable} of knowledge sources.
+ */
+ @ServiceMethod(returns = ReturnType.COLLECTION)
+ public PagedIterable listKnowledgeSources(Context context) {
+ return Utility.executeRestCallWithExceptionHandling(() -> restClient.getKnowledgeSources().list(null, context),
+ LOGGER);
+ }
+
+ /**
+ * Deletes an existing knowledge agent.
+ *
+ * @param sourceName The name of the knowledge source to delete.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public void deleteKnowledgeSource(String sourceName) {
+ deleteKnowledgeSourceWithResponse(sourceName, null, Context.NONE).getValue();
+ }
+
+ /**
+ * Deletes an existing knowledge source.
+ *
+ * @param sourceName The name of the knowledge source to delete.
+ * @param matchConditions Defining {@code If-Match} and {@code If-None-Match} conditions. If null is passed, no
+ * conditions will be applied.
+ * @param context The context to associate with this operation.
+ * @throws IllegalArgumentException thrown if parameters fail the validation.
+ * @throws ErrorResponseException thrown if the request is rejected by server.
+ * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+ * @return A {@link Response} indicating deletion completed.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Response deleteKnowledgeSourceWithResponse(String sourceName, MatchConditions matchConditions,
+ Context context) {
+ String ifMatch = matchConditions != null ? matchConditions.getIfMatch() : null;
+ String ifNoneMatch = matchConditions != null ? matchConditions.getIfNoneMatch() : null;
+ return Utility.executeRestCallWithExceptionHandling(
+ () -> restClient.getKnowledgeSources().deleteWithResponse(sourceName, ifMatch, ifNoneMatch, null, context),
+ LOGGER);
}
}
diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerAsyncClient.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerAsyncClient.java
index bc220d94b90e..6a287165dae9 100644
--- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerAsyncClient.java
+++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerAsyncClient.java
@@ -15,10 +15,15 @@
import com.azure.search.documents.SearchServiceVersion;
import com.azure.search.documents.implementation.util.MappingUtils;
import com.azure.search.documents.indexes.implementation.SearchServiceClientImpl;
+import com.azure.search.documents.indexes.implementation.models.DocumentKeysOrIds;
import com.azure.search.documents.indexes.implementation.models.ErrorResponseException;
import com.azure.search.documents.indexes.implementation.models.ListDataSourcesResult;
import com.azure.search.documents.indexes.implementation.models.ListIndexersResult;
import com.azure.search.documents.indexes.implementation.models.ListSkillsetsResult;
+import com.azure.search.documents.indexes.implementation.models.SkillNames;
+import com.azure.search.documents.indexes.models.CreateOrUpdateDataSourceConnectionOptions;
+import com.azure.search.documents.indexes.models.CreateOrUpdateIndexerOptions;
+import com.azure.search.documents.indexes.models.CreateOrUpdateSkillsetOptions;
import com.azure.search.documents.indexes.models.IndexerResyncBody;
import com.azure.search.documents.indexes.models.SearchIndexer;
import com.azure.search.documents.indexes.models.SearchIndexerDataSourceConnection;
@@ -26,6 +31,7 @@
import com.azure.search.documents.indexes.models.SearchIndexerStatus;
import reactor.core.publisher.Mono;
+import java.util.List;
import java.util.function.Function;
import static com.azure.core.util.FluxUtil.monoError;
@@ -499,6 +505,50 @@ public Mono> createOrUpdateDataSourc
context -> createOrUpdateDataSourceConnectionWithResponse(dataSource, onlyIfUnchanged, null, context));
}
+ /**
+ * Creates a new Azure AI Search data source or updates a data source if it already exists.
+ *
+ * Code Sample
+ *
+ * Create or update search indexer data source connection named "dataSource".
+ *
+ *
+ *
+ * SEARCH_INDEXER_ASYNC_CLIENT.getDataSourceConnection("dataSource")
+ * .flatMap(dataSource -> {
+ * dataSource.setContainer(new SearchIndexerDataContainer("updatecontainer"));
+ * return SEARCH_INDEXER_ASYNC_CLIENT.createOrUpdateDataSourceConnectionWithResponse(
+ * new CreateOrUpdateDataSourceConnectionOptions(dataSource)
+ * .setOnlyIfUnchanged(true)
+ * .setCacheResetRequirementsIgnored(true));
+ * })
+ * .subscribe(updateDataSource ->
+ * System.out.printf("The status code of the response is %s.%nThe dataSource name is %s. "
+ * + "The container name of dataSource is %s.%n", updateDataSource.getStatusCode(),
+ * updateDataSource.getValue().getName(), updateDataSource.getValue().getContainer().getName()));
+ *
+ *
+ *
+ * @param options The options used to create or update the
+ * {@link SearchIndexerDataSourceConnection data source connection}.
+ * @return a data source response.
+ * @throws NullPointerException If {@code options} is null.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono>
+ createOrUpdateDataSourceConnectionWithResponse(CreateOrUpdateDataSourceConnectionOptions options) {
+ if (options == null) {
+ return monoError(LOGGER, new NullPointerException("'options' cannot be null."));
+ }
+
+ return withContext(context -> createOrUpdateDataSourceConnectionWithResponse(options.getDataSourceConnection(),
+ options.isOnlyIfUnchanged(), options.isCacheResetRequirementsIgnored(), context));
+ }
+
Mono> createOrUpdateDataSourceConnectionWithResponse(
SearchIndexerDataSourceConnection dataSource, boolean onlyIfUnchanged, Boolean ignoreResetRequirements,
Context context) {
@@ -680,7 +730,7 @@ public PagedFlux listDataSourceConnections()
try {
return new PagedFlux<>(
() -> withContext(context -> this.listDataSourceConnectionsWithResponse(null, context))
- .map(MappingUtils::mappingPagingDataSource));
+ .map(MappingUtils::mapPagedDataSources));
} catch (RuntimeException ex) {
return pagedFluxError(LOGGER, ex);
}
@@ -707,7 +757,7 @@ public PagedFlux listDataSourceConnectionNames() {
try {
return new PagedFlux<>(
() -> withContext(context -> this.listDataSourceConnectionsWithResponse("name", context))
- .map(MappingUtils::mappingPagingDataSourceNames));
+ .map(MappingUtils::mapPagedDataSourceNames));
} catch (RuntimeException ex) {
return pagedFluxError(LOGGER, ex);
}
@@ -920,6 +970,52 @@ public Mono> createOrUpdateIndexerWithResponse(SearchInd
return withContext(context -> createOrUpdateIndexerWithResponse(indexer, onlyIfUnchanged, null, null, context));
}
+ /**
+ * Creates a new Azure AI Search indexer or updates an indexer if it already exists.
+ *
+ * Code Sample
+ *
+ * Create or update search indexer named "searchIndexer".
+ *
+ *
+ *
+ * SEARCH_INDEXER_ASYNC_CLIENT.getIndexer("searchIndexer")
+ * .flatMap(searchIndexerFromService -> {
+ * searchIndexerFromService.setFieldMappings(Collections.singletonList(
+ * new FieldMapping("hotelName").setTargetFieldName("HotelName")));
+ * return SEARCH_INDEXER_ASYNC_CLIENT.createOrUpdateIndexerWithResponse(
+ * new CreateOrUpdateIndexerOptions(searchIndexerFromService)
+ * .setOnlyIfUnchanged(true)
+ * .setCacheReprocessingChangeDetectionDisabled(false)
+ * .setCacheResetRequirementsIgnored(true));
+ * })
+ * .subscribe(indexerFromService ->
+ * System.out.printf("The status code of the response is %s.%nThe indexer name is %s. "
+ * + "The target field name of indexer is %s.%n", indexerFromService.getStatusCode(),
+ * indexerFromService.getValue().getName(),
+ * indexerFromService.getValue().getFieldMappings().get(0).getTargetFieldName()));
+ *
+ *
+ *
+ * @param options The options used to create or update the {@link SearchIndexer indexer}.
+ * @return a response containing the created Indexer.
+ * @throws NullPointerException If {@code options} is null.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono> createOrUpdateIndexerWithResponse(CreateOrUpdateIndexerOptions options) {
+ if (options == null) {
+ return monoError(LOGGER, new NullPointerException("'options' cannot be null."));
+ }
+
+ return withContext(context -> createOrUpdateIndexerWithResponse(options.getIndexer(),
+ options.isOnlyIfUnchanged(), options.isCacheReprocessingChangeDetectionDisabled(),
+ options.isCacheResetRequirementsIgnored(), context));
+ }
+
Mono> createOrUpdateIndexerWithResponse(SearchIndexer indexer, boolean onlyIfUnchanged,
Boolean disableCacheReprocessingChangeDetection, Boolean ignoreResetRequirements, Context context) {
if (indexer == null) {
@@ -1016,7 +1112,7 @@ Mono> getIndexerWithResponse(String indexerName, Context
public PagedFlux listIndexers() {
try {
return new PagedFlux<>(() -> withContext(context -> this.listIndexersWithResponse(null, context))
- .map(MappingUtils::mappingPagingSearchIndexer));
+ .map(MappingUtils::mapPagedSearchIndexers));
} catch (RuntimeException ex) {
return pagedFluxError(LOGGER, ex);
}
@@ -1042,7 +1138,7 @@ public PagedFlux listIndexers() {
public PagedFlux listIndexerNames() {
try {
return new PagedFlux<>(() -> withContext(context -> this.listIndexersWithResponse("name", context))
- .map(MappingUtils::mappingPagingSearchIndexerNames));
+ .map(MappingUtils::mapPagedSearchIndexerNames));
} catch (RuntimeException ex) {
return pagedFluxError(LOGGER, ex);
}
@@ -1298,6 +1394,93 @@ Mono> getIndexerStatusWithResponse(String indexerN
}
}
+ /**
+ * Resets specific documents in the datasource to be selectively re-ingested by the indexer.
+ *
+ *
+ *
+ * // Reset the documents with keys 1234 and 4321.
+ * SEARCH_INDEXER_ASYNC_CLIENT.resetDocuments("searchIndexer", false, Arrays.asList("1234", "4321"), null)
+ * // Clear the previous documents to be reset and replace them with documents 1235 and 5231.
+ * .then(SEARCH_INDEXER_ASYNC_CLIENT.resetDocuments("searchIndexer", true, Arrays.asList("1235", "5321"), null))
+ * .subscribe();
+ *
+ *
+ *
+ * @param indexerName The name of the indexer to reset documents for.
+ * @param overwrite If false, keys or IDs will be appended to existing ones. If true, only the keys or IDs in this
+ * payload will be queued to be re-ingested.
+ * @param documentKeys Document keys to be reset.
+ * @param datasourceDocumentIds Datasource document identifiers to be reset.
+ * @return A response signalling completion.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono resetDocuments(String indexerName, Boolean overwrite, List documentKeys,
+ List datasourceDocumentIds) {
+ return withContext(
+ context -> resetDocumentsWithResponse(indexerName, overwrite, documentKeys, datasourceDocumentIds, context))
+ .map(Response::getValue);
+ }
+
+ /**
+ * Resets specific documents in the datasource to be selectively re-ingested by the indexer.
+ *
+ *
+ *
+ * SEARCH_INDEXER_ASYNC_CLIENT.getIndexer("searchIndexer")
+ * .flatMap(searchIndexer -> SEARCH_INDEXER_ASYNC_CLIENT.resetDocumentsWithResponse(searchIndexer, false,
+ * Arrays.asList("1234", "4321"), null)
+ * .flatMap(resetDocsResult -> {
+ * System.out.printf("Requesting documents to be reset completed with status code %d.%n",
+ * resetDocsResult.getStatusCode());
+ *
+ * // Clear the previous documents to be reset and replace them with documents 1235 and 5231.
+ * return SEARCH_INDEXER_ASYNC_CLIENT.resetDocumentsWithResponse(searchIndexer, true,
+ * Arrays.asList("1235", "5321"), null);
+ * }))
+ * .subscribe(resetDocsResult ->
+ * System.out.printf("Overwriting the documents to be reset completed with status code %d.%n",
+ * resetDocsResult.getStatusCode()));
+ *
+ *
+ *
+ * @param indexer The indexer to reset documents for.
+ * @param overwrite If false, keys or IDs will be appended to existing ones. If true, only the keys or IDs in this
+ * payload will be queued to be re-ingested.
+ * @param documentKeys Document keys to be reset.
+ * @param datasourceDocumentIds Datasource document identifiers to be reset.
+ * @return A response signalling completion.
+ * @throws NullPointerException If {@code indexer} is null.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono> resetDocumentsWithResponse(SearchIndexer indexer, Boolean overwrite,
+ List documentKeys, List datasourceDocumentIds) {
+ if (indexer == null) {
+ return monoError(LOGGER, new NullPointerException("'indexer' cannot be null."));
+ }
+
+ return withContext(context -> resetDocumentsWithResponse(indexer.getName(), overwrite, documentKeys,
+ datasourceDocumentIds, context));
+ }
+
+ Mono> resetDocumentsWithResponse(String indexerName, Boolean overwrite, List documentKeys,
+ List datasourceDocumentIds, Context context) {
+ try {
+ DocumentKeysOrIds documentKeysOrIds
+ = new DocumentKeysOrIds().setDocumentKeys(documentKeys).setDatasourceDocumentIds(datasourceDocumentIds);
+
+ return restClient.getIndexers()
+ .resetDocsWithResponseAsync(indexerName, overwrite, documentKeysOrIds, null, context);
+ } catch (RuntimeException ex) {
+ return monoError(LOGGER, ex);
+ }
+ }
+
/**
* Creates a new skillset in an Azure AI Search service.
*
@@ -1478,7 +1661,7 @@ Mono> getSkillsetWithResponse(String skillsetNam
public PagedFlux listSkillsets() {
try {
return new PagedFlux<>(() -> withContext(context -> listSkillsetsWithResponse(null, context))
- .map(MappingUtils::mappingPagingSkillset));
+ .map(MappingUtils::mapPagedSkillsets));
} catch (RuntimeException ex) {
return pagedFluxError(LOGGER, ex);
}
@@ -1504,7 +1687,7 @@ public PagedFlux listSkillsets() {
public PagedFlux listSkillsetNames() {
try {
return new PagedFlux<>(() -> withContext(context -> listSkillsetsWithResponse("name", context))
- .map(MappingUtils::mappingPagingSkillsetNames));
+ .map(MappingUtils::mapPagedSkillsetNames));
} catch (RuntimeException ex) {
return pagedFluxError(LOGGER, ex);
}
@@ -1585,6 +1768,52 @@ public Mono> createOrUpdateSkillsetWithResponse(
context -> createOrUpdateSkillsetWithResponse(skillset, onlyIfUnchanged, null, null, context));
}
+ /**
+ * Creates a new Azure AI Search skillset or updates a skillset if it already exists.
+ *
+ * Code Sample
+ *
+ * Create or update search indexer skillset "searchIndexerSkillset".
+ *
+ *
+ *
+ * SEARCH_INDEXER_ASYNC_CLIENT.getSkillset("searchIndexerSkillset")
+ * .flatMap(indexerSkillset -> {
+ * indexerSkillset.setDescription("This is new description!");
+ * return SEARCH_INDEXER_ASYNC_CLIENT.createOrUpdateSkillsetWithResponse(
+ * new CreateOrUpdateSkillsetOptions(indexerSkillset)
+ * .setOnlyIfUnchanged(true)
+ * .setCacheReprocessingChangeDetectionDisabled(false)
+ * .setCacheResetRequirementsIgnored(true));
+ * })
+ * .subscribe(updateSkillsetResponse ->
+ * System.out.printf("The status code of the response is %s.%nThe indexer skillset name is %s. "
+ * + "The description of indexer skillset is %s.%n", updateSkillsetResponse.getStatusCode(),
+ * updateSkillsetResponse.getValue().getName(),
+ * updateSkillsetResponse.getValue().getDescription()));
+ *
+ *
+ *
+ * @param options The options used to create or update the {@link SearchIndexerSkillset skillset}.
+ * @return a response containing the skillset that was created or updated.
+ * @throws NullPointerException If {@code options} is null.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono>
+ createOrUpdateSkillsetWithResponse(CreateOrUpdateSkillsetOptions options) {
+ if (options == null) {
+ return monoError(LOGGER, new NullPointerException("'options' cannot be null."));
+ }
+
+ return withContext(context -> createOrUpdateSkillsetWithResponse(options.getSkillset(),
+ options.isOnlyIfUnchanged(), options.isCacheReprocessingChangeDetectionDisabled(),
+ options.isCacheResetRequirementsIgnored(), context));
+ }
+
Mono> createOrUpdateSkillsetWithResponse(SearchIndexerSkillset skillset,
boolean onlyIfUnchanged, Boolean disableCacheReprocessingChangeDetection, Boolean ignoreResetRequirements,
Context context) {
@@ -1711,4 +1940,66 @@ Mono> resyncWithResponseAsync(String indexerName, IndexerResyncBo
return monoError(LOGGER, ex);
}
}
+
+ /**
+ * Resets skills in an existing skillset in an Azure AI Search service.
+ *
+ *
+ *
+ * // Reset the "myOcr" and "myText" skills.
+ * SEARCH_INDEXER_ASYNC_CLIENT.resetSkills("searchIndexerSkillset", Arrays.asList("myOcr", "myText"))
+ * .subscribe();
+ *
+ *
+ *
+ * @param skillsetName The name of the skillset to reset.
+ * @param skillNames The skills to reset.
+ * @return A response signalling completion.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono resetSkills(String skillsetName, List skillNames) {
+ return withContext(
+ context -> resetSkillsWithResponse(skillsetName, skillNames, context).flatMap(FluxUtil::toMono));
+ }
+
+ /**
+ * Resets skills in an existing skillset in an Azure AI Search service.
+ *
+ *
+ *
+ * SEARCH_INDEXER_ASYNC_CLIENT.getSkillset("searchIndexerSkillset")
+ * .flatMap(searchIndexerSkillset -> SEARCH_INDEXER_ASYNC_CLIENT.resetSkillsWithResponse(searchIndexerSkillset,
+ * Arrays.asList("myOcr", "myText")))
+ * .subscribe(resetSkillsResponse -> System.out.printf("Resetting skills completed with status code %d.%n",
+ * resetSkillsResponse.getStatusCode()));
+ *
+ *
+ *
+ * @param skillset The skillset to reset.
+ * @param skillNames The skills to reset.
+ * @return A response signalling completion.
+ * @throws NullPointerException If {@code skillset} is null.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono> resetSkillsWithResponse(SearchIndexerSkillset skillset, List skillNames) {
+ if (skillset == null) {
+ return monoError(LOGGER, new NullPointerException("'skillset' cannot be null."));
+ }
+
+ return withContext(context -> resetSkillsWithResponse(skillset.getName(), skillNames, context));
+ }
+
+ Mono> resetSkillsWithResponse(String skillsetName, List skillNames, Context context) {
+ try {
+ return restClient.getSkillsets()
+ .resetSkillsWithResponseAsync(skillsetName, new SkillNames().setSkillNames(skillNames), null, context);
+ } catch (RuntimeException ex) {
+ return monoError(LOGGER, ex);
+
+ }
+ }
}
diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerClient.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerClient.java
index d09d25b3f7a2..6902704d7cfd 100644
--- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerClient.java
+++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/SearchIndexerClient.java
@@ -15,16 +15,24 @@
import com.azure.search.documents.implementation.util.MappingUtils;
import com.azure.search.documents.implementation.util.Utility;
import com.azure.search.documents.indexes.implementation.SearchServiceClientImpl;
+import com.azure.search.documents.indexes.implementation.models.DocumentKeysOrIds;
import com.azure.search.documents.indexes.implementation.models.ErrorResponseException;
import com.azure.search.documents.indexes.implementation.models.ListDataSourcesResult;
import com.azure.search.documents.indexes.implementation.models.ListIndexersResult;
import com.azure.search.documents.indexes.implementation.models.ListSkillsetsResult;
+import com.azure.search.documents.indexes.implementation.models.SkillNames;
+import com.azure.search.documents.indexes.models.CreateOrUpdateDataSourceConnectionOptions;
+import com.azure.search.documents.indexes.models.CreateOrUpdateIndexerOptions;
+import com.azure.search.documents.indexes.models.CreateOrUpdateSkillsetOptions;
import com.azure.search.documents.indexes.models.IndexerResyncBody;
import com.azure.search.documents.indexes.models.SearchIndexer;
import com.azure.search.documents.indexes.models.SearchIndexerDataSourceConnection;
import com.azure.search.documents.indexes.models.SearchIndexerSkillset;
import com.azure.search.documents.indexes.models.SearchIndexerStatus;
+import java.util.List;
+import java.util.Objects;
+
/**
* This class provides a client that contains the operations for creating, getting, listing, updating, or deleting data
* source connections, indexers, or skillsets and running or resetting indexers in an Azure AI Search service.
@@ -465,6 +473,44 @@ public Response createOrUpdateDataSourceConne
return createOrUpdateDataSourceConnectionWithResponse(dataSourceConnection, onlyIfUnchanged, null, context);
}
+ /**
+ * Creates a new Azure AI Search data source or updates a data source if it already exists.
+ *
+ * Code Sample
+ *
+ * Create or update search indexer data source connection named "dataSource".
+ *
+ *
+ *
+ * SearchIndexerDataSourceConnection dataSource = SEARCH_INDEXER_CLIENT.getDataSourceConnection("dataSource");
+ * dataSource.setContainer(new SearchIndexerDataContainer("updatecontainer"));
+ * CreateOrUpdateDataSourceConnectionOptions options = new CreateOrUpdateDataSourceConnectionOptions(dataSource)
+ * .setOnlyIfUnchanged(true)
+ * .setCacheResetRequirementsIgnored(true);
+ *
+ * Response<SearchIndexerDataSourceConnection> updateDataSource = SEARCH_INDEXER_CLIENT
+ * .createOrUpdateDataSourceConnectionWithResponse(options, new Context(KEY_1, VALUE_1));
+ * System.out.printf("The status code of the response is %s.%nThe dataSource name is %s. "
+ * + "The container name of dataSource is %s.%n", updateDataSource.getStatusCode(),
+ * updateDataSource.getValue().getName(), updateDataSource.getValue().getContainer().getName());
+ *
+ *
+ *
+ * @param options The options used to create or update the {@link SearchIndexerDataSourceConnection data source
+ * connection}.
+ * @param context additional context that is passed through the HTTP pipeline during the service call
+ * @return a data source response.
+ * @throws NullPointerException If {@code options} is null.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Response createOrUpdateDataSourceConnectionWithResponse(
+ CreateOrUpdateDataSourceConnectionOptions options, Context context) {
+ Objects.requireNonNull(options, "'options' cannot be null.");
+
+ return createOrUpdateDataSourceConnectionWithResponse(options.getDataSourceConnection(),
+ options.isOnlyIfUnchanged(), options.isCacheResetRequirementsIgnored(), context);
+ }
+
Response createOrUpdateDataSourceConnectionWithResponse(
SearchIndexerDataSourceConnection dataSource, boolean onlyIfUnchanged, Boolean ignoreResetRequirements,
Context context) {
@@ -645,7 +691,7 @@ public PagedIterable listDataSourceConnection
public PagedIterable listDataSourceConnections(Context context) {
try {
return new PagedIterable<>(
- () -> MappingUtils.mappingPagingDataSource(listDataSourceConnectionsWithResponse(null, context)));
+ () -> MappingUtils.mapPagedDataSources(listDataSourceConnectionsWithResponse(null, context)));
} catch (RuntimeException ex) {
throw LOGGER.logExceptionAsError(ex);
}
@@ -704,7 +750,7 @@ public PagedIterable listDataSourceConnectionNames() {
public PagedIterable listDataSourceConnectionNames(Context context) {
try {
return new PagedIterable<>(() -> MappingUtils
- .mappingPagingDataSourceNames(this.listDataSourceConnectionsWithResponse("name", context)));
+ .mapPagedDataSourceNames(this.listDataSourceConnectionsWithResponse("name", context)));
} catch (RuntimeException ex) {
throw LOGGER.logExceptionAsError(ex);
}
@@ -875,6 +921,44 @@ public Response createOrUpdateIndexerWithResponse(SearchIndexer i
return createOrUpdateIndexerWithResponse(indexer, onlyIfUnchanged, null, null, context);
}
+ /**
+ * Creates a new Azure AI Search indexer or updates an indexer if it already exists.
+ *
+ * Code Sample
+ *
+ * Create or update search indexer named "searchIndexer".
+ *
+ *
+ *
+ * SearchIndexer searchIndexerFromService = SEARCH_INDEXER_CLIENT.getIndexer("searchIndexer");
+ * searchIndexerFromService.setFieldMappings(Collections.singletonList(
+ * new FieldMapping("hotelName").setTargetFieldName("HotelName")));
+ * CreateOrUpdateIndexerOptions options = new CreateOrUpdateIndexerOptions(searchIndexerFromService)
+ * .setOnlyIfUnchanged(true)
+ * .setCacheReprocessingChangeDetectionDisabled(false)
+ * .setCacheResetRequirementsIgnored(true);
+ * Response<SearchIndexer> indexerFromService = SEARCH_INDEXER_CLIENT.createOrUpdateIndexerWithResponse(
+ * options, new Context(KEY_1, VALUE_1));
+ * System.out.printf("The status code of the response is %s.%nThe indexer name is %s. "
+ * + "The target field name of indexer is %s.%n", indexerFromService.getStatusCode(),
+ * indexerFromService.getValue().getName(),
+ * indexerFromService.getValue().getFieldMappings().get(0).getTargetFieldName());
+ *
+ *
+ *
+ * @param options The options used to create or update the {@link SearchIndexer indexer}.
+ * @param context additional context that is passed through the HTTP pipeline during the service call
+ * @return A response object containing the Indexer.
+ * @throws NullPointerException If {@code options} is null.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Response createOrUpdateIndexerWithResponse(CreateOrUpdateIndexerOptions options,
+ Context context) {
+ Objects.requireNonNull(options, "'options' cannot be null.");
+ return createOrUpdateIndexerWithResponse(options.getIndexer(), options.isOnlyIfUnchanged(),
+ options.isCacheReprocessingChangeDetectionDisabled(), options.isCacheResetRequirementsIgnored(), context);
+ }
+
Response createOrUpdateIndexerWithResponse(SearchIndexer indexer, boolean onlyIfUnchanged,
Boolean disableCacheReprocessingChangeDetection, Boolean ignoreResetRequirements, Context context) {
if (indexer == null) {
@@ -938,7 +1022,7 @@ public PagedIterable listIndexers() {
public PagedIterable listIndexers(Context context) {
try {
return new PagedIterable<>(
- () -> MappingUtils.mappingPagingSearchIndexer(listIndexersWithResponse(null, context)));
+ () -> MappingUtils.mapPagedSearchIndexers(listIndexersWithResponse(null, context)));
} catch (RuntimeException ex) {
throw LOGGER.logExceptionAsError(ex);
}
@@ -997,7 +1081,7 @@ public PagedIterable listIndexerNames() {
public PagedIterable listIndexerNames(Context context) {
try {
return new PagedIterable<>(
- () -> MappingUtils.mappingPagingSearchIndexerNames(this.listIndexersWithResponse("name", context)));
+ () -> MappingUtils.mapPagedSearchIndexerNames(this.listIndexersWithResponse("name", context)));
} catch (RuntimeException ex) {
throw LOGGER.logExceptionAsError(ex);
}
@@ -1430,8 +1514,7 @@ public PagedIterable listSkillsets() {
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable listSkillsets(Context context) {
try {
- return new PagedIterable<>(
- () -> MappingUtils.mappingPagingSkillset(listSkillsetsWithResponse(null, context)));
+ return new PagedIterable<>(() -> MappingUtils.mapPagedSkillsets(listSkillsetsWithResponse(null, context)));
} catch (RuntimeException ex) {
throw LOGGER.logExceptionAsError(ex);
}
@@ -1490,7 +1573,7 @@ public PagedIterable listSkillsetNames() {
public PagedIterable listSkillsetNames(Context context) {
try {
return new PagedIterable<>(
- () -> MappingUtils.mappingPagingSkillsetNames(listSkillsetsWithResponse("name", context)));
+ () -> MappingUtils.mapPagedSkillsetNames(listSkillsetsWithResponse("name", context)));
} catch (RuntimeException ex) {
throw LOGGER.logExceptionAsError(ex);
}
@@ -1553,6 +1636,43 @@ public Response createOrUpdateSkillsetWithResponse(Search
return createOrUpdateSkillsetWithResponse(skillset, onlyIfUnchanged, null, null, context);
}
+ /**
+ * Creates a new Azure AI Search skillset or updates a skillset if it already exists.
+ *
+ * Code Sample
+ *
+ * Create or update search indexer skillset "searchIndexerSkillset".
+ *
+ *
+ *
+ * SearchIndexerSkillset indexerSkillset = SEARCH_INDEXER_CLIENT.getSkillset("searchIndexerSkillset");
+ * indexerSkillset.setDescription("This is new description!");
+ * CreateOrUpdateSkillsetOptions options = new CreateOrUpdateSkillsetOptions(indexerSkillset)
+ * .setOnlyIfUnchanged(true)
+ * .setCacheReprocessingChangeDetectionDisabled(false)
+ * .setCacheResetRequirementsIgnored(true);
+ * Response<SearchIndexerSkillset> updateSkillsetResponse = SEARCH_INDEXER_CLIENT.createOrUpdateSkillsetWithResponse(
+ * options, new Context(KEY_1, VALUE_1));
+ * System.out.printf("The status code of the response is %s.%nThe indexer skillset name is %s. "
+ * + "The description of indexer skillset is %s.%n", updateSkillsetResponse.getStatusCode(),
+ * updateSkillsetResponse.getValue().getName(),
+ * updateSkillsetResponse.getValue().getDescription());
+ *
+ *
+ *
+ * @param options The options used to create or update the {@link SearchIndexerSkillset skillset}.
+ * @param context additional context that is passed through the HTTP pipeline during the service call
+ * @return a response containing the skillset that was created or updated.
+ * @throws NullPointerException If {@code options} is null.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Response createOrUpdateSkillsetWithResponse(CreateOrUpdateSkillsetOptions options,
+ Context context) {
+ Objects.requireNonNull(options, "'options' cannot be null.");
+ return createOrUpdateSkillsetWithResponse(options.getSkillset(), options.isOnlyIfUnchanged(),
+ options.isCacheReprocessingChangeDetectionDisabled(), options.isCacheResetRequirementsIgnored(), context);
+ }
+
Response createOrUpdateSkillsetWithResponse(SearchIndexerSkillset skillset,
boolean onlyIfUnchanged, Boolean disableCacheReprocessingChangeDetection, Boolean ignoreResetRequirements,
Context context) {
@@ -1647,4 +1767,116 @@ public Response resyncWithResponse(String indexerName, IndexerResyncBody i
() -> restClient.getIndexers().resyncWithResponse(indexerName, indexerResync, null, context), LOGGER);
}
+ /**
+ * Resets specific documents in the datasource to be selectively re-ingested by the indexer.
+ *
+ *
+ *
+ * // Reset the documents with keys 1234 and 4321.
+ * SEARCH_INDEXER_CLIENT.resetDocuments("searchIndexer", false, Arrays.asList("1234", "4321"), null);
+ *
+ * // Clear the previous documents to be reset and replace them with documents 1235 and 5231.
+ * SEARCH_INDEXER_CLIENT.resetDocuments("searchIndexer", true, Arrays.asList("1235", "5321"), null);
+ *
+ *
+ *
+ * @param indexerName The name of the indexer to reset documents for.
+ * @param overwrite If false, keys or IDs will be appended to existing ones. If true, only the keys or IDs in this
+ * payload will be queued to be re-ingested.
+ * @param documentKeys Document keys to be reset.
+ * @param datasourceDocumentIds Datasource document identifiers to be reset.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public void resetDocuments(String indexerName, Boolean overwrite, List documentKeys,
+ List datasourceDocumentIds) {
+ resetDocumentsWithResponse(new SearchIndexer(indexerName), overwrite, documentKeys, datasourceDocumentIds,
+ Context.NONE);
+ }
+
+ /**
+ * Resets specific documents in the datasource to be selectively re-ingested by the indexer.
+ *
+ *
+ *
+ * SearchIndexer searchIndexer = SEARCH_INDEXER_CLIENT.getIndexer("searchIndexer");
+ *
+ * // Reset the documents with keys 1234 and 4321.
+ * Response<Void> resetDocsResult = SEARCH_INDEXER_CLIENT.resetDocumentsWithResponse(searchIndexer, false,
+ * Arrays.asList("1234", "4321"), null, new Context(KEY_1, VALUE_1));
+ * System.out.printf("Requesting documents to be reset completed with status code %d.%n",
+ * resetDocsResult.getStatusCode());
+ *
+ * // Clear the previous documents to be reset and replace them with documents 1235 and 5231.
+ * resetDocsResult = SEARCH_INDEXER_CLIENT.resetDocumentsWithResponse(searchIndexer, true,
+ * Arrays.asList("1235", "5321"), null, new Context(KEY_1, VALUE_1));
+ * System.out.printf("Overwriting the documents to be reset completed with status code %d.%n",
+ * resetDocsResult.getStatusCode());
+ *
+ *
+ *
+ * @param indexer The indexer to reset documents for.
+ * @param overwrite If false, keys or IDs will be appended to existing ones. If true, only the keys or IDs in this
+ * payload will be queued to be re-ingested.
+ * @param documentKeys Document keys to be reset.
+ * @param datasourceDocumentIds Datasource document identifiers to be reset.
+ * @param context additional context that is passed through the HTTP pipeline during the service call
+ * @return A response signalling completion.
+ * @throws NullPointerException If {@code indexer} is null.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Response resetDocumentsWithResponse(SearchIndexer indexer, Boolean overwrite,
+ List documentKeys, List datasourceDocumentIds, Context context) {
+ DocumentKeysOrIds documentKeysOrIds
+ = new DocumentKeysOrIds().setDocumentKeys(documentKeys).setDatasourceDocumentIds(datasourceDocumentIds);
+
+ return Utility.executeRestCallWithExceptionHandling(() -> restClient.getIndexers()
+ .resetDocsWithResponse(indexer.getName(), overwrite, documentKeysOrIds, null, context), LOGGER);
+ }
+
+ /**
+ * Resets skills in an existing skillset in an Azure AI Search service.
+ *
+ *
+ *