diff --git a/src/Plugin/search_api/processor/AggregatedFields.php b/src/Plugin/search_api/processor/AggregatedFields.php
index 05c2938..4b2d4c4 100644
--- a/src/Plugin/search_api/processor/AggregatedFields.php
+++ b/src/Plugin/search_api/processor/AggregatedFields.php
@@ -102,7 +102,11 @@ public function addFieldValues(ItemInterface $item) {
           break;
       }
 
-      $aggregated_field->setValues($values);
+      // Do not use setValues(), since that doesn't preprocess the values
+      // according to their data type.
+      foreach ($values as $value) {
+        $aggregated_field->addValue($value);
+      }
     }
   }
 
diff --git a/tests/src/Unit/Plugin/Processor/AggregatedFieldsTest.php b/tests/src/Unit/Plugin/Processor/AggregatedFieldsTest.php
index 9b0b52e..37bea7d 100644
--- a/tests/src/Unit/Plugin/Processor/AggregatedFieldsTest.php
+++ b/tests/src/Unit/Plugin/Processor/AggregatedFieldsTest.php
@@ -44,6 +44,13 @@ class AggregatedFieldsTest extends UnitTestCase {
   protected $fieldId = 'aggregated_field';
 
   /**
+   * The callback with which text values should be preprocessed.
+   *
+   * @var callable
+   */
+  protected $valueCallback;
+
+  /**
    * Creates a new processor object for use in the tests.
    */
   protected function setUp() {
@@ -76,7 +83,7 @@ protected function setUp() {
           'property_path' => 'foobaz:bla',
         ),
         'aggregated_field' => array(
-          'type' => 'string',
+          'type' => 'text',
           'property_path' => 'aggregated_field',
         ),
       ),
@@ -84,6 +91,28 @@ protected function setUp() {
     $this->processor = new AggregatedFields(array('index' => $this->index), 'aggregated_field', array());
     $this->index->addProcessor($this->processor);
     $this->setUpMockContainer();
+
+    // We want to check correct data type handling, so we need a somewhat more
+    // complex mock-up for the datatype plugin handler.
+    /** @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\search_api\DataType\DataTypePluginManager $data_type_manager */
+    $data_type_manager = $this->container->get('plugin.manager.search_api.data_type');
+    $data_type_manager->method('hasDefinition')
+      ->willReturn(TRUE);
+    $this->valueCallback = function ($value) {
+      if (is_numeric($value)) {
+        return $value + 1;
+      }
+      else {
+        return '*' . $value;
+      }
+    };
+    $data_type = $this->getMock('Drupal\search_api\DataType\DataTypeInterface');
+    $data_type->method('getValue')
+      ->willReturnCallback($this->valueCallback);
+    $data_type_manager->method('createInstance')
+      ->willReturnMap(array(
+        array('text', array(), $data_type),
+      ));
   }
 
   /**
@@ -130,12 +159,14 @@ public function testAggregation($type, $expected, $integer = FALSE) {
     foreach (array('entity:test1', 'entity:test2') as $datasource_id) {
       $this->itemIds[$i++] = $item_id = Utility::createCombinedId($datasource_id, '1:en');
       $item = Utility::createItem($this->index, $item_id);
-      foreach ($this->index->getFields() as $field_id => $field) {
-        $field = clone $field;
-        if (!empty($field_values[$field_id])) {
-          $field->setValues($field_values[$field_id]);
+      foreach (array(NULL, $datasource_id) as $field_datasource_id) {
+        foreach ($this->index->getFieldsByDatasource($field_datasource_id) as $field_id => $field) {
+          $field = clone $field;
+          if (!empty($field_values[$field_id])) {
+            $field->setValues($field_values[$field_id]);
+          }
+          $item->setField($field_id, $field);
         }
-        $item->setField($field_id, $field);
       }
       $item->setFieldsExtracted(TRUE);
       $items[$item_id] = $item;
@@ -146,8 +177,8 @@ public function testAggregation($type, $expected, $integer = FALSE) {
       $this->processor->addFieldValues($item);
     }
 
-    $this->assertEquals($expected[0], $items[$this->itemIds[0]]->getField($this->fieldId)->getValues(), 'Correct aggregation for item 1.');
-    $this->assertEquals($expected[1], $items[$this->itemIds[1]]->getField($this->fieldId)->getValues(), 'Correct aggregation for item 2.');
+    $this->assertEquals(array_map($this->valueCallback, $expected[0]), $items[$this->itemIds[0]]->getField($this->fieldId)->getValues(), 'Correct aggregation for item 1.');
+    $this->assertEquals(array_map($this->valueCallback, $expected[1]), $items[$this->itemIds[1]]->getField($this->fieldId)->getValues(), 'Correct aggregation for item 2.');
   }
 
   /**
