-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REST high-level client: add support for exists alias #28332
Changes from all commits
38dbb8d
5cb6e7d
dcf0994
55e87d8
0f32d21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import org.apache.http.entity.ContentType; | ||
import org.apache.lucene.util.BytesRef; | ||
import org.elasticsearch.action.DocWriteRequest; | ||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; | ||
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; | ||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; | ||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; | ||
|
@@ -133,7 +134,7 @@ static Request delete(DeleteRequest deleteRequest) { | |
} | ||
|
||
static Request deleteIndex(DeleteIndexRequest deleteIndexRequest) { | ||
String endpoint = endpoint(deleteIndexRequest.indices(), Strings.EMPTY_ARRAY, ""); | ||
String endpoint = endpoint(deleteIndexRequest.indices()); | ||
|
||
Params parameters = Params.builder(); | ||
parameters.withTimeout(deleteIndexRequest.timeout()); | ||
|
@@ -144,7 +145,7 @@ static Request deleteIndex(DeleteIndexRequest deleteIndexRequest) { | |
} | ||
|
||
static Request openIndex(OpenIndexRequest openIndexRequest) { | ||
String endpoint = endpoint(openIndexRequest.indices(), Strings.EMPTY_ARRAY, "_open"); | ||
String endpoint = endpoint(openIndexRequest.indices(), "_open"); | ||
|
||
Params parameters = Params.builder(); | ||
|
||
|
@@ -157,7 +158,7 @@ static Request openIndex(OpenIndexRequest openIndexRequest) { | |
} | ||
|
||
static Request closeIndex(CloseIndexRequest closeIndexRequest) { | ||
String endpoint = endpoint(closeIndexRequest.indices(), Strings.EMPTY_ARRAY, "_close"); | ||
String endpoint = endpoint(closeIndexRequest.indices(), "_close"); | ||
|
||
Params parameters = Params.builder(); | ||
|
||
|
@@ -169,7 +170,7 @@ static Request closeIndex(CloseIndexRequest closeIndexRequest) { | |
} | ||
|
||
static Request createIndex(CreateIndexRequest createIndexRequest) throws IOException { | ||
String endpoint = endpoint(createIndexRequest.indices(), Strings.EMPTY_ARRAY, ""); | ||
String endpoint = endpoint(createIndexRequest.indices()); | ||
|
||
Params parameters = Params.builder(); | ||
parameters.withTimeout(createIndexRequest.timeout()); | ||
|
@@ -472,23 +473,54 @@ static Request multiSearch(MultiSearchRequest multiSearchRequest) throws IOExcep | |
return new Request(HttpPost.METHOD_NAME, "/_msearch", params.getParams(), entity); | ||
} | ||
|
||
static Request existsAlias(GetAliasesRequest getAliasesRequest) { | ||
Params params = Params.builder(); | ||
params.withIndicesOptions(getAliasesRequest.indicesOptions()); | ||
params.withLocal(getAliasesRequest.local()); | ||
if (getAliasesRequest.indices().length == 0 && getAliasesRequest.aliases().length == 0) { | ||
throw new IllegalArgumentException("existsAlias requires at least an alias or an index"); | ||
} | ||
String endpoint = endpoint(getAliasesRequest.indices(), "_alias", getAliasesRequest.aliases()); | ||
return new Request("HEAD", endpoint, params.getParams(), null); | ||
} | ||
|
||
private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException { | ||
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef(); | ||
return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType)); | ||
} | ||
|
||
static String endpoint(String index, String type, String id) { | ||
return buildEndpoint(index, type, id); | ||
} | ||
|
||
static String endpoint(String index, String type, String id, String endpoint) { | ||
return buildEndpoint(index, type, id, endpoint); | ||
} | ||
|
||
static String endpoint(String[] indices) { | ||
return buildEndpoint(String.join(",", indices)); | ||
} | ||
|
||
static String endpoint(String[] indices, String endpoint) { | ||
return buildEndpoint(String.join(",", indices), endpoint); | ||
} | ||
|
||
static String endpoint(String[] indices, String[] types, String endpoint) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK in 7.0 multiple types are no longer supported. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is the plan, but we are not there yet. What we currently do in the client is aligned with what the API supports. Once the API will change, it will be time to also update the client. |
||
return endpoint(String.join(",", indices), String.join(",", types), endpoint); | ||
return buildEndpoint(String.join(",", indices), String.join(",", types), endpoint); | ||
} | ||
|
||
static String endpoint(String[] indices, String endpoint, String[] suffixes) { | ||
return buildEndpoint(String.join(",", indices), endpoint, String.join(",", suffixes)); | ||
} | ||
|
||
static String endpoint(String[] indices, String endpoint, String type) { | ||
return endpoint(String.join(",", indices), endpoint, type); | ||
} | ||
|
||
/** | ||
* Utility method to build request's endpoint. | ||
* Utility method to build request's endpoint given its parts as strings | ||
*/ | ||
static String endpoint(String... parts) { | ||
static String buildEndpoint(String... parts) { | ||
StringJoiner joiner = new StringJoiner("/", "/", ""); | ||
for (String part : parts) { | ||
if (Strings.hasLength(part)) { | ||
|
@@ -656,6 +688,11 @@ Params withIndicesOptions(IndicesOptions indicesOptions) { | |
return this; | ||
} | ||
|
||
Params withLocal(boolean local) { | ||
putParam("local", Boolean.toString(local)); | ||
return this; | ||
} | ||
|
||
Map<String, String> getParams() { | ||
return Collections.unmodifiableMap(params); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Makes things easier :) Could you do the same for
createIndex
anddeleteIndex
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch