SearchIndexerClient.java
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.search.documents.indexes;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
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.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 Cognitive Search service.
*
* @see SearchIndexerClientBuilder
*/
@ServiceClient(builder = SearchIndexerClientBuilder.class)
public class SearchIndexerClient {
private final SearchIndexerAsyncClient asyncClient;
SearchIndexerClient(SearchIndexerAsyncClient searchIndexerAsyncClient) {
this.asyncClient = searchIndexerAsyncClient;
}
/**
* Gets the {@link HttpPipeline} powering this client.
*
* @return the pipeline.
*/
HttpPipeline getHttpPipeline() {
return this.asyncClient.getHttpPipeline();
}
/**
* Gets the endpoint for the Azure Cognitive Search service.
*
* @return the endpoint value.
*/
public String getEndpoint() {
return this.asyncClient.getEndpoint();
}
/**
* Creates a new Azure Cognitive Search data source or updates a data source if it already exists
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create or update search indexer data source connection named "dataSource". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateDataSourceConnection#SearchIndexerDataSourceConnection -->
* <pre>
* SearchIndexerDataSourceConnection dataSource = searchIndexerClient.getDataSourceConnection("dataSource");
* dataSource.setContainer(new SearchIndexerDataContainer("updatecontainer"));
*
* SearchIndexerDataSourceConnection updateDataSource = searchIndexerClient.createOrUpdateDataSourceConnection(dataSource);
* System.out.printf("The dataSource name is %s. The container name of dataSource is %s.%n",
* updateDataSource.getName(), updateDataSource.getContainer().getName());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateDataSourceConnection#SearchIndexerDataSourceConnection -->
*
* @param dataSourceConnection The definition of the data source to create or update.
* @return the data source that was created or updated.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SearchIndexerDataSourceConnection createOrUpdateDataSourceConnection(
SearchIndexerDataSourceConnection dataSourceConnection) {
return createOrUpdateDataSourceConnectionWithResponse(dataSourceConnection, false, Context.NONE).getValue();
}
/**
* Creates a new Azure Cognitive Search data source or updates a data source if it already exists.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create or update search indexer data source connection named "dataSource". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateDataSourceConnectionWithResponse#SearchIndexerDataSourceConnection-boolean-Context -->
* <pre>
* SearchIndexerDataSourceConnection dataSource = searchIndexerClient.getDataSourceConnection("dataSource");
* dataSource.setContainer(new SearchIndexerDataContainer("updatecontainer"));
*
* Response<SearchIndexerDataSourceConnection> updateDataSource = searchIndexerClient
* .createOrUpdateDataSourceConnectionWithResponse(dataSource, true, new Context(key1, value1));
* 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());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateDataSourceConnectionWithResponse#SearchIndexerDataSourceConnection-boolean-Context -->
*
* @param dataSourceConnection the {@link SearchIndexerDataSourceConnection} to create or update
* @param onlyIfUnchanged {@code true} to update if the {@code dataSourceConnection} is the same as the current
* service value. {@code false} to always update existing value.
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response containing data source that was created or updated.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<SearchIndexerDataSourceConnection> createOrUpdateDataSourceConnectionWithResponse(
SearchIndexerDataSourceConnection dataSourceConnection, boolean onlyIfUnchanged, Context context) {
return asyncClient.createOrUpdateDataSourceConnectionWithResponse(dataSourceConnection, onlyIfUnchanged, null,
context).block();
}
/**
* Creates a new Azure Cognitive Search data source or updates a data source if it already exists.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create or update search indexer data source connection named "dataSource". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateDataSourceConnectionWithResponse#CreateOrUpdateDataSourceConnectionOptions-Context -->
* <pre>
* SearchIndexerDataSourceConnection dataSource = searchIndexerClient.getDataSourceConnection("dataSource");
* dataSource.setContainer(new SearchIndexerDataContainer("updatecontainer"));
* CreateOrUpdateDataSourceConnectionOptions options = new CreateOrUpdateDataSourceConnectionOptions(dataSource)
* .setOnlyIfUnchanged(true)
* .setCacheResetRequirementsIgnored(true);
*
* Response<SearchIndexerDataSourceConnection> updateDataSource = searchIndexerClient
* .createOrUpdateDataSourceConnectionWithResponse(options, new Context(key1, value1));
* 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());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateDataSourceConnectionWithResponse#CreateOrUpdateDataSourceConnectionOptions-Context -->
*
* @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<SearchIndexerDataSourceConnection> createOrUpdateDataSourceConnectionWithResponse(
CreateOrUpdateDataSourceConnectionOptions options, Context context) {
Objects.requireNonNull(options, "'options' cannot be null.");
return asyncClient.createOrUpdateDataSourceConnectionWithResponse(options.getDataSourceConnection(),
options.isOnlyIfUnchanged(), options.isCacheResetRequirementsIgnored(), context)
.block();
}
/**
* Creates a new Azure Cognitive Search data source
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create search indexer data source connection named "dataSource". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createDataSourceConnection#SearchIndexerDataSourceConnection -->
* <pre>
* SearchIndexerDataSourceConnection dataSource = new SearchIndexerDataSourceConnection("dataSource",
* com.azure.search.documents.indexes.models.SearchIndexerDataSourceType.AZURE_BLOB, "{connectionString}",
* new com.azure.search.documents.indexes.models.SearchIndexerDataContainer("container"));
* SearchIndexerDataSourceConnection dataSourceFromService =
* searchIndexerClient.createDataSourceConnection(dataSource);
* System.out.printf("The data source name is %s. The ETag of data source is %s.%n",
* dataSourceFromService.getName(), dataSourceFromService.getETag());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createDataSourceConnection#SearchIndexerDataSourceConnection -->
*
* @param dataSourceConnection The definition of the data source to create
* @return the data source that was created.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SearchIndexerDataSourceConnection createDataSourceConnection(
SearchIndexerDataSourceConnection dataSourceConnection) {
return createDataSourceConnectionWithResponse(dataSourceConnection, Context.NONE).getValue();
}
/**
* Creates a new Azure Cognitive Search data source
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create search indexer data source connection named "dataSource". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createDataSourceConnectionWithResponse#SearchIndexerDataSourceConnection-Context -->
* <pre>
* SearchIndexerDataSourceConnection dataSource = new SearchIndexerDataSourceConnection("dataSource",
* SearchIndexerDataSourceType.AZURE_BLOB, "{connectionString}",
* new SearchIndexerDataContainer("container"));
* Response<SearchIndexerDataSourceConnection> dataSourceFromService =
* searchIndexerClient.createDataSourceConnectionWithResponse(dataSource, new Context(key1, value1));
*
* System.out.printf("The status code of the response is %s. The data source name is %s.%n",
* dataSourceFromService.getStatusCode(), dataSourceFromService.getValue().getName());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createDataSourceConnectionWithResponse#SearchIndexerDataSourceConnection-Context -->
*
* @param dataSourceConnection the definition of the data source to create doesn't match specified values
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response containing data source that was created.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<SearchIndexerDataSourceConnection> createDataSourceConnectionWithResponse(
SearchIndexerDataSourceConnection dataSourceConnection, Context context) {
return asyncClient.createDataSourceConnectionWithResponse(dataSourceConnection, context)
.block();
}
/**
* Retrieves a DataSource from an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Get search indexer data source connection named "dataSource". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.getDataSourceConnection#String -->
* <pre>
* SearchIndexerDataSourceConnection dataSource =
* searchIndexerClient.getDataSourceConnection("dataSource");
* System.out.printf("The dataSource name is %s. The ETag of dataSource is %s.%n", dataSource.getName(),
* dataSource.getETag());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.getDataSourceConnection#String -->
*
* @param dataSourceConnectionName the name of the data source to retrieve
* @return the DataSource.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SearchIndexerDataSourceConnection getDataSourceConnection(String dataSourceConnectionName) {
return getDataSourceConnectionWithResponse(dataSourceConnectionName, Context.NONE).getValue();
}
/**
* Retrieves a DataSource from an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Get search indexer data source connection named "dataSource". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.getDataSourceConnectionWithResponse#String-Context -->
* <pre>
* Response<SearchIndexerDataSourceConnection> dataSource =
* searchIndexerClient.getDataSourceConnectionWithResponse(
* "dataSource", new Context(key1, value1));
*
* System.out.printf("The status code of the response is %s. The data source name is %s.%n",
* dataSource.getStatusCode(), dataSource.getValue().getName());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.getDataSourceConnectionWithResponse#String-Context -->
*
* @param dataSourceConnectionName the name of the data source to retrieve
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response containing the DataSource.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<SearchIndexerDataSourceConnection> getDataSourceConnectionWithResponse(
String dataSourceConnectionName, Context context) {
return asyncClient.getDataSourceConnectionWithResponse(dataSourceConnectionName, context)
.block();
}
/**
* List all DataSources from an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexer data source connections. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listDataSourceConnections -->
* <pre>
* PagedIterable<SearchIndexerDataSourceConnection> dataSources = searchIndexerClient.listDataSourceConnections();
* for (SearchIndexerDataSourceConnection dataSource: dataSources) {
* System.out.printf("The dataSource name is %s. The ETag of dataSource is %s.%n", dataSource.getName(),
* dataSource.getETag());
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listDataSourceConnections -->
*
* @return a list of DataSources
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<SearchIndexerDataSourceConnection> listDataSourceConnections() {
return listDataSourceConnections(Context.NONE);
}
/**
* List all DataSources from an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexer data source connections. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listDataSourceConnectionsWithResponse#Context -->
* <pre>
* PagedIterable<SearchIndexerDataSourceConnection> dataSources =
* searchIndexerClient.listDataSourceConnections(new Context(key1, value1));
*
* System.out.println("The status code of the response is"
* + dataSources.iterableByPage().iterator().next().getStatusCode());
* for (SearchIndexerDataSourceConnection dataSource: dataSources) {
* System.out.printf("The dataSource name is %s. The ETag of dataSource is %s.%n",
* dataSource.getName(), dataSource.getETag());
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listDataSourceConnectionsWithResponse#Context -->
*
* @param context Additional context that is passed through the HTTP pipeline during the service call.
* @return a response containing the list of DataSources.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<SearchIndexerDataSourceConnection> listDataSourceConnections(Context context) {
return new PagedIterable<>(asyncClient.listDataSourceConnections(context));
}
/**
* List all DataSource names from an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexer data source connection names. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listDataSourceConnectionNames -->
* <pre>
* PagedIterable<String> dataSources = searchIndexerClient.listDataSourceConnectionNames();
* for (String dataSourceName: dataSources) {
* System.out.printf("The dataSource name is %s.%n", dataSourceName);
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listDataSourceConnectionNames -->
*
* @return a list of DataSources names
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<String> listDataSourceConnectionNames() {
return listDataSourceConnectionNames(Context.NONE);
}
/**
* List all DataSources names from an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexer data source connection names. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listDataSourceConnectionNamesWithContext#Context -->
* <pre>
* PagedIterable<String> dataSources = searchIndexerClient.listDataSourceConnectionNames(new Context(key1, value1));
* System.out.println("The status code of the response is"
* + dataSources.iterableByPage().iterator().next().getStatusCode());
* for (String dataSourceName: dataSources) {
* System.out.printf("The dataSource name is %s.%n", dataSourceName);
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listDataSourceConnectionNamesWithContext#Context -->
*
* @param context Additional context that is passed through the HTTP pipeline during the service call.
* @return a response containing the list of DataSource names.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<String> listDataSourceConnectionNames(Context context) {
return new PagedIterable<>(asyncClient.listDataSourceConnectionNames(context));
}
/**
* Delete a DataSource
*
* <p><strong>Code Sample</strong></p>
*
* <p> Delete all search indexer data source connection named "dataSource". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.deleteDataSourceConnection#String -->
* <pre>
* searchIndexerClient.deleteDataSourceConnection("dataSource");
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.deleteDataSourceConnection#String -->
*
* @param dataSourceConnectionName the name of the data source to be deleted
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void deleteDataSourceConnection(String dataSourceConnectionName) {
deleteDataSourceConnectionWithResponse(new SearchIndexerDataSourceConnection(dataSourceConnectionName), false,
Context.NONE);
}
/**
* Delete a DataSource with Response
*
* <p><strong>Code Sample</strong></p>
*
* <p> Delete all search indexer data source connection named "dataSource". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.deleteDataSourceConnectionWithResponse#SearchIndexerDataSourceConnection-boolean-Context -->
* <pre>
* SearchIndexerDataSourceConnection dataSource =
* searchIndexerClient.getDataSourceConnection("dataSource");
* Response<Void> deleteResponse = searchIndexerClient.deleteDataSourceConnectionWithResponse(dataSource, true,
* new Context(key1, value1));
* System.out.printf("The status code of the response is %d.%n", deleteResponse.getStatusCode());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.deleteDataSourceConnectionWithResponse#SearchIndexerDataSourceConnection-boolean-Context -->
*
* @param dataSourceConnection the {@link SearchIndexerDataSourceConnection} to be deleted.
* @param onlyIfUnchanged {@code true} to delete if the {@code dataSourceConnection} is the same as the current
* service value. {@code false} to always delete existing value.
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return an empty response
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> deleteDataSourceConnectionWithResponse(SearchIndexerDataSourceConnection dataSourceConnection,
boolean onlyIfUnchanged, Context context) {
String eTag = onlyIfUnchanged ? dataSourceConnection.getETag() : null;
return asyncClient.deleteDataSourceConnectionWithResponse(dataSourceConnection.getName(), eTag, context)
.block();
}
/**
* Creates a new Azure Cognitive Search indexer.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create search indexer named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createIndexer#SearchIndexer -->
* <pre>
* SearchIndexer searchIndexer = new SearchIndexer("searchIndexer", "dataSource",
* "searchIndex");
* SearchIndexer indexerFromService = searchIndexerClient.createIndexer(searchIndexer);
* System.out.printf("The indexer name is %s. The ETag of indexer is %s.%n", indexerFromService.getName(),
* indexerFromService.getETag());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createIndexer#SearchIndexer -->
*
* @param indexer definition of the indexer to create.
* @return the created Indexer.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SearchIndexer createIndexer(SearchIndexer indexer) {
return createIndexerWithResponse(indexer, Context.NONE).getValue();
}
/**
* Creates a new Azure Cognitive Search indexer.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create search indexer named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createIndexerWithResponse#SearchIndexer-Context -->
* <pre>
* SearchIndexer searchIndexer = new SearchIndexer("searchIndexer", "dataSource",
* "searchIndex");
* Response<SearchIndexer> indexerFromServiceResponse = searchIndexerClient.createIndexerWithResponse(
* searchIndexer, new Context(key1, value1));
*
* System.out.printf("The status code of the response is %s. The indexer name is %s.%n",
* indexerFromServiceResponse.getStatusCode(), indexerFromServiceResponse.getValue().getName());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createIndexerWithResponse#SearchIndexer-Context -->
*
* @param indexer definition of the indexer to create
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response containing the created Indexer.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<SearchIndexer> createIndexerWithResponse(SearchIndexer indexer, Context context) {
return asyncClient.createIndexerWithResponse(indexer, context).block();
}
/**
* Creates a new Azure Cognitive Search indexer or updates an indexer if it already exists.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create or update search indexer named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateIndexer#SearchIndexer -->
* <pre>
* SearchIndexer searchIndexerFromService = searchIndexerClient.getIndexer("searchIndexer");
* searchIndexerFromService.setFieldMappings(Collections.singletonList(
* new FieldMapping("hotelName").setTargetFieldName("HotelName")));
* SearchIndexer updateIndexer = searchIndexerClient.createOrUpdateIndexer(searchIndexerFromService);
* System.out.printf("The indexer name is %s. The target field name of indexer is %s.%n",
* updateIndexer.getName(), updateIndexer.getFieldMappings().get(0).getTargetFieldName());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateIndexer#SearchIndexer -->
*
* @param indexer The definition of the indexer to create or update.
* @return a response containing the created Indexer.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SearchIndexer createOrUpdateIndexer(SearchIndexer indexer) {
return createOrUpdateIndexerWithResponse(indexer, false, Context.NONE).getValue();
}
/**
* Creates a new Azure Cognitive Search indexer or updates an indexer if it already exists.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create or update search indexer named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateIndexerWithResponse#SearchIndexer-boolean-Context -->
* <pre>
* SearchIndexer searchIndexerFromService = searchIndexerClient.getIndexer("searchIndexer");
* searchIndexerFromService.setFieldMappings(Collections.singletonList(
* new FieldMapping("hotelName").setTargetFieldName("HotelName")));
* Response<SearchIndexer> indexerFromService = searchIndexerClient.createOrUpdateIndexerWithResponse(
* searchIndexerFromService, true, new Context(key1, value1));
* 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());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateIndexerWithResponse#SearchIndexer-boolean-Context -->
*
* @param indexer The {@link SearchIndexer} to create or update.
* @param onlyIfUnchanged {@code true} to update if the {@code indexer} is the same as the current service value.
* {@code false} to always update existing value.
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return A response object containing the Indexer.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<SearchIndexer> createOrUpdateIndexerWithResponse(SearchIndexer indexer, boolean onlyIfUnchanged,
Context context) {
return asyncClient.createOrUpdateIndexerWithResponse(indexer, onlyIfUnchanged, null, null, context).block();
}
/**
* Creates a new Azure Cognitive Search indexer or updates an indexer if it already exists.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create or update search indexer named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateIndexerWithResponse#CreateOrUpdateIndexerOptions-Context -->
* <pre>
* SearchIndexer searchIndexerFromService = searchIndexerClient.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 = searchIndexerClient.createOrUpdateIndexerWithResponse(
* options, new Context(key1, value1));
* 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());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateIndexerWithResponse#CreateOrUpdateIndexerOptions-Context -->
*
* @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<SearchIndexer> createOrUpdateIndexerWithResponse(CreateOrUpdateIndexerOptions options,
Context context) {
Objects.requireNonNull(options, "'options' cannot be null.");
return asyncClient.createOrUpdateIndexerWithResponse(options.getIndexer(), options.isOnlyIfUnchanged(),
options.isCacheReprocessingChangeDetectionDisabled(), options.isCacheResetRequirementsIgnored(), context)
.block();
}
/**
* Lists all indexers available for an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexers. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listIndexers -->
* <pre>
* PagedIterable<SearchIndexer> indexers = searchIndexerClient.listIndexers();
* for (SearchIndexer indexer: indexers) {
* System.out.printf("The indexer name is %s. The ETag of indexer is %s.%n", indexer.getName(),
* indexer.getETag());
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listIndexers -->
*
* @return all Indexers from the Search service.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<SearchIndexer> listIndexers() {
return listIndexers(Context.NONE);
}
/**
* Lists all indexers available for an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexers. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listIndexersWithResponse#Context -->
* <pre>
* PagedIterable<SearchIndexer> indexers = searchIndexerClient.listIndexers(new Context(key1, value1));
* System.out.println("The status code of the response is"
* + indexers.iterableByPage().iterator().next().getStatusCode());
* for (SearchIndexer indexer: indexers) {
* System.out.printf("The indexer name is %s. The ETag of index is %s.%n",
* indexer.getName(), indexer.getETag());
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listIndexersWithResponse#Context -->
*
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return all Indexers from the Search service.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<SearchIndexer> listIndexers(Context context) {
return new PagedIterable<>(asyncClient.listIndexers(context));
}
/**
* Lists all indexers names for an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexer names. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listIndexerNames -->
* <pre>
* PagedIterable<String> indexers = searchIndexerClient.listIndexerNames();
* for (String indexerName: indexers) {
* System.out.printf("The indexer name is %s.%n", indexerName);
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listIndexerNames -->
*
* @return all Indexer names from the Search service .
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<String> listIndexerNames() {
return listIndexerNames(Context.NONE);
}
/**
* Lists all indexers names for an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexer names. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listIndexerNames#Context -->
* <pre>
* PagedIterable<String> indexers = searchIndexerClient.listIndexerNames(new Context(key1, value1));
* System.out.println("The status code of the response is"
* + indexers.iterableByPage().iterator().next().getStatusCode());
* for (String indexerName: indexers) {
* System.out.printf("The indexer name is %s.%n", indexerName);
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listIndexerNames#Context -->
*
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return all Indexer names from the Search service.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<String> listIndexerNames(Context context) {
return new PagedIterable<>(asyncClient.listIndexerNames(context));
}
/**
* Retrieves an indexer definition.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Get search indexer with name "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.getIndexer#String -->
* <pre>
* SearchIndexer indexerFromService =
* searchIndexerClient.getIndexer("searchIndexer");
* System.out.printf("The indexer name is %s. The ETag of indexer is %s.%n", indexerFromService.getName(),
* indexerFromService.getETag());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.getIndexer#String -->
*
* @param indexerName the name of the indexer to retrieve
* @return the indexer.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SearchIndexer getIndexer(String indexerName) {
return getIndexerWithResponse(indexerName, Context.NONE).getValue();
}
/**
* Retrieves an indexer definition.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Get search indexer with name "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.getIndexerWithResponse#String-Context -->
* <pre>
* Response<SearchIndexer> indexerFromServiceResponse = searchIndexerClient.getIndexerWithResponse(
* "searchIndexer", new Context(key1, value1));
*
* System.out.printf("The status code of the response is %s. The indexer name is %s.%n",
* indexerFromServiceResponse.getStatusCode(), indexerFromServiceResponse.getValue().getName());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.getIndexerWithResponse#String-Context -->
*
* @param indexerName the name of the indexer to retrieve
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response containing the indexer.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<SearchIndexer> getIndexerWithResponse(String indexerName, Context context) {
return asyncClient.getIndexerWithResponse(indexerName, context).block();
}
/**
* Deletes an Azure Cognitive Search indexer.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Delete search indexer named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.deleteIndexer#String -->
* <pre>
* searchIndexerClient.deleteIndexer("searchIndexer");
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.deleteIndexer#String -->
*
* @param indexerName the name of the indexer to delete
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void deleteIndexer(String indexerName) {
deleteIndexerWithResponse(new SearchIndexer(indexerName), false, Context.NONE);
}
/**
* Deletes an Azure Cognitive Search indexer.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Delete search index named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.deleteIndexerWithResponse#SearchIndexer-boolean-Context -->
* <pre>
* SearchIndexer searchIndexer = searchIndexerClient.getIndexer("searchIndexer");
* Response<Void> deleteResponse = searchIndexerClient.deleteIndexerWithResponse(searchIndexer, true,
* new Context(key1, value1));
* System.out.printf("The status code of the response is %d.%n", deleteResponse.getStatusCode());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.deleteIndexerWithResponse#SearchIndexer-boolean-Context -->
*
* @param indexer the search {@link SearchIndexer}
* @param onlyIfUnchanged {@code true} to delete if the {@code indexer} is the same as the current service value.
* {@code false} to always delete existing value.
* @param context the context
* @return a response signalling completion.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> deleteIndexerWithResponse(SearchIndexer indexer, boolean onlyIfUnchanged, Context context) {
String eTag = onlyIfUnchanged ? indexer.getETag() : null;
return asyncClient.deleteIndexerWithResponse(indexer.getName(), eTag, context).block();
}
/**
* Resets the change tracking state associated with an indexer.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Reset search indexer named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.resetIndexer#String -->
* <pre>
* searchIndexerClient.resetIndexer("searchIndexer");
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.resetIndexer#String -->
*
* @param indexerName the name of the indexer to reset
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void resetIndexer(String indexerName) {
resetIndexerWithResponse(indexerName, Context.NONE);
}
/**
* Resets the change tracking state associated with an indexer.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Reset search indexer named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.resetIndexerWithResponse#String-Context -->
* <pre>
* Response<Void> response = searchIndexerClient.resetIndexerWithResponse("searchIndexer",
* new Context(key1, value1));
* System.out.println("The status code of the response is " + response.getStatusCode());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.resetIndexerWithResponse#String-Context -->
*
* @param indexerName the name of the indexer to reset
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response signalling completion.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> resetIndexerWithResponse(String indexerName, Context context) {
return asyncClient.resetIndexerWithResponse(indexerName, context).block();
}
/**
* Runs an indexer on-demand.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Run search indexer named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.runIndexer#String -->
* <pre>
* searchIndexerClient.runIndexer("searchIndexer");
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.runIndexer#String -->
*
* @param indexerName the name of the indexer to run
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void runIndexer(String indexerName) {
runIndexerWithResponse(indexerName, Context.NONE);
}
/**
* Runs an indexer on-demand.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Run search indexer named "searchIndexer". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.runIndexerWithResponse#String-Context -->
* <pre>
* Response<Void> response = searchIndexerClient.runIndexerWithResponse("searchIndexer",
* new Context(key1, value1));
* System.out.println("The status code of the response is " + response.getStatusCode());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.runIndexerWithResponse#String-Context -->
*
* @param indexerName the name of the indexer to run
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response signalling completion.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> runIndexerWithResponse(String indexerName, Context context) {
return asyncClient.runIndexerWithResponse(indexerName, context).block();
}
/**
* Returns the current status and execution history of an indexer.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Get search indexer status. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.getIndexerStatus#String -->
* <pre>
* SearchIndexerStatus indexerStatus = searchIndexerClient.getIndexerStatus("searchIndexer");
* System.out.printf("The indexer status is %s.%n", indexerStatus.getStatus());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.getIndexerStatus#String -->
*
* @param indexerName the name of the indexer for which to retrieve status
* @return a response with the indexer execution info.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SearchIndexerStatus getIndexerStatus(String indexerName) {
return getIndexerStatusWithResponse(indexerName, Context.NONE).getValue();
}
/**
* Returns the current status and execution history of an indexer.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Get search indexer status. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.getIndexerStatusWithResponse#String-Context -->
* <pre>
* Response<SearchIndexerStatus> response = searchIndexerClient.getIndexerStatusWithResponse("searchIndexer",
* new Context(key1, value1));
* System.out.printf("The status code of the response is %s.%nThe indexer status is %s.%n",
* response.getStatusCode(), response.getValue().getStatus());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.getIndexerStatusWithResponse#String-Context -->
*
* @param indexerName the name of the indexer for which to retrieve status
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response with the indexer execution info.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<SearchIndexerStatus> getIndexerStatusWithResponse(String indexerName, Context context) {
return asyncClient.getIndexerStatusWithResponse(indexerName, context).block();
}
/**
* Resets specific documents in the datasource to be selectively re-ingested by the indexer.
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.resetDocuments#String-Boolean-List-List -->
* <pre>
* // Reset the documents with keys 1234 and 4321.
* searchIndexerClient.resetDocuments("searchIndexer", false, Arrays.asList("1234", "4321"), null);
*
* // Clear the previous documents to be reset and replace them with documents 1235 and 5231.
* searchIndexerClient.resetDocuments("searchIndexer", true, Arrays.asList("1235", "5321"), null);
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.resetDocuments#String-Boolean-List-List -->
*
* @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<String> documentKeys,
List<String> datasourceDocumentIds) {
resetDocumentsWithResponse(new SearchIndexer(indexerName), overwrite, documentKeys, datasourceDocumentIds,
Context.NONE);
}
/**
* Resets specific documents in the datasource to be selectively re-ingested by the indexer.
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.resetDocumentsWithResponse#SearchIndexer-Boolean-List-List-Context -->
* <pre>
* SearchIndexer searchIndexer = searchIndexerClient.getIndexer("searchIndexer");
*
* // Reset the documents with keys 1234 and 4321.
* Response<Void> resetDocsResult = searchIndexerClient.resetDocumentsWithResponse(searchIndexer, false,
* Arrays.asList("1234", "4321"), null, new Context(key1, value1));
* 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 = searchIndexerClient.resetDocumentsWithResponse(searchIndexer, true,
* Arrays.asList("1235", "5321"), null, new Context(key1, value1));
* System.out.printf("Overwriting the documents to be reset completed with status code %d.%n",
* resetDocsResult.getStatusCode());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.resetDocumentsWithResponse#SearchIndexer-Boolean-List-List-Context -->
*
* @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<Void> resetDocumentsWithResponse(SearchIndexer indexer, Boolean overwrite,
List<String> documentKeys, List<String> datasourceDocumentIds, Context context) {
return asyncClient.resetDocumentsWithResponse(indexer.getName(), overwrite, documentKeys, datasourceDocumentIds,
context).block();
}
/**
* Creates a new skillset in an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create search indexer skillset "searchIndexerSkillset". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createSkillset#SearchIndexerSkillset -->
* <pre>
* List<InputFieldMappingEntry> inputs = Collections.singletonList(
* new InputFieldMappingEntry("image")
* .setSource("/document/normalized_images/*")
* );
*
* List<OutputFieldMappingEntry> outputs = Arrays.asList(
* new OutputFieldMappingEntry("text")
* .setTargetName("mytext"),
* new OutputFieldMappingEntry("layoutText")
* .setTargetName("myLayoutText")
* );
* SearchIndexerSkillset searchIndexerSkillset = new SearchIndexerSkillset("searchIndexerSkillset",
* Collections.singletonList(new OcrSkill(inputs, outputs)
* .setShouldDetectOrientation(true)
* .setDefaultLanguageCode(null)
* .setName("myocr")
* .setDescription("Extracts text (plain and structured) from image.")
* .setContext("/document/normalized_images/*")));
* SearchIndexerSkillset skillset = searchIndexerClient.createSkillset(searchIndexerSkillset);
* System.out.printf("The indexer skillset name is %s. The ETag of indexer skillset is %s.%n",
* skillset.getName(), skillset.getETag());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createSkillset#SearchIndexerSkillset -->
*
* @param skillset definition of the skillset containing one or more cognitive skills
* @return the created SearchIndexerSkillset.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SearchIndexerSkillset createSkillset(SearchIndexerSkillset skillset) {
return createSkillsetWithResponse(skillset, Context.NONE).getValue();
}
/**
* Creates a new skillset in an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create search indexer skillset "searchIndexerSkillset". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createSkillsetWithResponse#SearchIndexerSkillset-Context -->
* <pre>
* List<InputFieldMappingEntry> inputs = Collections.singletonList(
* new InputFieldMappingEntry("image")
* .setSource("/document/normalized_images/*")
* );
*
* List<OutputFieldMappingEntry> outputs = Arrays.asList(
* new OutputFieldMappingEntry("text")
* .setTargetName("mytext"),
* new OutputFieldMappingEntry("layoutText")
* .setTargetName("myLayoutText")
* );
* SearchIndexerSkillset searchIndexerSkillset = new SearchIndexerSkillset("searchIndexerSkillset",
* Collections.singletonList(new OcrSkill(inputs, outputs)
* .setShouldDetectOrientation(true)
* .setDefaultLanguageCode(null)
* .setName("myocr")
* .setDescription("Extracts text (plain and structured) from image.")
* .setContext("/document/normalized_images/*")));
* Response<SearchIndexerSkillset> skillsetWithResponse =
* searchIndexerClient.createSkillsetWithResponse(searchIndexerSkillset, new Context(key1, value1));
* System.out.printf("The status code of the response is %s. The indexer skillset name is %s.%n",
* skillsetWithResponse.getStatusCode(), skillsetWithResponse.getValue().getName());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createSkillsetWithResponse#SearchIndexerSkillset-Context -->
*
* @param skillset definition of the skillset containing one or more cognitive skills
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response containing the created SearchIndexerSkillset.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<SearchIndexerSkillset> createSkillsetWithResponse(SearchIndexerSkillset skillset, Context context) {
return asyncClient.createSkillsetWithResponse(skillset, context).block();
}
/**
* Retrieves a skillset definition.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Get search indexer skillset "searchIndexerSkillset". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.getSearchIndexerSkillset#String -->
* <pre>
* SearchIndexerSkillset indexerSkillset =
* searchIndexerClient.getSkillset("searchIndexerSkillset");
* System.out.printf("The indexer skillset name is %s. The ETag of indexer skillset is %s.%n",
* indexerSkillset.getName(), indexerSkillset.getETag());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.getSearchIndexerSkillset#String -->
*
* @param skillsetName the name of the skillset to retrieve
* @return the SearchIndexerSkillset.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SearchIndexerSkillset getSkillset(String skillsetName) {
return getSkillsetWithResponse(skillsetName, Context.NONE).getValue();
}
/**
* Retrieves a skillset definition.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Get search indexer skillset "searchIndexerSkillset". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.getSkillsetWithResponse#String-Context -->
* <pre>
* Response<SearchIndexerSkillset> skillsetWithResponse = searchIndexerClient.getSkillsetWithResponse(
* "searchIndexerSkillset", new Context(key1, value1));
*
* System.out.printf("The status code of the response is %s. The indexer skillset name is %s.%n",
* skillsetWithResponse.getStatusCode(), skillsetWithResponse.getValue().getName());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.getSkillsetWithResponse#String-Context -->
*
* @param skillsetName the name of the skillset to retrieve
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response containing the SearchIndexerSkillset.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<SearchIndexerSkillset> getSkillsetWithResponse(String skillsetName, Context context) {
return asyncClient.getSkillsetWithResponse(skillsetName, context).block();
}
/**
* Lists all skillsets available for an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexer skillsets. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listSkillsets -->
* <pre>
* PagedIterable<SearchIndexerSkillset> indexerSkillsets = searchIndexerClient.listSkillsets();
* for (SearchIndexerSkillset skillset: indexerSkillsets) {
* System.out.printf("The skillset name is %s. The ETag of skillset is %s.%n", skillset.getName(),
* skillset.getETag());
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listSkillsets -->
*
* @return the list of skillsets.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<SearchIndexerSkillset> listSkillsets() {
return listSkillsets(Context.NONE);
}
/**
* Lists all skillsets available for an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexer skillsets. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listSkillsetsWithContext#Context -->
* <pre>
* PagedIterable<SearchIndexerSkillset> indexerSkillsets = searchIndexerClient.listSkillsets(new Context(key1, value1));
* System.out.println("The status code of the response is"
* + indexerSkillsets.iterableByPage().iterator().next().getStatusCode());
* for (SearchIndexerSkillset skillset: indexerSkillsets) {
* System.out.printf("The skillset name is %s. The ETag of skillset is %s.%n",
* skillset.getName(), skillset.getETag());
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listSkillsetsWithContext#Context -->
*
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return the list of skillsets.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<SearchIndexerSkillset> listSkillsets(Context context) {
return new PagedIterable<>(asyncClient.listSkillsets(context));
}
/**
* Lists all skillset names for an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexer skillset names. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listSkillsetNames -->
* <pre>
* PagedIterable<String> skillsetNames = searchIndexerClient.listSkillsetNames();
* for (String skillsetName: skillsetNames) {
* System.out.printf("The indexer skillset name is %s.%n", skillsetName);
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listSkillsetNames -->
*
* @return the list of skillset names.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<String> listSkillsetNames() {
return listSkillsetNames(Context.NONE);
}
/**
* Lists all skillset names for an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> List all search indexer skillset names with response. </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.listSkillsetNamesWithResponse#Context -->
* <pre>
* PagedIterable<String> skillsetNames = searchIndexerClient.listSkillsetNames(new Context(key1, value1));
* System.out.println("The status code of the response is"
* + skillsetNames.iterableByPage().iterator().next().getStatusCode());
* for (String skillsetName: skillsetNames) {
* System.out.printf("The indexer skillset name is %s.%n", skillsetName);
* }
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.listSkillsetNamesWithResponse#Context -->
*
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return the list of skillset names.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<String> listSkillsetNames(Context context) {
return new PagedIterable<>(asyncClient.listSkillsetNames(context));
}
/**
* Creates a new Azure Cognitive Search skillset or updates a skillset if it already exists.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create or update search indexer skillset "searchIndexerSkillset". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateIndexerSkillset#SearchIndexerSkillset -->
* <pre>
* SearchIndexerSkillset indexerSkillset = searchIndexerClient.getSkillset("searchIndexerSkillset");
* indexerSkillset.setDescription("This is new description!");
* SearchIndexerSkillset updateSkillset = searchIndexerClient.createOrUpdateSkillset(indexerSkillset);
* System.out.printf("The indexer skillset name is %s. The description of indexer skillset is %s.%n",
* updateSkillset.getName(), updateSkillset.getDescription());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateIndexerSkillset#SearchIndexerSkillset -->
*
* @param skillset the {@link SearchIndexerSkillset} to create or update.
* @return the skillset that was created or updated.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SearchIndexerSkillset createOrUpdateSkillset(SearchIndexerSkillset skillset) {
return createOrUpdateSkillsetWithResponse(skillset, false, Context.NONE).getValue();
}
/**
* Creates a new Azure Cognitive Search skillset or updates a skillset if it already exists.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create or update search indexer skillset "searchIndexerSkillset". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateSkillsetWithResponse#SearchIndexerSkillset-boolean-Context -->
* <pre>
* SearchIndexerSkillset indexerSkillset = searchIndexerClient.getSkillset("searchIndexerSkillset");
* indexerSkillset.setDescription("This is new description!");
* Response<SearchIndexerSkillset> updateSkillsetResponse = searchIndexerClient.createOrUpdateSkillsetWithResponse(
* indexerSkillset, true, new Context(key1, value1));
* 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());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateSkillsetWithResponse#SearchIndexerSkillset-boolean-Context -->
*
* @param skillset the {@link SearchIndexerSkillset} to create or update.
* @param onlyIfUnchanged {@code true} to update if the {@code skillset} is the same as the current service value.
* {@code false} to always update existing value.
* @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.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<SearchIndexerSkillset> createOrUpdateSkillsetWithResponse(SearchIndexerSkillset skillset,
boolean onlyIfUnchanged, Context context) {
return asyncClient.createOrUpdateSkillsetWithResponse(skillset, onlyIfUnchanged, null, null, context)
.block();
}
/**
* Creates a new Azure Cognitive Search skillset or updates a skillset if it already exists.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Create or update search indexer skillset "searchIndexerSkillset". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateSkillsetWithResponse#CreateOrUpdateSkillsetOptions-Context -->
* <pre>
* SearchIndexerSkillset indexerSkillset = searchIndexerClient.getSkillset("searchIndexerSkillset");
* indexerSkillset.setDescription("This is new description!");
* CreateOrUpdateSkillsetOptions options = new CreateOrUpdateSkillsetOptions(indexerSkillset)
* .setOnlyIfUnchanged(true)
* .setCacheReprocessingChangeDetectionDisabled(false)
* .setCacheResetRequirementsIgnored(true);
* Response<SearchIndexerSkillset> updateSkillsetResponse = searchIndexerClient.createOrUpdateSkillsetWithResponse(
* options, new Context(key1, value1));
* 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());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.createOrUpdateSkillsetWithResponse#CreateOrUpdateSkillsetOptions-Context -->
*
* @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<SearchIndexerSkillset> createOrUpdateSkillsetWithResponse(CreateOrUpdateSkillsetOptions options,
Context context) {
Objects.requireNonNull(options, "'options' cannot be null.");
return asyncClient.createOrUpdateSkillsetWithResponse(options.getSkillset(), options.isOnlyIfUnchanged(),
options.isCacheReprocessingChangeDetectionDisabled(), options.isCacheResetRequirementsIgnored(), context)
.block();
}
/**
* Deletes a cognitive skillset in an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Delete search indexer skillset "searchIndexerSkillset". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.deleteSkillset#String -->
* <pre>
* searchIndexerClient.deleteSkillset("searchIndexerSkillset");
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.deleteSkillset#String -->
*
* @param skillsetName the name of the skillset to delete
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void deleteSkillset(String skillsetName) {
deleteSkillsetWithResponse(new SearchIndexerSkillset(skillsetName), false, Context.NONE);
}
/**
* Deletes a cognitive skillset in an Azure Cognitive Search service.
*
* <p><strong>Code Sample</strong></p>
*
* <p> Delete search indexer skillset "searchIndexerSkillset". </p>
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.deleteSkillsetWithResponse#SearchIndexerSkillset-boolean-Context -->
* <pre>
* SearchIndexerSkillset searchIndexerSkillset = searchIndexerClient.getSkillset("searchIndexerSkillset");
* Response<Void> deleteResponse = searchIndexerClient.deleteSkillsetWithResponse(searchIndexerSkillset, true,
* new Context(key1, value1));
* System.out.printf("The status code of the response is %d.%n", deleteResponse.getStatusCode());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.deleteSkillsetWithResponse#SearchIndexerSkillset-boolean-Context -->
*
* @param skillset the {@link SearchIndexerSkillset} to delete.
* @param onlyIfUnchanged {@code true} to delete if the {@code skillset} is the same as the current service value.
* {@code false} to always delete existing value.
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return a response signalling completion.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> deleteSkillsetWithResponse(SearchIndexerSkillset skillset, boolean onlyIfUnchanged,
Context context) {
String eTag = onlyIfUnchanged ? skillset.getETag() : null;
return asyncClient.deleteSkillsetWithResponse(skillset.getName(), eTag, context).block();
}
/**
* Resets skills in an existing skillset in an Azure Cognitive Search service.
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.resetSkills#String-List -->
* <pre>
* // Reset the "myOcr" and "myText" skills.
* searchIndexerClient.resetSkills("searchIndexerSkillset", Arrays.asList("myOcr", "myText"));
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.resetSkills#String-List -->
*
* @param skillsetName The name of the skillset to reset.
* @param skillNames The skills to reset.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void resetSkills(String skillsetName, List<String> skillNames) {
resetSkillsWithResponse(new SearchIndexerSkillset(skillsetName), skillNames, Context.NONE);
}
/**
* Resets skills in an existing skillset in an Azure Cognitive Search service.
*
* <!-- src_embed com.azure.search.documents.indexes.SearchIndexerClient.resetSkillsWithResponse#SearchIndexerSkillset-List-Context -->
* <pre>
* SearchIndexerSkillset searchIndexerSkillset = searchIndexerClient.getSkillset("searchIndexerSkillset");
*
* // Reset the "myOcr" and "myText" skills.
* Response<Void> resetSkillsResponse = searchIndexerClient.resetSkillsWithResponse(searchIndexerSkillset,
* Arrays.asList("myOcr", "myText"), new Context(key1, value1));
* System.out.printf("Resetting skills completed with status code %d.%n", resetSkillsResponse.getStatusCode());
* </pre>
* <!-- end com.azure.search.documents.indexes.SearchIndexerClient.resetSkillsWithResponse#SearchIndexerSkillset-List-Context -->
*
* @param skillset The skillset to reset.
* @param skillNames The skills to 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 skillset} is null.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> resetSkillsWithResponse(SearchIndexerSkillset skillset, List<String> skillNames,
Context context) {
return asyncClient.resetSkillsWithResponse(skillset.getName(), skillNames, context).block();
}
}