# Is it possible to change the ids of a set of documents?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-change-the-ids-of-a-set-of-documents/14335>\
**Category:** Elasticsearch\
**Created:** [November 9, 2013, 3:52pm UTC](https://discuss.elastic.co/t/is-it-possible-to-change-the-ids-of-a-set-of-documents/14335 "2013-11-09T15:52:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rian\_Stockbower](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rian_stockbower/32/1545_2.png) [@Rian\_Stockbower](https://discuss.elastic.co/u/Rian_Stockbower)\
**Post date:** [November 9, 2013, 3:52pm UTC](https://discuss.elastic.co/t/is-it-possible-to-change-the-ids-of-a-set-of-documents/14335/1 "2013-11-09T15:52:07Z")

</div>

I have an id that's mapped to a path. That path corresponds with the UNC  
path of a document on a drive. When that file changes, I simply re-index  
the contents of that file so the index stays up to date.

But what if I have a rename operation? Or a directory rename operation?

I think file renaming should be easy:

1. Grab the document by its old id
2. Update the mapped field with the new path, effectively changing its  
document id
3. There is no step 3

But a directory rename operation is a bit more complicated, I think. I see  
two possibilities:

Compute the change by walking the directory tree.

1. Recurse through the changed directory, and build a list of paths that  
will have to be updated
2. Grab each document by its old id
3. Update the mapped field with the new path, effectively changing its  
document id

But this can be an expensive operation in terms of disk IO, even if the  
computed query is just a single bulk update query which would be quite fast.

Second possibility: have elasticsearch examine the index for ids that  
contain a pattern that matches the old path, and update each to the new  
path. Is such a thing possible? If so, how expensive would it be?

-Rian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Shuai\_Lin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shuai_lin/32/1980_2.png) [@Shuai\_Lin](https://discuss.elastic.co/u/Shuai_Lin)\
**Post date:** [November 10, 2013, 2:59am UTC](https://discuss.elastic.co/t/is-it-possible-to-change-the-ids-of-a-set-of-documents/14335/2 "2013-11-10T02:59:28Z")

</div>

Hi,

You can use a prefix query[1] to get all the docs that need to be updated,  
and do a partial update[2].

[1]

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

[2]

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Regards

On Sat, Nov 9, 2013 at 11:52 PM, rianjs [rstockbower@gmail.com](mailto:rstockbower@gmail.com) wrote:

> I have an id that's mapped to a path. That path corresponds with the UNC  
> path of a document on a drive. When that file changes, I simply re-index  
> the contents of that file so the index stays up to date.
> 
> But what if I have a rename operation? Or a directory rename operation?
> 
> I think file renaming should be easy:
> 
> 1. Grab the document by its old id
> 2. Update the mapped field with the new path, effectively changing its  
> document id
> 3. There is no step 3
> 
> But a directory rename operation is a bit more complicated, I think. I see  
> two possibilities:
> 
> Compute the change by walking the directory tree.
> 
> 1. Recurse through the changed directory, and build a list of paths  
> that will have to be updated
> 2. Grab each document by its old id
> 3. Update the mapped field with the new path, effectively changing its  
> document id
> 
> But this can be an expensive operation in terms of disk IO, even if the  
> computed query is just a single bulk update query which would be quite fast.
> 
> Second possibility: have elasticsearch examine the index for ids that  
> contain a pattern that matches the old path, and update each to the new  
> path. Is such a thing possible? If so, how expensive would it be?
> 
> -Rian
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:07am UTC](https://discuss.elastic.co/t/is-it-possible-to-change-the-ids-of-a-set-of-documents/14335/3 "2017-07-06T02:07:58Z")

</div>


