mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-25 15:47:23 -04:00
Accept more ingest simulate params as ints or strings (#66197)
_version, _if_seq_no and _if_primary_term params in the simulate pipeline API cannot be parsed correctly when the value is integer orstring type. This PR fix the bug and modify the test method to test it.
This commit is contained in:
parent
6dfdacdc8f
commit
f318f791b9
2 changed files with 24 additions and 14 deletions
|
@ -186,7 +186,13 @@ public class SimulatePipelineRequest extends ActionRequest implements ToXContent
|
|||
dataMap, Metadata.ROUTING.getFieldName());
|
||||
Long version = null;
|
||||
if (dataMap.containsKey(Metadata.VERSION.getFieldName())) {
|
||||
version = (Long) ConfigurationUtils.readObject(null, null, dataMap, Metadata.VERSION.getFieldName());
|
||||
String versionValue = ConfigurationUtils.readOptionalStringOrIntProperty(null, null,
|
||||
dataMap, Metadata.VERSION.getFieldName());
|
||||
if (versionValue != null) {
|
||||
version = Long.valueOf(versionValue);
|
||||
} else {
|
||||
throw new IllegalArgumentException("[_version] cannot be null");
|
||||
}
|
||||
}
|
||||
VersionType versionType = null;
|
||||
if (dataMap.containsKey(Metadata.VERSION_TYPE.getFieldName())) {
|
||||
|
@ -196,12 +202,24 @@ public class SimulatePipelineRequest extends ActionRequest implements ToXContent
|
|||
IngestDocument ingestDocument =
|
||||
new IngestDocument(index, id, routing, version, versionType, document);
|
||||
if (dataMap.containsKey(Metadata.IF_SEQ_NO.getFieldName())) {
|
||||
Long ifSeqNo = (Long) ConfigurationUtils.readObject(null, null, dataMap, Metadata.IF_SEQ_NO.getFieldName());
|
||||
String ifSeqNoValue = ConfigurationUtils.readOptionalStringOrIntProperty(null, null,
|
||||
dataMap, Metadata.IF_SEQ_NO.getFieldName());
|
||||
if (ifSeqNoValue != null) {
|
||||
Long ifSeqNo = Long.valueOf(ifSeqNoValue);
|
||||
ingestDocument.setFieldValue(Metadata.IF_SEQ_NO.getFieldName(), ifSeqNo);
|
||||
} else {
|
||||
throw new IllegalArgumentException("[_if_seq_no] cannot be null");
|
||||
}
|
||||
}
|
||||
if (dataMap.containsKey(Metadata.IF_PRIMARY_TERM.getFieldName())) {
|
||||
Long ifPrimaryTerm = (Long) ConfigurationUtils.readObject(null, null, dataMap, Metadata.IF_PRIMARY_TERM.getFieldName());
|
||||
String ifPrimaryTermValue = ConfigurationUtils.readOptionalStringOrIntProperty(null, null,
|
||||
dataMap, Metadata.IF_PRIMARY_TERM.getFieldName());
|
||||
if (ifPrimaryTermValue != null) {
|
||||
Long ifPrimaryTerm = Long.valueOf(ifPrimaryTermValue);
|
||||
ingestDocument.setFieldValue(Metadata.IF_PRIMARY_TERM.getFieldName(), ifPrimaryTerm);
|
||||
} else {
|
||||
throw new IllegalArgumentException("[_if_primary_term] cannot be null");
|
||||
}
|
||||
}
|
||||
ingestDocumentList.add(ingestDocument);
|
||||
}
|
||||
|
|
|
@ -124,20 +124,12 @@ public class SimulatePipelineRequestParsingTests extends ESTestCase {
|
|||
Map<String, Object> expectedDoc = new HashMap<>();
|
||||
List<IngestDocument.Metadata> fields = Arrays.asList(INDEX, ID, ROUTING, VERSION, VERSION_TYPE, IF_SEQ_NO, IF_PRIMARY_TERM);
|
||||
for(IngestDocument.Metadata field : fields) {
|
||||
if (field == VERSION) {
|
||||
Long value = randomLong();
|
||||
doc.put(field.getFieldName(), value);
|
||||
expectedDoc.put(field.getFieldName(), value);
|
||||
} else if (field == VERSION_TYPE) {
|
||||
if (field == VERSION_TYPE) {
|
||||
String value = VersionType.toString(
|
||||
randomFrom(VersionType.INTERNAL, VersionType.EXTERNAL, VersionType.EXTERNAL_GTE)
|
||||
);
|
||||
doc.put(field.getFieldName(), value);
|
||||
expectedDoc.put(field.getFieldName(), value);
|
||||
} else if (field == IF_SEQ_NO || field == IF_PRIMARY_TERM) {
|
||||
Long value = randomNonNegativeLong();
|
||||
doc.put(field.getFieldName(), value);
|
||||
expectedDoc.put(field.getFieldName(), value);
|
||||
} else {
|
||||
if (randomBoolean()) {
|
||||
String value = randomAlphaOfLengthBetween(1, 10);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue