-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
Add support for indices exists to REST high level client #27384
Changes from 29 commits
a3a2f22
5b6bd87
d05262f
2e4d42a
e57d2ff
abf2919
a63880f
b1379b6
2ea0363
902aa9b
c5af2e7
a14e05b
da2ad92
18e2c92
51ed9aa
3491962
53c681f
f35fe50
3aad6c1
0e6adfa
53d226c
659a252
d665b55
3fd5006
fe18f27
1157286
9461afb
910cc95
8df7602
870fdfd
1f57a30
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 |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; | ||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; | ||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; | ||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest; | ||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; | ||
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; | ||
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest; | ||
|
@@ -55,6 +56,7 @@ | |
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.WriteRequest; | ||
import org.elasticsearch.action.support.master.AcknowledgedRequest; | ||
import org.elasticsearch.action.support.master.MasterNodeReadRequest; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.action.support.replication.ReplicationRequest; | ||
import org.elasticsearch.action.update.UpdateRequest; | ||
|
@@ -262,6 +264,26 @@ public void testExists() { | |
getAndExistsTest(Request::exists, HttpHead.METHOD_NAME); | ||
} | ||
|
||
public void testIndicesExist() { | ||
String[] indices = randomIndicesNames(1, 10); | ||
|
||
GetIndexRequest getIndexRequest = new GetIndexRequest().indices(indices); | ||
|
||
Map<String, String> expectedParams = new HashMap<>(); | ||
setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams); | ||
setRandomLocal(getIndexRequest, expectedParams); | ||
setRandomFlatSettings(getIndexRequest, expectedParams); | ||
setRandomHumanReadable(getIndexRequest, expectedParams); | ||
setRandomIncludeDefaults(getIndexRequest, expectedParams); | ||
|
||
final Request request = Request.indicesExist(getIndexRequest); | ||
|
||
assertEquals(HttpHead.METHOD_NAME, request.getMethod()); | ||
assertEquals("/" + String.join(",", indices), request.getEndpoint()); | ||
assertThat(expectedParams, equalTo(request.getParameters())); | ||
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. nit: can you assert that request.getEntity is null please? |
||
assertNull(request.getEntity()); | ||
} | ||
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. I think that one test here is enough. test it with a random number of indices ? 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. Done! Test is now using up to 10 indices with random names. 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. with setRandomIndicesOptions this should not be needed |
||
|
||
private static void getAndExistsTest(Function<GetRequest, Request> requestConverter, String method) { | ||
String index = randomAlphaOfLengthBetween(3, 10); | ||
String type = randomAlphaOfLengthBetween(3, 10); | ||
|
@@ -1008,12 +1030,7 @@ public void testExistsAlias() { | |
String[] aliases = randomIndicesNames(indices.length == 0 ? 1 : 0, 5); | ||
getAliasesRequest.aliases(aliases); | ||
Map<String, String> expectedParams = new HashMap<>(); | ||
if (randomBoolean()) { | ||
boolean local = randomBoolean(); | ||
getAliasesRequest.local(local); | ||
} | ||
expectedParams.put("local", Boolean.toString(getAliasesRequest.local())); | ||
|
||
setRandomLocal(getAliasesRequest, expectedParams); | ||
setRandomIndicesOptions(getAliasesRequest::indicesOptions, getAliasesRequest::indicesOptions, expectedParams); | ||
|
||
Request request = Request.existsAlias(getAliasesRequest); | ||
|
@@ -1252,6 +1269,46 @@ private static void setRandomIndicesOptions(Consumer<IndicesOptions> setter, Sup | |
} | ||
} | ||
|
||
private static void setRandomIncludeDefaults(GetIndexRequest request, Map<String, String> expectedParams) { | ||
if (randomBoolean()) { | ||
boolean includeDefaults = randomBoolean(); | ||
request.includeDefaults(includeDefaults); | ||
if (includeDefaults) { | ||
expectedParams.put("include_defaults", String.valueOf(includeDefaults)); | ||
} | ||
} | ||
} | ||
|
||
private static void setRandomHumanReadable(GetIndexRequest request, Map<String, String> expectedParams) { | ||
if (randomBoolean()) { | ||
boolean humanReadable = randomBoolean(); | ||
request.humanReadable(humanReadable); | ||
if (humanReadable) { | ||
expectedParams.put("human", String.valueOf(humanReadable)); | ||
} | ||
} | ||
} | ||
|
||
private static void setRandomFlatSettings(GetIndexRequest request, Map<String, String> expectedParams) { | ||
if (randomBoolean()) { | ||
boolean flatSettings = randomBoolean(); | ||
request.flatSettings(flatSettings); | ||
if (flatSettings) { | ||
expectedParams.put("flat_settings", String.valueOf(flatSettings)); | ||
} | ||
} | ||
} | ||
|
||
private static void setRandomLocal(MasterNodeReadRequest<?> request, Map<String, String> expectedParams) { | ||
if (randomBoolean()) { | ||
boolean local = randomBoolean(); | ||
request.local(local); | ||
if (local) { | ||
expectedParams.put("local", String.valueOf(local)); | ||
} | ||
} | ||
} | ||
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. good work! |
||
|
||
private static void setRandomTimeout(Consumer<String> setter, TimeValue defaultTimeout, Map<String, String> expectedParams) { | ||
if (randomBoolean()) { | ||
String timeout = randomTimeValue(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
include::create_index.asciidoc[] | ||
|
||
<<<<<<< HEAD | ||
include::indices_exists.asciidoc[] | ||
|
||
include::deleteindex.asciidoc[] | ||
======= | ||
include::delete_index.asciidoc[] | ||
>>>>>>> master | ||
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. could you fix this? A merge gone wrong I think 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. include::deleteindex.asciidoc[] should go, it's been replaced by include::delete_index.asciidoc[] 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. Fixed, thanks for noticing it! |
||
|
||
include::open_index.asciidoc[] | ||
|
||
|
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.
nit: can you revert the addition of the static import? It affects also other methods that you are not changing and that causes some noise in the PR.
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.
Will do 👍