Renaming Files and Directories
So far, so good. Renaming a file is easy—a simple update
or index
request is all that is required. You can even use optimistic concurrency control to ensure that your change doesn’t conflict with the changes from another user:
PUT
/fs/file/
1
?version=
2
{
"name"
:
"README.asciidoc"
,
"path"
:
"/clinton/projects/elasticsearch"
,
"contents"
:
"Starting a new Elasticsearch project is easy..."
}
- The
version
number ensures that the change is applied only if the document in the index has this same version number.
We can even rename a directory, but this means updating all of the files that exist anywhere in the path hierarchy beneath that directory. This may be quick or slow, depending on how many files need to be updated. All we would need to do is to use scan-and-scroll to retrieve all the files, and the bulk
API to update them. The process isn’t atomic, but all files will quickly move to their new home.
Comments