Skip to content

Commit

Permalink
[Remove] Type metadata from ingest documents (#2491)
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Singh <surajrider@gmail.com>
  • Loading branch information
dreamer-89 authored Mar 17, 2022
1 parent 3675400 commit f34a753
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void testConvertScalarToList() throws Exception {
public void testAppendMetadataExceptVersion() throws Exception {
// here any metadata field value becomes a list, which won't make sense in most of the cases,
// but support for append is streamlined like for set so we test it
Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.TYPE, Metadata.ID, Metadata.ROUTING);
Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.ID, Metadata.ROUTING);
List<String> values = new ArrayList<>();
Processor appendProcessor;
if (randomBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testSetExistingNullFieldWithOverrideDisabled() throws Exception {
}

public void testSetMetadataExceptVersion() throws Exception {
Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.TYPE, Metadata.ID, Metadata.ROUTING);
Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.ID, Metadata.ROUTING);
Processor processor = createSetProcessor(randomMetadata.getFieldName(), "_value", true, false);
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
processor.execute(ingestDocument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,6 @@ private static List<IngestDocument> parseDocs(Map<String, Object> config) {
Map<String, Object> dataMap = (Map<String, Object>) object;
Map<String, Object> document = ConfigurationUtils.readMap(null, null, dataMap, Fields.SOURCE);
String index = ConfigurationUtils.readStringOrIntProperty(null, null, dataMap, Metadata.INDEX.getFieldName(), "_index");
if (dataMap.containsKey(Metadata.TYPE.getFieldName())) {
deprecationLogger.deprecate(
"simulate_pipeline_with_types",
"[types removal] specifying _type in pipeline simulation requests is deprecated"
);
}
String id = ConfigurationUtils.readStringOrIntProperty(null, null, dataMap, Metadata.ID.getFieldName(), "_id");
String routing = ConfigurationUtils.readOptionalStringOrIntProperty(null, null, dataMap, Metadata.ROUTING.getFieldName());
Long version = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.opensearch.index.mapper.IndexFieldMapper;
import org.opensearch.index.mapper.RoutingFieldMapper;
import org.opensearch.index.mapper.SourceFieldMapper;
import org.opensearch.index.mapper.TypeFieldMapper;
import org.opensearch.index.mapper.VersionFieldMapper;
import org.opensearch.script.TemplateScript;

Expand Down Expand Up @@ -846,7 +845,6 @@ public String toString() {

public enum Metadata {
INDEX(IndexFieldMapper.NAME),
TYPE(TypeFieldMapper.NAME),
ID(IdFieldMapper.NAME),
ROUTING(RoutingFieldMapper.NAME),
VERSION(VersionFieldMapper.NAME),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import static org.opensearch.ingest.IngestDocument.Metadata.ID;
import static org.opensearch.ingest.IngestDocument.Metadata.INDEX;
import static org.opensearch.ingest.IngestDocument.Metadata.ROUTING;
import static org.opensearch.ingest.IngestDocument.Metadata.TYPE;
import static org.opensearch.ingest.IngestDocument.Metadata.VERSION;
import static org.opensearch.ingest.IngestDocument.Metadata.VERSION_TYPE;
import static org.opensearch.ingest.IngestDocument.Metadata.IF_SEQ_NO;
Expand Down Expand Up @@ -132,15 +131,7 @@ public void testParseUsingPipelineStore(boolean useExplicitType) throws Exceptio
assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(1));
}

public void testParseWithProvidedPipelineNoType() throws Exception {
innerTestParseWithProvidedPipeline(false);
}

public void testParseWithProvidedPipelineWithType() throws Exception {
innerTestParseWithProvidedPipeline(true);
}

private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws Exception {
public void innerTestParseWithProvidedPipeline() throws Exception {
int numDocs = randomIntBetween(1, 10);

Map<String, Object> requestContent = new HashMap<>();
Expand All @@ -150,16 +141,7 @@ private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws
for (int i = 0; i < numDocs; i++) {
Map<String, Object> doc = new HashMap<>();
Map<String, Object> expectedDoc = new HashMap<>();
List<IngestDocument.Metadata> fields = Arrays.asList(
INDEX,
TYPE,
ID,
ROUTING,
VERSION,
VERSION_TYPE,
IF_SEQ_NO,
IF_PRIMARY_TERM
);
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();
Expand All @@ -173,14 +155,6 @@ private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws
Long value = randomNonNegativeLong();
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else if (field == TYPE) {
if (useExplicitType) {
String value = randomAlphaOfLengthBetween(1, 10);
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else {
expectedDoc.put(field.getFieldName(), "_doc");
}
} else {
if (randomBoolean()) {
String value = randomAlphaOfLengthBetween(1, 10);
Expand Down Expand Up @@ -249,9 +223,6 @@ private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws
assertThat(actualRequest.getPipeline().getId(), equalTo(SIMULATED_PIPELINE_ID));
assertThat(actualRequest.getPipeline().getDescription(), nullValue());
assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(numProcessors));
if (useExplicitType) {
assertWarnings("[types removal] specifying _type in pipeline simulation requests is deprecated");
}
}

public void testNullPipelineId() {
Expand Down

0 comments on commit f34a753

Please sign in to comment.