Specifying aliases

Elasticsearch allows the user to create an alias—a virtual index name that can be used to refer to an index or multiple indices. The Elasticsearch index API aliases an index with a name. This enables all the APIs to automatically convert their alias names into the actual index name. 

Say, for example, that we want to query against a set of similar indexes. Rather than specifying each of the index names in the query, we can make use of aliases and execute the query against the alias. The alias will internally point to all the indexes and perform a query against them. This will be highly beneficial if we added certain indexes dynamically on a regular basis, so that one application/user performing the query need not worry about including those indexes in the query as long as the index is updated with the alias (which can be done manually by an admin or specified during index creation). 

Let's say the IT admin creates an alias pointing to all the indexes containing the metrics for a specific month. For example, as shown in the following code snippet, an alias called april_04_metrics is created for all the indexes of the metricbeat-7.0.0-2019.04.* pattern, that is, those Metricbeats indexes that are created on a daily basis in the month of April 2019:

curl -X POST   http://localhost:9200/_aliases  -H 'content-type: application/json' -d '
{
"actions":
[
{"add":{ "index" : "metricbeat-7.0.0-2019.04.*", "alias": "april_04_metrics"} }
]
}'

Now, using the april_04_metrics alias name, the query can be executed against all the indexes of the metricbeat-7.0.0-2019.04.* pattern as follows:

curl -X GET http://localhost:9200/april_04_metrics/_search  

In the following example, the sales alias is created against the it_sales and retail_sales indexes. In the future, if a new sales index gets created, then that index can also point to the sales index so that the end user/application can always make use of the sales endpoint to query all sales data, as follows:

curl -X POST   http://localhost:9200/_aliases -d '{ 
"actions" : [
{ "add" : { "index" : "it_sales", "alias" : "sales" } },
{ "add" : { "index" : "retail_sales", "alias" : "sales" } }
] }

To remove an alias from an index, use the remove action of the aliases API, as follows:

curl -X POST   http://localhost:9200/_aliases -d '
{ "actions" : [ { "remove" : { "index" : "retail_sales", "alias" : "sales" } }] }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.81.200