Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
de8411a
Remove types from GetMappings request and response
romseygeek Oct 1, 2019
e8e8ca9
test failures
romseygeek Oct 2, 2019
97f5d3a
Merge remote-tracking branch 'origin/master' into types-removal/getma…
romseygeek Oct 2, 2019
04341c8
null check
romseygeek Oct 2, 2019
4a053c3
null checks - need to work out what to do here
romseygeek Oct 3, 2019
b584dbe
Deal correctly with null mappings
romseygeek Oct 3, 2019
de90da4
Merge remote-tracking branch 'origin/master' into types-removal/getma…
romseygeek Oct 3, 2019
8edbc27
imports
romseygeek Oct 3, 2019
51382b9
Fix ml mapping merger
romseygeek Oct 4, 2019
5bfc3ba
tests
romseygeek Oct 4, 2019
292c045
GetMappingsResponse and GetIndexResponse don't return types in mappings
romseygeek Oct 13, 2019
b911f14
Merge branch 'types-removal/get-mappings-response' into types-removal…
romseygeek Oct 13, 2019
53f54e3
serialization
romseygeek Oct 14, 2019
777c8eb
Use proper response tests
romseygeek Oct 14, 2019
6227bcb
Merge remote-tracking branch 'origin/master' into types-removal/getma…
romseygeek Oct 14, 2019
3ef6360
precommit, serialization
romseygeek Oct 14, 2019
b392317
Merge remote-tracking branch 'origin/master' into types-removal/getma…
romseygeek Oct 16, 2019
b03506c
feedback
romseygeek Oct 16, 2019
e8bdb16
compilation
romseygeek Oct 16, 2019
c8b64b3
still need to deal with nulls in certain cases
romseygeek Oct 16, 2019
645de20
test failures
romseygeek Oct 16, 2019
0e5323d
feedback
romseygeek Oct 17, 2019
80374dc
Merge branch 'master' into types-removal/getmappings
elasticmachine Oct 17, 2019
0e9a3dd
Merge branch 'master' into types-removal/getmappings
elasticmachine Oct 20, 2019
9f93b0e
BWC
romseygeek Oct 21, 2019
8a90d94
Merge remote-tracking branch 'origin/master' into types-removal/getma…
romseygeek Oct 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) {
@Deprecated
static Request getMappings(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest) {
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, RequestConverters.endpoint(indices, "_mapping", types));
Request request = new Request(HttpGet.METHOD_NAME, RequestConverters.endpoint(indices, "_mapping"));

RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public void testGetIndexWithTypes() throws IOException {
assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS));
assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS));
assertNotNull(getIndexResponse.getMappings().get(indexName));
MappingMetaData mappingMetaData = getIndexResponse.getMappings().get(indexName).get("_doc");
MappingMetaData mappingMetaData = getIndexResponse.getMappings().get(indexName);
assertNotNull(mappingMetaData);
assertEquals("_doc", mappingMetaData.type());
assertEquals("{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}", mappingMetaData.source().string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,50 +288,6 @@ public void testGetMapping() {
Assert.assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod()));
}

public void testGetMappingWithTypes() {
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingRequest =
new org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest();

String[] indices = Strings.EMPTY_ARRAY;
if (randomBoolean()) {
indices = RequestConvertersTests.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<>();

RequestConvertersTests.setRandomIndicesOptions(getMappingRequest::indicesOptions,
getMappingRequest::indicesOptions, expectedParams);
RequestConvertersTests.setRandomMasterTimeout(getMappingRequest, expectedParams);
RequestConvertersTests.setRandomLocal(getMappingRequest::local, expectedParams);
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");

Request request = IndicesRequestConverters.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);
}
Assert.assertThat(endpoint.toString(), equalTo(request.getEndpoint()));

Assert.assertThat(expectedParams, equalTo(request.getParameters()));
Assert.assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod()));
}

