Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a document using index alias

I have created an index "index-000001" with primary shards = 5 and replica = 1. And I have created two aliases

  1. alias-read -> index-000001
  2. alias-write -> index-000001

for indexing and searching purposes. When I do a rollover on alias-write when it reaches its maximum capacity, it creates a new "index-000002" and updates aliases as

  1. alias-read -> index-000001 and index-000002
  2. alias-write -> index-000002

How do I update/delete a document existing in index-000001(what if in case all I know is the document id but not in which index the document resides) ?

Thanks

like image 924
user3861992 Avatar asked Jun 09 '17 19:06

user3861992


People also ask

Can you update a document in Elasticsearch?

The script can update, delete, or skip modifying the document. The update API also supports passing a partial document, which is merged into the existing document. To fully replace an existing document, use the index API.

What is an index alias?

An alias is a secondary name for a group of data streams or indices. Most Elasticsearch APIs accept an alias in place of a data stream or index name. You can change the data streams or indices of an alias at any time.

What is an API alias?

An alias in API Gateway holds environment-specific property values that can be used in policy routing configuration. The aliases can be referred to in routing endpoints, routing rules, endpoint connection properties, and outbound authentication tokens instead of providing a real value.


1 Answers

Updating using an index alias is not directly possible, the best solution for this is to use a search query using the document id or a term and get the required index. Using the index you can update your document directly.

GET alias-read/{type}/{doc_id} will get the required Document if doc_id is known.

If doc_id is not known, then find it using a unique id reference

GET alias-read/_search
{
   "term" : { "field" : "value" }
}

In both cases, you will get a single document as a response.

Once the document is obtained, you can use the "_index" field to get the required index.

PUT {index_name}/{type}/{id} {
    "required_field" : "new_value"
}

to update the document.

like image 82
Phenomenal One Avatar answered Oct 21 '22 13:10

Phenomenal One