user3861992
user3861992

Reputation: 319

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

Upvotes: 10

Views: 2383

Answers (1)

Phenomenal One
Phenomenal One

Reputation: 2587

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.

Upvotes: 6

Related Questions