-
Notifications
You must be signed in to change notification settings - Fork 25.3k
[Rest Compatible Api] include_type_name parameter #70966
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 all commits
ddf6152
51ef24a
1bbc802
9592c74
b6abb3f
4ead400
10dde5e
adead4d
c8f7413
57e63fc
539b421
27c80c0
2ea3520
4c707bb
4dcd63c
39d7633
b384677
0cc4427
64c7e90
8da814d
734e8b8
276fc88
07db905
bc0e5df
0835b80
22c5175
9e1644f
2049d0e
e7298ee
a1ea94c
0426b02
5f1b950
95bba64
176da8d
2199c3e
8c57e85
53f7556
a571491
6a5708a
75edcd3
b00c1cb
5f2620b
063d043
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.master.AcknowledgedRequest; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.RestApiVersion; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
|
@@ -37,7 +38,7 @@ | |
*/ | ||
public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implements IndicesRequest { | ||
|
||
private static final ObjectParser<RolloverRequest, Void> PARSER = new ObjectParser<>("rollover"); | ||
private static final ObjectParser<RolloverRequest, Boolean> PARSER = new ObjectParser<>("rollover"); | ||
private static final ObjectParser<Map<String, Condition<?>>, Void> CONDITION_PARSER = new ObjectParser<>("conditions"); | ||
|
||
private static final ParseField CONDITIONS = new ParseField("conditions"); | ||
|
@@ -67,14 +68,32 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem | |
CONDITIONS, ObjectParser.ValueType.OBJECT); | ||
PARSER.declareField((parser, request, context) -> request.createIndexRequest.settings(parser.map()), | ||
CreateIndexRequest.SETTINGS, ObjectParser.ValueType.OBJECT); | ||
PARSER.declareField((parser, request, includeTypeName) -> { | ||
if (includeTypeName) { | ||
//expecting one type only | ||
for (Map.Entry<String, Object> mappingsEntry : parser.map().entrySet()) { | ||
request.createIndexRequest.mapping((Map<String, Object>) mappingsEntry.getValue()); | ||
} | ||
} else { | ||
// a type is not included, add a dummy _doc type | ||
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. Rather than doing a check here I think we should just wrap it with 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 basically tried to retrofit the change from 7.x branch. |
||
Map<String, Object> mappings = parser.map(); | ||
if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, mappings)) { | ||
throw new IllegalArgumentException("The mapping definition cannot be nested under a type " + | ||
"[" + MapperService.SINGLE_MAPPING_NAME + "] unless include_type_name is set to true."); | ||
} | ||
request.createIndexRequest.mapping(mappings); | ||
} | ||
}, CreateIndexRequest.MAPPINGS.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7)), ObjectParser.ValueType.OBJECT); | ||
PARSER.declareField((parser, request, context) -> { | ||
// a type is not included, add a dummy _doc type | ||
Map<String, Object> mappings = parser.map(); | ||
if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, mappings)) { | ||
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. And I think we should remove this check as well - really to check properly we need to parse the mappings, and if they've included a type this will get caught further along. 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. Building on what I said in a previous comment -- these were added in #38270 to catch an important case that mapping parsing wasn't able to detect. But there have been substantial improvements/ refactors to mapping parsing since then, so we may be able to remove these checks and have the tests still pass. To keep this PR a straightforward 'restore' of old logic, maybe we could look into removing these checks in a follow-up. 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. Assuming I am reading the code correctly, this check is only applied when REST API compatibility for v7 is applied (i.e. CreateIndexRequest.MAPPINGS.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7)), but the check is now no longer for v8+. I have a minor preference to keep the check when compatibility is in use, else remove the check in a follow up PR if it also requires changes to the test. 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 see, in that case I will keep the check for both 7.x and 8.x fields. 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. ++ let's keep it for now and I can look at removing it in a followup |
||
|
||
throw new IllegalArgumentException("The mapping definition cannot be nested under a type"); | ||
} | ||
request.createIndexRequest.mapping(mappings); | ||
}, CreateIndexRequest.MAPPINGS, ObjectParser.ValueType.OBJECT); | ||
}, CreateIndexRequest.MAPPINGS.forRestApiVersion(RestApiVersion.onOrAfter(RestApiVersion.V_8)), ObjectParser.ValueType.OBJECT); | ||
|
||
PARSER.declareField((parser, request, context) -> request.createIndexRequest.aliases(parser.map()), | ||
CreateIndexRequest.ALIASES, ObjectParser.ValueType.OBJECT); | ||
} | ||
|
@@ -238,7 +257,7 @@ public CreateIndexRequest getCreateIndexRequest() { | |
} | ||
|
||
// param isTypeIncluded decides how mappings should be parsed from XContent | ||
public void fromXContent(XContentParser parser) throws IOException { | ||
PARSER.parse(parser, this, null); | ||
public void fromXContent(boolean isTypeIncluded, XContentParser parser) throws IOException { | ||
PARSER.parse(parser, this, isTypeIncluded); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,10 @@ | |
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import static org.elasticsearch.common.RestApiVersion.V_8; | ||
import static org.elasticsearch.common.RestApiVersion.onOrAfter; | ||
|
||
|
||
public class IndexTemplateMetadata extends AbstractDiffable<IndexTemplateMetadata> { | ||
|
||
private final String name; | ||
|
@@ -378,7 +382,9 @@ private static void toInnerXContent(IndexTemplateMetadata indexTemplateMetadata, | |
indexTemplateMetadata.settings().toXContent(builder, params); | ||
builder.endObject(); | ||
|
||
includeTypeName &= (params.paramAsBoolean("reduce_mappings", false) == false); | ||
if(builder.getRestApiVersion().matches(onOrAfter(V_8))) { | ||
includeTypeName &= (params.paramAsBoolean("reduce_mappings", false) == false); | ||
} | ||
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. @romseygeek do you think there need to be a special handing for this in V7 mode? 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 this |
||
|
||
CompressedXContent m = indexTemplateMetadata.mappings(); | ||
if (m != null) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.