public void testGetFieldMapping() {
GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,14 @@ private static Map<String, Object> randomFieldMapping() {

private static void toXContent(GetIndexResponse response, XContentBuilder builder) throws IOException {
// first we need to repackage from GetIndexResponse to org.elasticsearch.action.admin.indices.get.GetIndexResponse
ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> allMappings = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<String, MappingMetaData> allMappings = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliases = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<String, Settings> settings = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<String, Settings> defaultSettings = ImmutableOpenMap.builder();

Map<String, MappingMetaData> indexMappings = response.getMappings();
for (String index : response.getIndices()) {
MappingMetaData mmd = indexMappings.get(index);
ImmutableOpenMap.Builder<String, MappingMetaData> typedMappings = ImmutableOpenMap.builder();
if (mmd != null) {
typedMappings.put(MapperService.SINGLE_MAPPING_NAME, mmd);
}
allMappings.put(index, typedMappings.build());
allMappings.put(index, indexMappings.get(index));
aliases.put(index, response.getAliases().get(index));
settings.put(index, response.getSettings().get(index));
defaultSettings.put(index, response.getDefaultSettings().get(index));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ private static Map<String, Object> randomFieldMapping() {
private static void toXContent(GetMappingsResponse response, XContentBuilder builder) throws IOException {
Params params = new ToXContent.MapParams(
Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "false"));
ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> allMappings = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<String, MappingMetaData> allMappings = ImmutableOpenMap.builder();

for (Map.Entry<String, MappingMetaData> indexEntry : response.mappings().entrySet()) {
ImmutableOpenMap.Builder<String, MappingMetaData> mappings = ImmutableOpenMap.builder();
mappings.put(MapperService.SINGLE_MAPPING_NAME, indexEntry.getValue());
allMappings.put(indexEntry.getKey(), mappings.build());
allMappings.put(indexEntry.getKey(), indexEntry.getValue());
}

org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse serverResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ private void assertSizeMappingEnabled(String index, String type, boolean enabled
String errMsg = String.format(Locale.ROOT,
"Expected size field mapping to be " + (enabled ? "enabled" : "disabled") + " for %s/%s", index, type);
GetMappingsResponse getMappingsResponse =
client().admin().indices().prepareGetMappings(index).addTypes(type).get();
Map<String, Object> mappingSource = getMappingsResponse.getMappings().get(index).get(type).getSourceAsMap();
client().admin().indices().prepareGetMappings(index).get();
Map<String, Object> mappingSource = getMappingsResponse.getMappings().get(index).getSourceAsMap();
assertThat(errMsg, mappingSource, hasKey("_size"));
String sizeAsString = mappingSource.get("_size").toString();
assertThat(sizeAsString, is(notNullValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -84,15 +84,16 @@ 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, mappingEntryBuilder.build());
mappingsMapBuilder.put(key, new MappingMetaData(in));
}
mappings = mappingsMapBuilder.build();

Expand Down Expand Up @@ -133,11 +134,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();
}

Expand Down Expand Up @@ -197,12 +198,20 @@ 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)) {
if (mmd != null) {
out.writeVInt(1);
out.writeString(MapperService.SINGLE_MAPPING_NAME);
}
else {
out.writeVInt(0);
}
}
if (mmd != null) {
mmd.writeTo(out);
}
}
out.writeVInt(aliases.size());
Expand Down Expand Up @@ -241,30 +250,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");
Expand Down Expand Up @@ -298,25 +289,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
Expand All @@ -329,7 +304,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);
Expand All @@ -350,10 +325,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;
Expand All @@ -364,7 +339,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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected GetIndexResponse read(StreamInput in) throws IOException {
@Override
protected void doMasterOperation(final GetIndexRequest request, String[] concreteIndices, final ClusterState state,
final ActionListener<GetIndexResponse> listener) {
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsResult = ImmutableOpenMap.of();
ImmutableOpenMap<String, MappingMetaData> mappingsResult = ImmutableOpenMap.of();
ImmutableOpenMap<String, List<AliasMetaData>> aliasesResult = ImmutableOpenMap.of();
ImmutableOpenMap<String, Settings> settings = ImmutableOpenMap.of();
ImmutableOpenMap<String, Settings> defaultSettings = ImmutableOpenMap.of();
Expand All @@ -99,8 +99,7 @@ protected void doMasterOperation(final GetIndexRequest request, String[] concret
case MAPPINGS:
if (!doneMappings) {
try {
mappingsResult = state.metaData().findMappings(concreteIndices, request.types(),
indicesService.getFieldFilter());
mappingsResult = state.metaData().findMappings(concreteIndices, indicesService.getFieldFilter());
doneMappings = true;
} catch (IOException e) {
listener.onFailure(e);
Expand Down
Loading