File tree Expand file tree Collapse file tree
algoliasearch-core/src/main/java/com/algolia/search Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments