|
15 | 15 | import com.azure.search.documents.indexes.models.FieldBuilderOptions; |
16 | 16 | import com.azure.search.documents.indexes.models.LexicalAnalyzerName; |
17 | 17 | import com.azure.search.documents.indexes.models.LexicalTokenizerName; |
| 18 | +import com.azure.search.documents.indexes.models.SearchAlias; |
18 | 19 | import com.azure.search.documents.indexes.models.SearchField; |
19 | 20 | import com.azure.search.documents.indexes.models.SearchIndex; |
20 | 21 | import com.azure.search.documents.indexes.models.SearchIndexStatistics; |
@@ -405,7 +406,7 @@ public Response<SearchIndex> createOrUpdateIndexWithResponse(SearchIndex index, |
405 | 406 | */ |
406 | 407 | @ServiceMethod(returns = ReturnType.SINGLE) |
407 | 408 | public void deleteIndex(String indexName) { |
408 | | - deleteIndexWithResponse(new SearchIndex(indexName), false, Context.NONE); |
| 409 | + asyncClient.deleteIndexWithResponse(indexName, null, Context.NONE).block(); |
409 | 410 | } |
410 | 411 |
|
411 | 412 | /** |
@@ -771,7 +772,7 @@ public Response<SynonymMap> createOrUpdateSynonymMapWithResponse(SynonymMap syno |
771 | 772 | */ |
772 | 773 | @ServiceMethod(returns = ReturnType.SINGLE) |
773 | 774 | public void deleteSynonymMap(String synonymMapName) { |
774 | | - deleteSynonymMapWithResponse(new SynonymMap(synonymMapName), false, Context.NONE); |
| 775 | + asyncClient.deleteSynonymMapWithResponse(synonymMapName, null, Context.NONE).block(); |
775 | 776 | } |
776 | 777 |
|
777 | 778 | /** |
@@ -863,4 +864,255 @@ public static List<SearchField> buildSearchFields(Class<?> model, FieldBuilderOp |
863 | 864 | return SearchIndexAsyncClient.buildSearchFields(model, options); |
864 | 865 | } |
865 | 866 |
|
| 867 | + /** |
| 868 | + * Creates a new Azure Cognitive Search alias. |
| 869 | + * |
| 870 | + * <p><strong>Code Sample</strong></p> |
| 871 | + * |
| 872 | + * <p> Create the search alias named "my-alias". </p> |
| 873 | + * |
| 874 | + * <!-- src_embed com.azure.search.documents.indexes.SearchIndexClient.createAlias#SearchAlias --> |
| 875 | + * <pre> |
| 876 | + * SearchAlias searchAlias = searchIndexClient.createAlias(new SearchAlias("my-alias", |
| 877 | + * Collections.singletonList("index-to-alias"))); |
| 878 | + * System.out.printf("Created alias '%s' that aliases index '%s'.", searchAlias.getName(), |
| 879 | + * searchAlias.getIndexes().get(0)); |
| 880 | + * </pre> |
| 881 | + * <!-- end com.azure.search.documents.indexes.SearchClient.createAlias#SearchAlias --> |
| 882 | + * |
| 883 | + * @param alias definition of the alias to create. |
| 884 | + * @return the created alias. |
| 885 | + */ |
| 886 | + public SearchAlias createAlias(SearchAlias alias) { |
| 887 | + return createAliasWithResponse(alias, Context.NONE).getValue(); |
| 888 | + } |
| 889 | + |
| 890 | + /** |
| 891 | + * Creates a new Azure Cognitive Search alias. |
| 892 | + * |
| 893 | + * <p><strong>Code Sample</strong></p> |
| 894 | + * |
| 895 | + * <p> Create the search alias named "my-alias". </p> |
| 896 | + * |
| 897 | + * <!-- src_embed com.azure.search.documents.indexes.SearchIndexClient.createAliasWithResponse#SearchAlias-Context --> |
| 898 | + * <pre> |
| 899 | + * Response<SearchAlias> response = searchIndexClient.createAliasWithResponse(new SearchAlias("my-alias", |
| 900 | + * Collections.singletonList("index-to-alias")), new Context(key1, value1)); |
| 901 | + * |
| 902 | + * System.out.printf("Response status code %d. Created alias '%s' that aliases index '%s'.", |
| 903 | + * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0)); |
| 904 | + * </pre> |
| 905 | + * <!-- end com.azure.search.documents.indexes.SearchClient.createAliasWithResponse#SearchAlias-Context --> |
| 906 | + * |
| 907 | + * @param alias definition of the alias to create. |
| 908 | + * @param context additional context that is passed through the HTTP pipeline during the service call |
| 909 | + * @return the created alias. |
| 910 | + */ |
| 911 | + public Response<SearchAlias> createAliasWithResponse(SearchAlias alias, Context context) { |
| 912 | + return asyncClient.createAliasWithResponse(alias, context).block(); |
| 913 | + } |
| 914 | + |
| 915 | + /** |
| 916 | + * Creates or updates an Azure Cognitive Search alias. |
| 917 | + * |
| 918 | + * <p><strong>Code Sample</strong></p> |
| 919 | + * |
| 920 | + * <p> Create then update the search alias named "my-alias". </p> |
| 921 | + * |
| 922 | + * <!-- src_embed com.azure.search.documents.indexes.SearchIndexClient.createOrUpdateAlias#SearchAlias --> |
| 923 | + * <pre> |
| 924 | + * SearchAlias searchAlias = searchIndexClient.createOrUpdateAlias( |
| 925 | + * new SearchAlias("my-alias", Collections.singletonList("index-to-alias"))); |
| 926 | + * |
| 927 | + * System.out.printf("Created alias '%s' that aliases index '%s'.", searchAlias.getName(), |
| 928 | + * searchAlias.getIndexes().get(0)); |
| 929 | + * |
| 930 | + * searchAlias = searchIndexClient.createOrUpdateAlias(new SearchAlias(searchAlias.getName(), |
| 931 | + * Collections.singletonList("new-index-to-alias"))); |
| 932 | + * |
| 933 | + * System.out.printf("Updated alias '%s' to aliases index '%s'.", searchAlias.getName(), |
| 934 | + * searchAlias.getIndexes().get(0)); |
| 935 | + * </pre> |
| 936 | + * <!-- end com.azure.search.documents.indexes.SearchIndexClient.createOrUpdateAlias#SearchAlias --> |
| 937 | + * |
| 938 | + * @param alias definition of the alias to create or update. |
| 939 | + * @return the created or updated alias. |
| 940 | + */ |
| 941 | + public SearchAlias createOrUpdateAlias(SearchAlias alias) { |
| 942 | + return createOrUpdateAliasWithResponse(alias, false, Context.NONE).getValue(); |
| 943 | + } |
| 944 | + |
| 945 | + /** |
| 946 | + * Creates or updates an Azure Cognitive Search alias. |
| 947 | + * |
| 948 | + * <p><strong>Code Sample</strong></p> |
| 949 | + * |
| 950 | + * <p> Create then update the search alias named "my-alias". </p> |
| 951 | + * |
| 952 | + * <!-- src_embed com.azure.search.documents.indexes.SearchIndexClient.createOrUpdateAliasWithResponse#SearchAlias-boolean-Context --> |
| 953 | + * <pre> |
| 954 | + * Response<SearchAlias> response = searchIndexClient.createOrUpdateAliasWithResponse( |
| 955 | + * new SearchAlias("my-alias", Collections.singletonList("index-to-alias")), false, new Context(key1, value1)); |
| 956 | + * |
| 957 | + * System.out.printf("Response status code %d. Created alias '%s' that aliases index '%s'.", |
| 958 | + * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0)); |
| 959 | + * |
| 960 | + * response = searchIndexClient.createOrUpdateAliasWithResponse( |
| 961 | + * new SearchAlias(response.getValue().getName(), Collections.singletonList("new-index-to-alias")) |
| 962 | + * .setETag(response.getValue().getETag()), true, new Context(key1, value1)); |
| 963 | + * |
| 964 | + * System.out.printf("Response status code %d. Updated alias '%s' that aliases index '%s'.", |
| 965 | + * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0)); |
| 966 | + * </pre> |
| 967 | + * <!-- end com.azure.search.documents.indexes.SearchIndexClient.createOrUpdateAliasWithResponse#SearchAlias-boolean-Context --> |
| 968 | + * |
| 969 | + * @param alias definition of the alias to create or update. |
| 970 | + * @param onlyIfUnchanged only update the alias if the eTag matches the alias on the service. |
| 971 | + * @param context additional context that is passed through the HTTP pipeline during the service call |
| 972 | + * @return the created or updated alias. |
| 973 | + */ |
| 974 | + public Response<SearchAlias> createOrUpdateAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged, |
| 975 | + Context context) { |
| 976 | + return asyncClient.createOrUpdateAliasWithResponse(alias, onlyIfUnchanged ? alias.getETag() : null, context) |
| 977 | + .block(); |
| 978 | + } |
| 979 | + |
| 980 | + /** |
| 981 | + * Gets the Azure Cognitive Search alias. |
| 982 | + * |
| 983 | + * <p><strong>Code Sample</strong></p> |
| 984 | + * |
| 985 | + * <p> Get the search alias named "my-alias". </p> |
| 986 | + * |
| 987 | + * <!-- src_embed com.azure.search.documents.indexes.SearchIndexClient.getAlias#String --> |
| 988 | + * <pre> |
| 989 | + * SearchAlias searchAlias = searchIndexClient.getAlias("my-alias"); |
| 990 | + * |
| 991 | + * System.out.printf("Retrieved alias '%s' that aliases index '%s'.", searchAlias.getName(), |
| 992 | + * searchAlias.getIndexes().get(0)); |
| 993 | + * </pre> |
| 994 | + * <!-- end com.azure.search.documents.indexes.SearchIndexClient.getAlias#String --> |
| 995 | + * |
| 996 | + * @param aliasName name of the alias to get. |
| 997 | + * @return the retrieved alias. |
| 998 | + */ |
| 999 | + public SearchAlias getAlias(String aliasName) { |
| 1000 | + return getAliasWithResponse(aliasName, Context.NONE).getValue(); |
| 1001 | + } |
| 1002 | + |
| 1003 | + /** |
| 1004 | + * Gets the Azure Cognitive Search alias. |
| 1005 | + * |
| 1006 | + * <p><strong>Code Sample</strong></p> |
| 1007 | + * |
| 1008 | + * <p> Get the search alias named "my-alias". </p> |
| 1009 | + * |
| 1010 | + * <!-- src_embed com.azure.search.documents.indexes.SearchIndexClient.getAliasWithResponse#String-Context --> |
| 1011 | + * <pre> |
| 1012 | + * Response<SearchAlias> response = searchIndexClient.getAliasWithResponse("my-alias", new Context(key1, value1)); |
| 1013 | + * |
| 1014 | + * System.out.printf("Response status code %d. Retrieved alias '%s' that aliases index '%s'.", |
| 1015 | + * response.getStatusCode(), response.getValue().getName(), response.getValue().getIndexes().get(0)); |
| 1016 | + * </pre> |
| 1017 | + * <!-- end com.azure.search.documents.indexes.SearchIndexClient.getAliasWithResponse#String-Context --> |
| 1018 | + * |
| 1019 | + * @param aliasName name of the alias to get. |
| 1020 | + * @param context additional context that is passed through the HTTP pipeline during the service call |
| 1021 | + * @return the retrieved alias. |
| 1022 | + */ |
| 1023 | + public Response<SearchAlias> getAliasWithResponse(String aliasName, Context context) { |
| 1024 | + return asyncClient.getAliasWithResponse(aliasName, context).block(); |
| 1025 | + } |
| 1026 | + |
| 1027 | + /** |
| 1028 | + * Deletes the Azure Cognitive Search alias. |
| 1029 | + * |
| 1030 | + * <p><strong>Code Sample</strong></p> |
| 1031 | + * |
| 1032 | + * <p> Delete the search alias named "my-alias". </p> |
| 1033 | + * |
| 1034 | + * <!-- src_embed com.azure.search.documents.indexes.SearchIndexClient.deleteAlias#String --> |
| 1035 | + * <pre> |
| 1036 | + * searchIndexClient.deleteAlias("my-alias"); |
| 1037 | + * |
| 1038 | + * System.out.println("Deleted alias 'my-alias'."); |
| 1039 | + * </pre> |
| 1040 | + * <!-- end com.azure.search.documents.indexes.SearchIndexClient.deleteAlias#String --> |
| 1041 | + * |
| 1042 | + * @param aliasName name of the alias to delete. |
| 1043 | + */ |
| 1044 | + public void deleteAlias(String aliasName) { |
| 1045 | + asyncClient.deleteAliasWithResponse(aliasName, null, Context.NONE).block(); |
| 1046 | + } |
| 1047 | + |
| 1048 | + /** |
| 1049 | + * Deletes the Azure Cognitive Search alias. |
| 1050 | + * |
| 1051 | + * <p><strong>Code Sample</strong></p> |
| 1052 | + * |
| 1053 | + * <p> Delete the search alias named "my-alias". </p> |
| 1054 | + * |
| 1055 | + * <!-- src_embed com.azure.search.documents.indexes.SearchIndexClient.deleteAliasWithResponse#SearchAlias-boolean-Context --> |
| 1056 | + * <pre> |
| 1057 | + * SearchAlias searchAlias = searchIndexClient.getAlias("my-alias"); |
| 1058 | + * |
| 1059 | + * Response<Void> response = searchIndexClient.deleteAliasWithResponse(searchAlias, true, |
| 1060 | + * new Context(key1, value1)); |
| 1061 | + * |
| 1062 | + * System.out.printf("Response status code %d. Deleted alias 'my-alias'.", response.getStatusCode()); |
| 1063 | + * </pre> |
| 1064 | + * <!-- end com.azure.search.documents.indexes.SearchIndexClient.deleteAliasWithResponse#SearchAlias-boolean-Context --> |
| 1065 | + * |
| 1066 | + * @param alias the alias to delete. |
| 1067 | + * @param onlyIfUnchanged only delete the alias if the eTag matches the alias on the service. |
| 1068 | + * @param context additional context that is passed through the HTTP pipeline during the service call |
| 1069 | + * @return a response indicating the alias has been deleted. |
| 1070 | + */ |
| 1071 | + public Response<Void> deleteAliasWithResponse(SearchAlias alias, boolean onlyIfUnchanged, Context context) { |
| 1072 | + return asyncClient.deleteAliasWithResponse(alias.getName(), onlyIfUnchanged ? alias.getETag() : null, context) |
| 1073 | + .block(); |
| 1074 | + } |
| 1075 | + |
| 1076 | + /** |
| 1077 | + * Lists all aliases in the Azure Cognitive Search service. |
| 1078 | + * |
| 1079 | + * <p><strong>Code Sample</strong></p> |
| 1080 | + * |
| 1081 | + * <p> List aliases </p> |
| 1082 | + * |
| 1083 | + * <!-- src_embed com.azure.search.documents.indexes.SearchIndexClient.listAliases --> |
| 1084 | + * <pre> |
| 1085 | + * searchIndexClient.listAliases() |
| 1086 | + * .forEach(searchAlias -> System.out.printf("Listed alias '%s' that aliases index '%s'.", |
| 1087 | + * searchAlias.getName(), searchAlias.getIndexes().get(0))); |
| 1088 | + * </pre> |
| 1089 | + * <!-- end com.azure.search.documents.indexes.SearchIndexClient.listAliases --> |
| 1090 | + * |
| 1091 | + * @return a list of aliases in the service. |
| 1092 | + */ |
| 1093 | + public PagedIterable<SearchAlias> listAliases() { |
| 1094 | + return listAliases(Context.NONE); |
| 1095 | + } |
| 1096 | + |
| 1097 | + /** |
| 1098 | + * Lists all aliases in the Azure Cognitive Search service. |
| 1099 | + * |
| 1100 | + * <p><strong>Code Sample</strong></p> |
| 1101 | + * |
| 1102 | + * <p> List aliases </p> |
| 1103 | + * |
| 1104 | + * <!-- src_embed com.azure.search.documents.indexes.SearchIndexClient.listAliases#Context --> |
| 1105 | + * <pre> |
| 1106 | + * searchIndexClient.listAliases(new Context(key1, value1)) |
| 1107 | + * .forEach(searchAlias -> System.out.printf("Listed alias '%s' that aliases index '%s'.", |
| 1108 | + * searchAlias.getName(), searchAlias.getIndexes().get(0))); |
| 1109 | + * </pre> |
| 1110 | + * <!-- end com.azure.search.documents.indexes.SearchIndexClient.listAliases#Context --> |
| 1111 | + * |
| 1112 | + * @param context additional context that is passed through the HTTP pipeline during the service call |
| 1113 | + * @return a list of aliases in the service. |
| 1114 | + */ |
| 1115 | + public PagedIterable<SearchAlias> listAliases(Context context) { |
| 1116 | + return new PagedIterable<>(asyncClient.listAliases(context)); |
| 1117 | + } |
866 | 1118 | } |
0 commit comments