English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Elasticsearch Index API

These APIs are responsible for managing all aspects of an index, such as settings, aliases, mappings, index templates.

Create index

This API can help you create an index. When a user passes a JSON object to any index, an index can be automatically created, or an index can be created before that. To create an index, you only need to send a PUT request with settings, mappings, and aliases, or simply send a request without content.

PUT colleges

After running the above code, we get the following output-

{
   "acknowledged": true
   "shards_acknowledged": true
   "index": "colleges"
}

We can also add some settings to the above command-

PUT colleges
{
  "settings": {
      "index": {
         "number_of_shards": 3,
         "number_of_replicas": 2
      }
   }
}

After running the above code, we get the following output-

{
   "acknowledged": true
   "shards_acknowledged": true
   "index": "colleges"
}

Delete Index

This API can help you delete any index. You just need to pass a delete request with the name of the specific index.

DELETE /colleges

You can use _all or*Delete all indexes.

Get Index

This API can be called by sending a GET request to one or more indexes. This will return information about the indexes.

GET colleges

After running the above code, we get the following output-

{
   "colleges": {
      "aliases": {
         "alias_1": { },
         "alias_2": {
            "filter": {
               "term": {
                  "user": "pkay"
               }
            },
            "index_routing": "pkay",
            "search_routing": "pkay"
         }
      },
      "mappings": { },
      "settings": {
         "index": {
            "creation_date": ""1556245406616",
            "number_of_shards": ""1",
            "number_of_replicas": ""1",
            "uuid": ""3ExJbdl2R1qDLssIkwDAug",
            "version": {
               "created": ""7000099"
            },
            "provided_name": "colleges"
         }
      }
   }
}

You can use _all or*Get information about all indexes.

Index Exists

The existence of an index can be determined by sending a GET request to the index alone. If the HTTP response is200, it exists. If it is404does not exist.

HEAD colleges

After running the above code, we get the following output-

200-OK

Index Settings

You can obtain the index settings by simply appending the _settings keyword at the end of the URL.

GET /colleges/_settings

After running the above code, we get the following output-

{
   "colleges": {
      "settings": {
         "index": {
            "creation_date": ""1556245406616",
            "number_of_shards": ""1",
            "number_of_replicas": ""1",
            "uuid": ""3ExJbdl2R1qDLssIkwDAug",
            "version": {
               "created": ""7000099"
            },
            "provided_name": "colleges"
         }
      }
   }
}

Index Statistics

This API can help you extract statistical information about a specific index. You only need to send a GET request with the index URL and the _stats keyword at the end.

GET /_stats

After running the above code, we get the following output-

………………………………………………
},
   "request_cache": {
      "memory_size_in_bytes": : 849,
      "evictions": 0,
      "hit_count": : 1171,
      "miss_count": : 4
   },
   "recovery": {
      "current_as_source": 0,
      "current_as_target": 0,
      "throttle_time_in_millis": 0
   }
}………………………………………………

Flush

The index refresh process ensures that all data currently retained in the transaction log is also permanently retained in Lucene. This reduces recovery time because, after opening the Lucene index, there is no need to re-index data from the transaction log.

POST colleges/_flush

After running the above code, we get the following output-

{
   "_shards": {
      "total": 2,
      "successful": 1,
      "failed": 0
   } 
}