Skip to content

Commit b79300d

Browse files
committed
added: indexExists method
[changelog] Exists method: Return whether an index exists or not.
1 parent d340b28 commit b79300d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

algoliasearch-core/src/main/java/com/algolia/search/SearchIndex.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,36 @@ public CompletableFuture<TaskStatusResponse> getTaskAsync(
17731773
requestOptions);
17741774
}
17751775

1776+
/**
1777+
* Return whether an index exists or not
1778+
*
1779+
* @throws AlgoliaRetryException When the retry has failed on all hosts
1780+
* @throws AlgoliaApiException When the API sends an http error code
1781+
* @throws AlgoliaRuntimeException When an error occurred during the serialization
1782+
*/
1783+
public boolean exists() {
1784+
return LaunderThrowable.await(existsAsync());
1785+
}
1786+
1787+
/**
1788+
* Return whether an index exists or not
1789+
*
1790+
* @throws AlgoliaRetryException When the retry has failed on all hosts
1791+
* @throws AlgoliaApiException When the API sends an http error code
1792+
* @throws AlgoliaRuntimeException When an error occurred during the serialization
1793+
*/
1794+
public CompletableFuture<Boolean> existsAsync() {
1795+
try {
1796+
this.getSettings();
1797+
} catch (AlgoliaApiException ex) {
1798+
if (ex.getHttpErrorCode() == 404) {
1799+
return CompletableFuture.completedFuture(false);
1800+
}
1801+
throw ex;
1802+
}
1803+
return CompletableFuture.completedFuture(true);
1804+
}
1805+
17761806
/**
17771807
* Wait for a task to complete before executing the next line of code, to synchronize index
17781808
* updates. All write operations in Algolia are asynchronous by design.

0 commit comments

Comments
 (0)