-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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 get mappings support to high-level rest client #30889
Changes from 11 commits
95a8a67
31ac916
d1921d8
7414c06
dd9feb1
1b6fd2f
9108459
7ffcdf7
3aa0094
ad03b58
da13f19
7a137e1
1fc8121
19f9386
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 |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
import org.elasticsearch.action.admin.indices.flush.FlushRequest; | ||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest; | ||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest; | ||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; | ||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; | ||
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; | ||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; | ||
|
@@ -191,6 +192,19 @@ static Request putMapping(PutMappingRequest putMappingRequest) throws IOExceptio | |
return request; | ||
} | ||
|
||
static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOException { | ||
String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices(); | ||
String[] types = getMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.types(); | ||
|
||
Request request = new Request(HttpGet.METHOD_NAME, endpoint(indices, "_mapping", types)); | ||
|
||
Params parameters = new Params(request); | ||
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout()); | ||
parameters.withIndicesOptions(getMappingsRequest.indicesOptions()); | ||
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 we need to set the local flag also |
||
parameters.withLocal(getMappingsRequest.local()); | ||
return request; | ||
} | ||
|
||
static Request refresh(RefreshRequest refreshRequest) { | ||
String[] indices = refreshRequest.indices() == null ? Strings.EMPTY_ARRAY : refreshRequest.indices(); | ||
Request request = new Request(HttpPost.METHOD_NAME, endpoint(indices, "_refresh")); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
import org.elasticsearch.action.admin.indices.flush.FlushRequest; | ||
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest; | ||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest; | ||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; | ||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; | ||
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; | ||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; | ||
|
@@ -399,6 +400,47 @@ public void testPutMapping() throws IOException { | |
assertToXContentBody(putMappingRequest, request.getEntity()); | ||
} | ||
|
||
public void testGetMapping() throws IOException { | ||
GetMappingsRequest getMappingRequest = new GetMappingsRequest(); | ||
|
||
String[] indices = Strings.EMPTY_ARRAY; | ||
if (randomBoolean()) { | ||
indices = randomIndicesNames(0, 5); | ||
getMappingRequest.indices(indices); | ||
} else if (randomBoolean()) { | ||
getMappingRequest.indices((String[]) null); | ||
} | ||
|
||
String type = null; | ||
if (randomBoolean()) { | ||
type = randomAlphaOfLengthBetween(3, 10); | ||
getMappingRequest.types(type); | ||
} else if (randomBoolean()) { | ||
getMappingRequest.types((String[]) null); | ||
} | ||
|
||
Map<String, String> expectedParams = new HashMap<>(); | ||
|
||
setRandomIndicesOptions(getMappingRequest::indicesOptions, getMappingRequest::indicesOptions, expectedParams); | ||
setRandomMasterTimeout(getMappingRequest, expectedParams); | ||
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. add a test around the local flag? 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. Yep, was added |
||
setRandomLocal(getMappingRequest, expectedParams); | ||
|
||
Request request = RequestConverters.getMappings(getMappingRequest); | ||
StringJoiner endpoint = new StringJoiner("/", "/", ""); | ||
String index = String.join(",", indices); | ||
if (Strings.hasLength(index)) { | ||
endpoint.add(index); | ||
} | ||
endpoint.add("_mapping"); | ||
if (type != null) { | ||
endpoint.add(type); | ||
} | ||
assertThat(endpoint.toString(), equalTo(request.getEndpoint())); | ||
|
||
assertThat(expectedParams, equalTo(request.getParameters())); | ||
assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); | ||
} | ||
|
||
public void testDeleteIndex() { | ||
String[] indices = randomIndicesNames(0, 5); | ||
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indices); | ||
|
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.
I don't see this being set in the corresponding REST action, would you mind opening another PR to fix that? It needs to be added to the SPEC too.