# How can I copy documents to same index and type?

**URL:** <https://discuss.elastic.co/t/how-can-i-copy-documents-to-same-index-and-type/66728>\
**Category:** Elasticsearch\
**Created:** [November 21, 2016, 2:01pm UTC](https://discuss.elastic.co/t/how-can-i-copy-documents-to-same-index-and-type/66728 "2016-11-21T14:01:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![liny](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@liny](https://discuss.elastic.co/u/liny)\
**Post date:** [November 21, 2016, 2:01pm UTC](https://discuss.elastic.co/t/how-can-i-copy-documents-to-same-index-and-type/66728/1 "2016-11-21T14:01:43Z")

</div>

Hi,

I am indexing files to elasticsearch 5 for content searching.  
A "content" field contains the content of file, which maybe has large data in mega-byte.  
The JSON example is shown as below:

> ```
> {
> "fileId": "unique_fileId",
> "filename": "ms_word.docx",
> "content": "<large data here>"
> }
> 
> ```

Because user will copy files to another folder, I need to copy documents to the same index and type with different document IDs.  
I don't want to read files again, and the best way should be just copying theses documents within same index and type by setting new fileId.  
The reindex API can't fit my requirement because the target must be another index.

I'd like to know if any better way to do above requirement?  
Appreciated for any comments.

Anderson.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [November 21, 2016, 2:24pm UTC](https://discuss.elastic.co/t/how-can-i-copy-documents-to-same-index-and-type/66728/2 "2016-11-21T14:24:12Z")

</div>

Hi,

two general question:

- Why are you storing your binary data in elasticsearch at all? Is it searchable content?

- when files change location on the user side, why can't you just update some path information about the location of the "large data"?

---

<div class="post-metadata">

**Author:** ![liny](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@liny](https://discuss.elastic.co/u/liny)\
**Post date:** [November 22, 2016, 2:24am UTC](https://discuss.elastic.co/t/how-can-i-copy-documents-to-same-index-and-type/66728/3 "2016-11-22T02:24:35Z")

</div>

Hi, @cbuescher:

> Why are you storing your binary data in elasticsearch at all? Is it searchable content?

Not binary data, I'll use Apache Tika to extract the content as text for searching.

.

> when files change location on the user side, why can't you just update some path information about the location of the "large data"?

For copying only operation, this could be a good solution.  
But if the user copies "my\_word.docx" to "my\_word\_1.docx" in the same folder, I still have to copy as new document, because these two files are two records in searching result.  
And maybe later user updated "my\_word\_1.docx", I only need to read the file content once for updating.

Let me know if any.  
Thank you.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [November 22, 2016, 8:44am UTC](https://discuss.elastic.co/t/how-can-i-copy-documents-to-same-index-and-type/66728/4 "2016-11-22T08:44:35Z")

</div>

> [@liny](#):
>
> But if the user copies "my\_word.docx" to "my\_word\_1.docx" in the same folder, I still have to copy as new document, because these two files are two records in searching result.

Why not insert the new document again then?

---

<div class="post-metadata">

**Author:** ![liny](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@liny](https://discuss.elastic.co/u/liny)\
**Post date:** [December 4, 2016, 6:29am UTC](https://discuss.elastic.co/t/how-can-i-copy-documents-to-same-index-and-type/66728/5 "2016-12-04T06:29:33Z")

</div>

I think it should be the fastest way to tell ES to copy the same content instead of reading and extracting file again.  
Let me know if any, thank you.

---

<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:** [January 1, 2017, 6:30am UTC](https://discuss.elastic.co/t/how-can-i-copy-documents-to-same-index-and-type/66728/6 "2017-01-01T06:30:01Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
