use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class ConvertProcessorTests method testAutoConvertMatchFloat.
public void testAutoConvertMatchFloat() throws Exception {
float randomFloat = randomFloat();
String randomString = Float.toString(randomFloat);
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", randomString));
Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO, false);
processor.execute(ingestDocument);
Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
assertThat(convertedValue, equalTo(randomFloat));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class ConvertProcessorTests method testConvertStringList.
public void testConvertStringList() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
int numItems = randomIntBetween(1, 10);
List<Object> fieldValue = new ArrayList<>();
List<String> expectedList = new ArrayList<>();
for (int j = 0; j < numItems; j++) {
Object randomValue;
String randomValueString;
switch(randomIntBetween(0, 2)) {
case 0:
float randomFloat = randomFloat();
randomValue = randomFloat;
randomValueString = Float.toString(randomFloat);
break;
case 1:
int randomInt = randomInt();
randomValue = randomInt;
randomValueString = Integer.toString(randomInt);
break;
case 2:
boolean randomBoolean = randomBoolean();
randomValue = randomBoolean;
randomValueString = Boolean.toString(randomBoolean);
break;
default:
throw new UnsupportedOperationException();
}
fieldValue.add(randomValue);
expectedList.add(randomValueString);
}
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.STRING, false);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class ConvertProcessorTests method testConvertFloatList.
public void testConvertFloatList() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
int numItems = randomIntBetween(1, 10);
List<String> fieldValue = new ArrayList<>();
List<Float> expectedList = new ArrayList<>();
for (int j = 0; j < numItems; j++) {
float randomFloat = randomFloat();
fieldValue.add(Float.toString(randomFloat));
expectedList.add(randomFloat);
}
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.FLOAT, false);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class ConvertProcessorTests method testAutoConvertMatchBoolean.
public void testAutoConvertMatchBoolean() throws Exception {
boolean randomBoolean = randomBoolean();
String booleanString = Boolean.toString(randomBoolean);
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", booleanString));
Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO, false);
processor.execute(ingestDocument);
Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
assertThat(convertedValue, equalTo(randomBoolean));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class ConvertProcessorTests method testConvertIntList.
public void testConvertIntList() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
int numItems = randomIntBetween(1, 10);
List<String> fieldValue = new ArrayList<>();
List<Integer> expectedList = new ArrayList<>();
for (int j = 0; j < numItems; j++) {
int randomInt = randomInt();
fieldValue.add(Integer.toString(randomInt));
expectedList.add(randomInt);
}
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.INTEGER, false);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
}
Aggregations