-
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
Support both typed and typeless 'get mapping' requests in the HLRC. #37796
Changes from 1 commit
acf286f
4e05f79
28f425d
05c870d
06805cc
3b02709
bd476a0
811c473
b2a19e4
705880d
e122a1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,6 @@ | |
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest; | ||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest; | ||
import org.elasticsearch.client.indices.GetFieldMappingsRequest; | ||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; | ||
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; | ||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; | ||
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest; | ||
|
@@ -49,6 +48,7 @@ | |
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; | ||
import org.elasticsearch.client.indices.FreezeIndexRequest; | ||
import org.elasticsearch.client.indices.GetIndexTemplatesRequest; | ||
import org.elasticsearch.client.indices.GetMappingsRequest; | ||
import org.elasticsearch.client.indices.IndexTemplatesExistRequest; | ||
import org.elasticsearch.client.indices.PutMappingRequest; | ||
import org.elasticsearch.client.indices.UnfreezeIndexRequest; | ||
|
@@ -151,7 +151,20 @@ static Request putMapping(org.elasticsearch.action.admin.indices.mapping.put.Put | |
return request; | ||
} | ||
|
||
static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOException { | ||
static Request getMappings(GetMappingsRequest getMappingsRequest) { | ||
String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices(); | ||
|
||
Request request = new Request(HttpGet.METHOD_NAME, RequestConverters.endpoint(indices, "_mapping")); | ||
|
||
RequestConverters.Params parameters = new RequestConverters.Params(request); | ||
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout()); | ||
parameters.withIndicesOptions(getMappingsRequest.indicesOptions()); | ||
parameters.withLocal(getMappingsRequest.local()); | ||
|
||
return request; | ||
} | ||
|
||
static Request getMappings(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest) { | ||
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. maybe add @deprecated even if we only use this internally. It makes it more obvious and serves as a grep-able reminder that we can remove this in 8.0. 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. 👍 |
||
String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices(); | ||
String[] types = getMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.types(); | ||
|
||
|
@@ -161,6 +174,7 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOExcep | |
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout()); | ||
parameters.withIndicesOptions(getMappingsRequest.indicesOptions()); | ||
parameters.withLocal(getMappingsRequest.local()); | ||
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true"); | ||
|
||
return request; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.indices; | ||
|
||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.client.TimedRequest; | ||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.common.Strings; | ||
|
||
public class GetMappingsRequest extends TimedRequest implements Validatable { | ||
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. since TimedRequest implement Validatable, we don't need it here again. 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. 👍 |
||
|
||
private boolean local = false; | ||
private boolean includeDefaults = false; | ||
private String[] indices = Strings.EMPTY_ARRAY; | ||
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen(); | ||
|
||
/** | ||
* Indicates whether the receiving node should operate based on local index information or | ||
* forward requests, where needed, to other nodes. If running locally, request will not | ||
* raise errors if local index information is missing. | ||
*/ | ||
public GetMappingsRequest local(boolean local) { | ||
this.local = local; | ||
return this; | ||
} | ||
|
||
public boolean local() { | ||
return local; | ||
} | ||
|
||
public GetMappingsRequest indices(String... indices) { | ||
this.indices = indices; | ||
return this; | ||
} | ||
|
||
public GetMappingsRequest indicesOptions(IndicesOptions indicesOptions) { | ||
this.indicesOptions = indicesOptions; | ||
return this; | ||
} | ||
|
||
public String[] indices() { | ||
return indices; | ||
} | ||
|
||
public IndicesOptions indicesOptions() { | ||
return indicesOptions; | ||
} | ||
|
||
public boolean includeDefaults() { | ||
return includeDefaults; | ||
} | ||
|
||
/** Indicates whether default mapping settings should be returned */ | ||
public GetMappingsRequest includeDefaults(boolean includeDefaults) { | ||
this.includeDefaults = includeDefaults; | ||
return this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.indices; | ||
|
||
import org.elasticsearch.cluster.metadata.MappingMetaData; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.XContentParserUtils; | ||
import org.elasticsearch.index.mapper.MapperService; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class GetMappingsResponse { | ||
|
||
static final ParseField MAPPINGS = new ParseField("mappings"); | ||
|
||
private Map<String, MappingMetaData> mappings; | ||
|
||
public GetMappingsResponse(Map<String, MappingMetaData> mappings) { | ||
this.mappings = mappings; | ||
} | ||
|
||
public Map<String, MappingMetaData> mappings() { | ||
return mappings; | ||
} | ||
|
||
public static GetMappingsResponse fromXContent(XContentParser parser) throws IOException { | ||
if (parser.currentToken() == null) { | ||
parser.nextToken(); | ||
} | ||
|
||
XContentParserUtils.ensureExpectedToken(parser.currentToken(), | ||
XContentParser.Token.START_OBJECT, | ||
parser::getTokenLocation); | ||
|
||
Map<String, Object> parts = parser.map(); | ||
|
||
Map<String, MappingMetaData> mappings = new HashMap<>(); | ||
for (Map.Entry<String, Object> entry : parts.entrySet()) { | ||
String indexName = entry.getKey(); | ||
assert entry.getValue() instanceof Map : "expected a map as type mapping, but got: " + entry.getValue().getClass(); | ||
|
||
@SuppressWarnings("unchecked") | ||
final Map<String, Object> fieldMappings = (Map<String, Object>) ((Map<String, ?>) entry.getValue()) | ||
.get(MAPPINGS.getPreferredName()); | ||
|
||
mappings.put(indexName, new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, fieldMappings)); | ||
} | ||
|
||
return new GetMappingsResponse(mappings); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
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. Although implementing equals/hashcode never hurts I think, it puts some additional burden on us in testing and maintaining it. I think I opted for starting with not implementing it as long as we don't need it, but I'd be interested in your opinion on this. 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 added these methods to support the serialization/ deserialization tests in |
||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
GetMappingsResponse that = (GetMappingsResponse) o; | ||
return Objects.equals(mappings, that.mappings); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(mappings); | ||
} | ||
} |
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: s/an/a
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.
Oops, thanks!