-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Remove type filter from GetMappings API #47364
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
Changes from 10 commits
de8411a
e8e8ca9
97f5d3a
04341c8
4a053c3
b584dbe
de90da4
8edbc27
51382b9
5bfc3ba
292c045
b911f14
53f54e3
777c8eb
6227bcb
3ef6360
b392317
b03506c
e8bdb16
c8b64b3
645de20
0e5323d
80374dc
0e9a3dd
9f93b0e
8a90d94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
|
|
||
| import com.carrotsearch.hppc.cursors.ObjectObjectCursor; | ||
| import org.apache.lucene.util.CollectionUtil; | ||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.action.ActionResponse; | ||
| import org.elasticsearch.cluster.metadata.AliasMetaData; | ||
| import org.elasticsearch.cluster.metadata.MappingMetaData; | ||
|
|
@@ -33,6 +34,7 @@ | |
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.common.xcontent.XContentParser.Token; | ||
| import org.elasticsearch.index.mapper.MapperService; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
|
|
@@ -43,22 +45,20 @@ | |
| import java.util.Objects; | ||
|
|
||
| import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
| import static org.elasticsearch.rest.BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY; | ||
| import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER; | ||
|
|
||
| /** | ||
| * A response for a get index action. | ||
| */ | ||
| public class GetIndexResponse extends ActionResponse implements ToXContentObject { | ||
|
|
||
| private ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = ImmutableOpenMap.of(); | ||
| private ImmutableOpenMap<String, MappingMetaData> mappings = ImmutableOpenMap.of(); | ||
| private ImmutableOpenMap<String, List<AliasMetaData>> aliases = ImmutableOpenMap.of(); | ||
| private ImmutableOpenMap<String, Settings> settings = ImmutableOpenMap.of(); | ||
| private ImmutableOpenMap<String, Settings> defaultSettings = ImmutableOpenMap.of(); | ||
| private String[] indices; | ||
|
|
||
| public GetIndexResponse(String[] indices, | ||
| ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings, | ||
| ImmutableOpenMap<String, MappingMetaData> mappings, | ||
| ImmutableOpenMap<String, List<AliasMetaData>> aliases, | ||
| ImmutableOpenMap<String, Settings> settings, | ||
| ImmutableOpenMap<String, Settings> defaultSettings) { | ||
|
|
@@ -84,15 +84,24 @@ public GetIndexResponse(String[] indices, | |
| this.indices = in.readStringArray(); | ||
|
|
||
| int mappingsSize = in.readVInt(); | ||
| ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> mappingsMapBuilder = ImmutableOpenMap.builder(); | ||
| ImmutableOpenMap.Builder<String, MappingMetaData> mappingsMapBuilder = ImmutableOpenMap.builder(); | ||
| for (int i = 0; i < mappingsSize; i++) { | ||
| String key = in.readString(); | ||
| int valueSize = in.readVInt(); | ||
| ImmutableOpenMap.Builder<String, MappingMetaData> mappingEntryBuilder = ImmutableOpenMap.builder(); | ||
| for (int j = 0; j < valueSize; j++) { | ||
| mappingEntryBuilder.put(in.readString(), new MappingMetaData(in)); | ||
| if (in.getVersion().before(Version.V_8_0_0)) { | ||
| int valueSize = in.readVInt(); | ||
| assert valueSize == 1 : "Expected single mapping but got " + valueSize; | ||
| String type = in.readString(); | ||
| assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc] but got " + type; | ||
| mappingsMapBuilder.put(key, new MappingMetaData(in)); | ||
| } | ||
| else { | ||
| if (in.readBoolean()) { | ||
| mappingsMapBuilder.put(key, new MappingMetaData(in)); | ||
| } | ||
| else { | ||
| mappingsMapBuilder.put(key, null); | ||
| } | ||
|
Contributor
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. If
Contributor
Author
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. ++ |
||
| } | ||
| mappingsMapBuilder.put(key, mappingEntryBuilder.build()); | ||
| } | ||
| mappings = mappingsMapBuilder.build(); | ||
|
|
||
|
|
@@ -133,11 +142,11 @@ public String[] getIndices() { | |
| return indices(); | ||
| } | ||
|
|
||
| public ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings() { | ||
| public ImmutableOpenMap<String, MappingMetaData> mappings() { | ||
| return mappings; | ||
| } | ||
|
|
||
| public ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> getMappings() { | ||
| public ImmutableOpenMap<String, MappingMetaData> getMappings() { | ||
| return mappings(); | ||
| } | ||
|
|
||
|
|
@@ -197,12 +206,19 @@ public String getSetting(String index, String setting) { | |
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeStringArray(indices); | ||
| out.writeVInt(mappings.size()); | ||
| for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexEntry : mappings) { | ||
| for (ObjectObjectCursor<String, MappingMetaData> indexEntry : mappings) { | ||
| out.writeString(indexEntry.key); | ||
| out.writeVInt(indexEntry.value.size()); | ||
| for (ObjectObjectCursor<String, MappingMetaData> mappingEntry : indexEntry.value) { | ||
| out.writeString(mappingEntry.key); | ||
| mappingEntry.value.writeTo(out); | ||
| MappingMetaData mmd = indexEntry.value; | ||
| if (out.getVersion().before(Version.V_8_0_0)) { | ||
| out.writeVInt(1); | ||
| out.writeString(MapperService.SINGLE_MAPPING_NAME); | ||
| mmd.writeTo(out); | ||
| } | ||
| else { | ||
| out.writeBoolean(mmd != null); | ||
| if (mmd != null) { | ||
| mmd.writeTo(out); | ||
| } | ||
| } | ||
| } | ||
| out.writeVInt(aliases.size()); | ||
|
|
@@ -241,30 +257,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
| } | ||
| builder.endObject(); | ||
|
|
||
| ImmutableOpenMap<String, MappingMetaData> indexMappings = mappings.get(index); | ||
| boolean includeTypeName = params.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, | ||
| DEFAULT_INCLUDE_TYPE_NAME_POLICY); | ||
| if (includeTypeName) { | ||
| builder.startObject("mappings"); | ||
| if (indexMappings != null) { | ||
| for (final ObjectObjectCursor<String, MappingMetaData> typeEntry : indexMappings) { | ||
| builder.field(typeEntry.key); | ||
| builder.map(typeEntry.value.sourceAsMap()); | ||
| } | ||
| } | ||
| builder.endObject(); | ||
| } else { | ||
| MappingMetaData mappings = null; | ||
| for (final ObjectObjectCursor<String, MappingMetaData> typeEntry : indexMappings) { | ||
| assert mappings == null; | ||
| mappings = typeEntry.value; | ||
| } | ||
| if (mappings == null) { | ||
| // no mappings yet | ||
| builder.startObject("mappings").endObject(); | ||
| } else { | ||
| builder.field("mappings", mappings.sourceAsMap()); | ||
| } | ||
| MappingMetaData indexMappings = mappings.get(index); | ||
| if (indexMappings == null) { | ||
| builder.startObject("mappings").endObject(); | ||
| } | ||
| else { | ||
| builder.field("mappings", indexMappings.sourceAsMap()); | ||
| } | ||
|
|
||
| builder.startObject("settings"); | ||
|
|
@@ -298,25 +296,9 @@ private static List<AliasMetaData> parseAliases(XContentParser parser) throws IO | |
| return indexAliases; | ||
| } | ||
|
|
||
| private static ImmutableOpenMap<String, MappingMetaData> parseMappings(XContentParser parser) throws IOException { | ||
| ImmutableOpenMap.Builder<String, MappingMetaData> indexMappings = ImmutableOpenMap.builder(); | ||
| // We start at START_OBJECT since parseIndexEntry ensures that | ||
| while (parser.nextToken() != Token.END_OBJECT) { | ||
| ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation); | ||
| parser.nextToken(); | ||
| if (parser.currentToken() == Token.START_OBJECT) { | ||
| String mappingType = parser.currentName(); | ||
| indexMappings.put(mappingType, new MappingMetaData(mappingType, parser.map())); | ||
| } else if (parser.currentToken() == Token.START_ARRAY) { | ||
| parser.skipChildren(); | ||
| } | ||
| } | ||
| return indexMappings.build(); | ||
| } | ||
|
|
||
| private static IndexEntry parseIndexEntry(XContentParser parser) throws IOException { | ||
| List<AliasMetaData> indexAliases = null; | ||
| ImmutableOpenMap<String, MappingMetaData> indexMappings = null; | ||
| MappingMetaData indexMappings = null; | ||
| Settings indexSettings = null; | ||
| Settings indexDefaultSettings = null; | ||
| // We start at START_OBJECT since fromXContent ensures that | ||
|
|
@@ -329,7 +311,7 @@ private static IndexEntry parseIndexEntry(XContentParser parser) throws IOExcept | |
| indexAliases = parseAliases(parser); | ||
| break; | ||
| case "mappings": | ||
| indexMappings = parseMappings(parser); | ||
| indexMappings = new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, parser.map()); | ||
| break; | ||
| case "settings": | ||
| indexSettings = Settings.fromXContent(parser); | ||
|
|
@@ -350,10 +332,10 @@ private static IndexEntry parseIndexEntry(XContentParser parser) throws IOExcept | |
| // This is just an internal container to make stuff easier for returning | ||
| private static class IndexEntry { | ||
| List<AliasMetaData> indexAliases = new ArrayList<>(); | ||
| ImmutableOpenMap<String, MappingMetaData> indexMappings = ImmutableOpenMap.of(); | ||
| MappingMetaData indexMappings = null; | ||
| Settings indexSettings = Settings.EMPTY; | ||
| Settings indexDefaultSettings = Settings.EMPTY; | ||
| IndexEntry(List<AliasMetaData> indexAliases, ImmutableOpenMap<String, MappingMetaData> indexMappings, | ||
| IndexEntry(List<AliasMetaData> indexAliases, MappingMetaData indexMappings, | ||
| Settings indexSettings, Settings indexDefaultSettings) { | ||
| if (indexAliases != null) this.indexAliases = indexAliases; | ||
| if (indexMappings != null) this.indexMappings = indexMappings; | ||
|
|
@@ -364,7 +346,7 @@ private static class IndexEntry { | |
|
|
||
| public static GetIndexResponse fromXContent(XContentParser parser) throws IOException { | ||
| ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliases = ImmutableOpenMap.builder(); | ||
| ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> mappings = ImmutableOpenMap.builder(); | ||
| ImmutableOpenMap.Builder<String, MappingMetaData> mappings = ImmutableOpenMap.builder(); | ||
| ImmutableOpenMap.Builder<String, Settings> settings = ImmutableOpenMap.builder(); | ||
| ImmutableOpenMap.Builder<String, Settings> defaultSettings = ImmutableOpenMap.builder(); | ||
| List<String> indices = new ArrayList<>(); | ||
|
|
||
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.
Small comment, I think we always put
elseon the same line as the previous closing brace:} else {. This applies to a few places in the PR.