> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Index exists

> Check if an index exists or not.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Check if index exists" href="/doc/libraries/sdk/methods/search/index-exists" />

**Required ACL:** `settings`

You can [initialize an index](/doc/libraries/sdk/v1/initialize) with any name.
The index is created on Algolia's servers when you add objects or set settings.
To prevent accidentally creating new indices, or changing existing indices,
you can use the `exists` method.
The `exists` method returns a boolean that indicates **whether an initialized index has been created**.

<Info>
  **Be careful when using this method to execute code conditionally.**
  Because index operations are asynchronous, an index might not yet exist when you call the `exist` method, but it might exist when the conditional code runs.
  Be mindful of the surrounding code, and of any process that might change your indices.
</Info>

## Examples

### Check if an index exists

<CodeGroup>
  ```cs C# theme={"system"}
  // Use an API key with `settings` ACL
  var client = new SearchClient("YourApplicationID", "YourAPIKey");
  var index = client.InitIndex("indexName");

  index.Exists();

  // Asynchronous
  await index.ExistsAsync();
  ```

  ```go Go theme={"system"}
  // Use an API key with `settings` ACL
  client := search.NewClient('YourApplicationID', 'YourAPIKey')
  index := client.InitIndex('indexName')
  ok, err := index.Exists()
  ```

  ```java Java theme={"system"}
  // Use an API key with `settings` ACL
  SearchClient client = DefaultSearchClient.create("YourApplicationID", "YourAPIKey");
  SearchIndex<Record> index = client.initIndex("indexName", Record.class);

  index.exists();
  ```

  ```js JavaScript theme={"system"}
  const algoliasearch = require('algoliasearch');

  // Use an API key with `settings` ACL
  const client = algoliasearch('YourApplicationID', 'YourAPIKey');
  const index = client.initIndex('indexName');

  index.exists().then(result => {
    console.log(result);
  });
  ```

  ```kotlin Kotlin theme={"system"}
  // Use an API key with `settings` ACL
  val client = ClientSearch(
    ApplicationID("YourApplicationID"),
    APIKey("YourAPIKey")
  )
  val index = client.initIndex(IndexName("indexName"))

  index.exists()
  ```

  ```php PHP theme={"system"}
  <?php
  require_once __DIR__."/vendor/autoload.php";
  use Algolia\AlgoliaSearch\SearchClient;

  // Use an API key with `settings` ACL
  $client = SearchClient::create(
    'YourApplicationID', 'YourAPIKey'
  );
  $index = $client->initIndex('indexName');

  $index->exists();
  ```

  ```python Python theme={"system"}
  from algoliasearch.search_client import SearchClient

  # Use an API key with `settings` ACL
  client = SearchClient.create("YourApplicationID", "YourAPIKey")
  index = client.init_index("indexName")

  index.exists()
  ```

  ```ruby Ruby theme={"system"}
  require 'algolia'

  # Use an API key with `settings` ACL
  client = Algolia::Search::Client.create(
    'YourApplicationID', 'YourAPIKey'
  )
  index = client.init_index('indexName')

  index.exists?
  ```

  ````

  ```swift Swift
  import AlgoliaSearchClient

  // Use an API key with `deleteIndex` ACL
  let client = SearchClient(
    appID: "YourApplicationID",
    apiKey: "YourAPIKey"
  )
  let index = client.index(withName: "indexName")

  index.exists { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ````
</CodeGroup>

## Parameters

This method doesn't accept any input parameters.

## Response

### Response as JSON

This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the `getLogs` method.
Don't rely on the order of properties—JSON objects don't preserve key order.

This method returns `true` if the index exists, and `false` otherwise.
