How do I remove indices from an alias using the elasticsearch-java client?
The API does not seem to have a method to specify the alias.
I cannot find an examples nor documentation.
I am busy converting code from the older highlevel to the newer client.
It will be a while before I am able to compile all the code and or have working tests.
I would rather not find out by trial and error.
What I have now is this:
private void removeIndexFromAlias(final List<String> indicesToDelete, final String alias) throws IOException {
client.indices()
.updateAliases((UpdateAliasesRequest.Builder updateAliasesRequestBuilder) ->
updateAliasesRequestBuilder
.actions( actionBuilder ->
actionBuilder.removeIndex((RemoveIndexAction.Builder removeIndexAction) -> removeIndexAction
//REMARK: I am not sure if .index(alias) is right here.
// There is no .alias(...) method
// I cannot find examples
.index(alias)
.indices(indicesToDelete))));
}
The only option to provide an alias is in the .index method as suggested by IntelliJ ;).
Hello!
Don't perform this call! It doesn't delete an index from an alias, it deletes both alias and index. I'll try to understand why this is so sparsely documented an will get back to you, in the meantime the correct way to remove an index from an alias is:
Thank you. It is a lot shorter too. Of course I didn't believe IntelliJ here;) I will probably come back with similar questions when I get stuck again and the IDE or documentation leads me in the wrong direction.
Some thoughts:
Once written the code is easy to read with the new API; but only if you had prior exposure to code written for NodeJS, jQuery or similar. People who wrote less functional style Java will have a harder time understanding it.
Writing the code is hard.
The code I wrote is what I get when I follow the types and use the intellisense of the IDE. The combination of builders and lambdas in combination with generics with Java's type erasure makes it hard for the IDE too to provide sensible options. Having better Javadoc would not get us far enough. Good examples with best practices for common use cases are essential to use this SDK.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.