diff --git a/config/schema/search_api.processor.schema.yml b/config/schema/search_api.processor.schema.yml
index efb2da1..63da031 100644
--- a/config/schema/search_api.processor.schema.yml
+++ b/config/schema/search_api.processor.schema.yml
@@ -28,6 +28,17 @@ plugin.plugin_configuration.search_api_processor.*:
 
 # Definitions for individual processors
 
+plugin.plugin_configuration.search_api_processor.add_hierarchy:
+  type: search_api.default_processor_configuration
+  label: 'Hierarchy processor'
+  mapping:
+    fields:
+      type: sequence
+      label: 'The fields to index hierarchy for'
+      sequence:
+        type: string
+        label: 'The field to index hierarchy for'
+
 plugin.plugin_configuration.search_api_processor.highlight:
   type: search_api.default_processor_configuration
   label: 'Highlight processor configuration'
diff --git a/src/Plugin/search_api/processor/AddHierarchy.php b/src/Plugin/search_api/processor/AddHierarchy.php
new file mode 100644
index 0000000..9984fd7
--- /dev/null
+++ b/src/Plugin/search_api/processor/AddHierarchy.php
@@ -0,0 +1,147 @@
+<?php
+
+namespace Drupal\search_api\Plugin\search_api\processor;
+
+use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Drupal\search_api\Item\FieldInterface;
+use Drupal\search_api\Processor\FieldsProcessorPluginBase;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * @SearchApiProcessor(
+ *   id = "add_hierarchy",
+ *   label = @Translation("Hierarchy"),
+ *   description = @Translation("Adds item's hierarchy into the backend"),
+ *   stages = {
+ *     "preprocess_index" = -45
+ *   }
+ * )
+ */
+class AddHierarchy extends FieldsProcessorPluginBase implements ContainerFactoryPluginInterface {
+
+  /**
+   * The entity type manager service used to determine hierarchy.
+   *
+   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
+   */
+  protected $entityTypeManager;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+    // Set configuration defaults.
+    $configuration += array(
+      'fields' => array(),
+    );
+
+    /** @var static $processor */
+    $processor = new static($configuration, $plugin_id, $plugin_definition);
+
+    $entity_type_manager = $container->get('entity_type.manager');
+    $processor->setEntityTypeManager($entity_type_manager);
+
+    return $processor;
+  }
+
+  /**
+   * Set the entity type manager service.
+   *
+   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
+   *   The entity type manager service.
+   */
+  public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager) {
+    $this->entityTypeManager = $entity_type_manager;
+  }
+
+  /**
+   * Determines if a given field is an entity reference field.
+   *
+   * @param \Drupal\search_api\Item\FieldInterface $field
+   *   The field to check.
+   *
+   * @return bool
+   *   Returns TRUE if the given field is an entity reference field.
+   */
+  protected function isEntityReferenceField(FieldInterface $field) {
+    return $field->getOriginalType() == 'field_item:entity_reference';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function preprocessIndexItems(array &$items) {
+    /** @var \Drupal\search_api\Item\ItemInterface $item */
+    foreach ($items as $item) {
+      foreach ($item->getFields() as $field) {
+        if ($this->isEntityReferenceField($field) && in_array($field->getFieldIdentifier(), $this->configuration['fields'])) {
+          // The field is an entity reference, so we have to traverse up the
+          // tree to find all parents.
+          $hierarchyValues = array();
+
+          $fieldValues = $field->getValues();
+
+          foreach ($fieldValues as $val) {
+            // Initial value is always included.
+            $hierarchyValues[] = $val;
+            $field_storage = $field->getDataDefinition()->getFieldDefinition()->getFieldStorageDefinition();
+            $this->extractHierarchy($val, $hierarchyValues, $field_storage);
+          }
+
+          $field->setValues(array_unique($hierarchyValues));
+        }
+      }
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   *
+   * Override this method to only allow entity reference fields.
+   */
+  public function testType($type, FieldInterface $field) {
+    return $this->isEntityReferenceField($field);
+  }
+
+  /**
+   * Extract the hierarchy of a given field.
+   *
+   * This method calls itself recursively and extracts the hierarchy by
+   * appending the `$values` array.
+   *
+   * Taxonomy references are handled differently since the hierarchy is not on
+   * the given item, but rather on the referenced vocabulary.
+   *
+   * @param mixed $id
+   *   The item ID for which to find hierarchical relationships.
+   * @param array $values
+   *   The values array.
+   * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage
+   *   The field storage definition.
+   */
+  protected function extractHierarchy($id, array &$values, FieldStorageDefinitionInterface $field_storage) {
+    // Load the entity storage for the given field.
+    $storage = $this->entityTypeManager->getStorage($field_storage->getTargetEntityTypeId());
+    $child = $storage->load($id);
+
+    // Special handling if this is a taxonomy field.
+    if ($field_storage->getSetting('target_type') == 'taxonomy_term') {
+      // Add each parent.
+      foreach ($this->entityTypeManager->getStorage('taxonomy_term')->loadParents($id) as $parent) {
+        $values[] = $parent->id();
+      }
+      return;
+    }
+    else {
+      // @todo This isn't yet capturing the parent item.
+      foreach ($child->{$field_storage->getName()} as $value) {
+        $values[] = $value;
+        // @todo Check for circular references to avoid infinite recursion.
+        $this->extractHierarchy($value, $values, $field_storage);
+      }
+    }
+  }
+
+}
diff --git a/src/Plugin/search_api/processor/Stopwords.php b/src/Plugin/search_api/processor/Stopwords.php
index 5a228d1..fa9eb56 100644
--- a/src/Plugin/search_api/processor/Stopwords.php
+++ b/src/Plugin/search_api/processor/Stopwords.php
@@ -3,6 +3,7 @@
 namespace Drupal\search_api\Plugin\search_api\processor;
 
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\search_api\Item\FieldInterface;
 use Drupal\search_api\Processor\FieldsProcessorPluginBase;
 use Drupal\search_api\Query\QueryInterface;
 use Drupal\search_api\Query\ResultSetInterface;
@@ -115,7 +116,7 @@ class Stopwords extends FieldsProcessorPluginBase {
   /**
    * {@inheritdoc}
    */
-  protected function testType($type) {
+  protected function testType($type, FieldInterface $field) {
     return Utility::isTextType($type, array('text', 'tokenized_text'));
   }
 
diff --git a/src/Plugin/search_api/processor/Tokenizer.php b/src/Plugin/search_api/processor/Tokenizer.php
index a5677ec..b5b6cee 100644
--- a/src/Plugin/search_api/processor/Tokenizer.php
+++ b/src/Plugin/search_api/processor/Tokenizer.php
@@ -5,6 +5,7 @@ namespace Drupal\search_api\Plugin\search_api\processor;
 use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Url;
+use Drupal\search_api\Item\FieldInterface;
 use Drupal\search_api\Processor\FieldsProcessorPluginBase;
 use Drupal\search_api\Utility;
 
@@ -100,7 +101,7 @@ class Tokenizer extends FieldsProcessorPluginBase {
   /**
    * {@inheritdoc}
    */
-  protected function testType($type) {
+  protected function testType($type, FieldInterface $field) {
     return Utility::isTextType($type, array('text', 'tokenized_text'));
   }
 
diff --git a/src/Processor/FieldsProcessorPluginBase.php b/src/Processor/FieldsProcessorPluginBase.php
index b0b95cd..4da8a64 100644
--- a/src/Processor/FieldsProcessorPluginBase.php
+++ b/src/Processor/FieldsProcessorPluginBase.php
@@ -49,7 +49,7 @@ abstract class FieldsProcessorPluginBase extends ProcessorPluginBase {
       $default_fields = array_filter($this->configuration['fields']);
     }
     foreach ($fields as $name => $field) {
-      if ($this->testType($field->getType())) {
+      if ($this->testType($field->getType(), $field)) {
         $field_options[$name] = Html::escape($field->getPrefixedLabel());
         if (!isset($this->configuration['fields']) && $this->testField($name, $field)) {
           $default_fields[$name] = $name;
@@ -274,7 +274,7 @@ abstract class FieldsProcessorPluginBase extends ProcessorPluginBase {
    */
   protected function testField($name, FieldInterface $field) {
     if (!isset($this->configuration['fields'])) {
-      return $this->testType($field->getType());
+      return $this->testType($field->getType(), $field);
     }
     return in_array($name, $this->configuration['fields'], TRUE);
   }
@@ -289,10 +289,14 @@ abstract class FieldsProcessorPluginBase extends ProcessorPluginBase {
    *   The type of the field (either when preprocessing the field at index time,
    *   or a condition on the field at query time).
    *
-   * @return bool
-   *   TRUE if fields of that type should be processed, FALSE otherwise.
+   * @param \Drupal\search_api\Item\FieldInterface $field
+   *   The field item if additional information is needed to determine if the
+   *   type should be processed or not.
+   *
+   * @return bool TRUE if fields of that type should be processed, FALSE otherwise.
+   * TRUE if fields of that type should be processed, FALSE otherwise.
    */
-  protected function testType($type) {
+  protected function testType($type, FieldInterface $field) {
     return Utility::isTextType($type, array('text', 'tokenized_text', 'string'));
   }
 
diff --git a/src/Query/Query.php b/src/Query/Query.php
index 4cfc7e6..263a844 100644
--- a/src/Query/Query.php
+++ b/src/Query/Query.php
@@ -549,7 +549,7 @@ class Query implements QueryInterface {
    * Implements the magic __wakeup() method to reload the query's index.
    */
   public function __wakeup() {
-    if (!isset($this->index) && !empty($this->indexId)) {
+    if (!isset($this->index) && !empty($this->indexId) && \Drupal::hasContainer()) {
       $this->index = \Drupal::entityTypeManager()
         ->getStorage('search_api_index')
         ->load($this->indexId);
diff --git a/src/Utility.php b/src/Utility.php
index 1585562..029b02b 100644
--- a/src/Utility.php
+++ b/src/Utility.php
@@ -266,7 +266,6 @@ class Utility {
       }
       $field->addValue($value);
     }
-    $field->setOriginalType($data->getDataDefinition()->getDataType());
   }
 
   /**
diff --git a/tests/src/Kernel/Processor/AddHierarchyTest.php b/tests/src/Kernel/Processor/AddHierarchyTest.php
new file mode 100644
index 0000000..2a439ce
--- /dev/null
+++ b/tests/src/Kernel/Processor/AddHierarchyTest.php
@@ -0,0 +1,260 @@
+<?php
+
+namespace Drupal\Tests\search_api\Kernel\Processor;
+
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
+use Drupal\node\Entity\NodeType;
+use Drupal\search_api\Item\Field;
+use Drupal\search_api\Utility;
+use Drupal\simpletest\NodeCreationTrait;
+use Drupal\taxonomy\Tests\TaxonomyTestTrait;
+use Drupal\Tests\search_api\Kernel\ResultsTrait;
+
+/**
+ * Tests the "Hierarchy" processor.
+ *
+ * @see \Drupal\search_api\Plugin\search_api\processor\AddHierarchy
+ *
+ * @group search_api
+ *
+ * @coversDefaultClass \Drupal\search_api\Plugin\search_api\processor\AddHierarchy
+ */
+class AddHierarchyTest extends ProcessorTestBase {
+
+  use NodeCreationTrait;
+  use EntityReferenceTestTrait;
+  use ResultsTrait;
+  use TaxonomyTestTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = array(
+    'filter',
+    'taxonomy',
+  );
+
+  /**
+   * A hierarchy to test.
+   */
+  protected static $hierarchy = array(
+    'fruit' => array(
+      'apple',
+      'pear'
+    ),
+    'vegetable' => array(
+      'radish',
+      'turnip',
+    ),
+  );
+
+  /**
+   * The nodes created for testing.
+   *
+   * @var \Drupal\node\NodeInterface[]
+   */
+  protected $nodes;
+
+  /**
+   * Hierarchical taxonomy terms.
+   *
+   * This is keyed by "type.item", for example: "fruit.pear".
+   *
+   * @var \Drupal\taxonomy\TermInterface[]
+   */
+  protected $terms;
+
+  /**
+   * Vocabulary to test with when using taxonomy for the hierarchy.
+   *
+   * @var \Drupal\taxonomy\VocabularyInterface
+   */
+  protected $vocabulary;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp($processor = NULL) {
+    parent::setUp('add_hierarchy');
+
+    $this->installConfig(['filter']);
+    $this->installEntitySchema('taxonomy_term');
+    $this->createTaxonomyHierarchy();
+
+    // Create a node type for testing.
+    $type = NodeType::create(array(
+      'type' => 'page',
+      'name' => 'page',
+    ));
+    $type->save();
+
+    // Add the taxonomy field to page type.
+    $this->createEntityReferenceField(
+      'node',
+      'page',
+      'term_field',
+      NULL,
+      'taxonomy_term',
+      'default',
+      array(),
+      FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
+    );
+
+    // Add a generic entity reference field.
+    $this->createEntityReferenceField(
+      'node',
+      'page',
+      'parent_reference',
+      NULL,
+      'node',
+      'default',
+      array()
+    );
+
+    // Index the taxonomy field.
+    $term_field = new Field($this->index, 'term_field');
+    $term_field->setType('integer');
+    $term_field->setPropertyPath('term_field');
+    $term_field->setDatasourceId('entity:node');
+    $term_field->setLabel('Terms');
+    $this->index->addField($term_field);
+    $this->index->save();
+
+    // Index the entity reference field.
+    $reference_field = new Field($this->index, 'parent_reference');
+    $reference_field->setType('integer');
+    $reference_field->setPropertyPath('parent_reference');
+    $reference_field->setDatasourceId('entity:node');
+    $reference_field->setLabel('Parent page');
+    $this->index->addField($reference_field);
+    $this->index->save();
+
+    // Setup a node index.
+    $manager = $this->container->get('plugin.manager.search_api.datasource');
+    $datasources['entity:node'] = $manager->createInstance('entity:node', ['index' => $this->index]);
+    $this->index->setDatasources($datasources);
+    $this->index->save();
+    $this->container->get('search_api.index_task_manager')->addItemsAll($this->index);
+    $index_storage = $this->container->get('entity_type.manager')->getStorage('search_api_index');
+    $index_storage->resetCache([$this->index->id()]);
+    $this->index = $index_storage->load($this->index->id());
+  }
+
+  /**
+   * Tests taxonomy-based hierarchy indexing.
+   *
+   * @covers ::preprocessIndexItems
+   */
+  public function testPreprocessIndexItemsTaxonomy() {
+    // Add hierarchical terms to 3 nodes.
+    foreach (array('vegetable.turnip', 'vegetable', 'fruit.pear') as $i => $term) {
+      $this->nodes[$i] = $this->createNode(array(
+        'type' => 'page',
+        'term_field' => array(
+          'target_id' => $this->terms[$term]->id(),
+        ),
+      ));
+    }
+    $this->index->reindex();
+    $this->index->indexItems();
+
+    // By default, hierarchy is not indexed, so a search for 'vegetable'
+    // should only return node 2.
+    $query = Utility::createQuery($this->index);
+    $query->addCondition('term_field', $this->terms['vegetable']->id());
+    $result = $query->execute();
+    $expected = array('node' => array(1));
+    $this->assertResults($result, $expected);
+
+    // Enable hierarchical indexing.
+    $processor = $this->index->getProcessors()['add_hierarchy'];
+    $processor->setConfiguration(array('fields' => array('term_field')));
+    $this->index->addProcessor($processor);
+    $this->index->save();
+    $this->index->reindex();
+    $this->index->indexItems();
+
+    // Query for 'vegetable' should return 2 items:
+    // Node 1 is 'vegetable.turnip' and node 2 is just 'vegetable'.
+    $query = Utility::createQuery($this->index);
+    $query->addCondition('term_field', $this->terms['vegetable']->id());
+    $result = $query->execute();
+    $expected = array('node' => array(0, 1));
+    $this->assertResults($result, $expected);
+
+    // A search for just turnips should return node 1 only.
+    $query = Utility::createQuery($this->index);
+    $query->addCondition('term_field', $this->terms['vegetable.turnip']->id());
+    $result = $query->execute();
+    $expected = array('node' => array(0));
+    $this->assertResults($result, $expected);
+  }
+
+  /**
+   * Helper function to create the hierarchy with taxonomy terms.
+   */
+  protected function createTaxonomyHierarchy() {
+    $this->vocabulary = $this->createVocabulary();
+
+    foreach (static::$hierarchy as $type => $items) {
+      // Add the 'type' item, and nest items underneath.
+      $this->terms[$type] = $type_term = $this->createTerm($this->vocabulary, array(
+        'name' => $type,
+      ));
+      foreach ($items as $item) {
+        $this->terms["$type.$item"] = $this->createTerm($this->vocabulary, array(
+          'name' => $item,
+          'parent' => $type_term,
+        ));
+      }
+    }
+  }
+
+  /**
+   * Test non-taxonomy-based hierarchy.
+   *
+   * @covers ::preprocessIndexItems
+   * @covers ::extractHierarchy
+   */
+  public function testPreprocessIndexItems() {
+    // Setup the nodes to follow the hierarchy.
+    foreach (static::$hierarchy as $type => $items) {
+      $this->nodes[] = $type_node = $this->createNode(array(
+        'title' => $type,
+      ));
+      foreach ($items as $item) {
+        $this->nodes[] = $this->createNode(array(
+          'title' => $item,
+          'parent_reference' => array('target_id' => $type_node->id()),
+        ));
+      }
+    }
+    $this->index->reindex();
+    $this->index->indexItems();
+
+    // Initially hierarchy is excluded, so 'vegetable' should only return
+    // nodes 5 and 6.
+    $query = Utility::createQuery($this->index);
+    $query->addCondition('parent_reference', $this->nodes[3]->id());
+    $result = $query->execute();
+    $expected = array('node' => array(4, 5));
+    $this->assertResults($result, $expected);
+
+    // Enable hierarchical indexing.
+    $processor = $this->index->getProcessors()['add_hierarchy'];
+    $processor->setConfiguration(array('fields' => array('parent_reference')));
+    $this->index->addProcessor($processor);
+    $this->index->save();
+    $this->index->reindex();
+    $this->index->indexItems();
+
+    // A search for 'vegetable' should now include the hierarchy.
+    $query = Utility::createQuery($this->index);
+    $query->addCondition('parent_reference', $this->nodes[3]->id());
+    $result = $query->execute();
+    $expected = array('node' => array(3, 4, 5));
+    $this->assertResults($result, $expected);
+  }
+
+}
diff --git a/tests/src/Kernel/Processor/ContentAccessTest.php b/tests/src/Kernel/Processor/ContentAccessTest.php
index 1964845..2b15f09 100644
--- a/tests/src/Kernel/Processor/ContentAccessTest.php
+++ b/tests/src/Kernel/Processor/ContentAccessTest.php
@@ -9,8 +9,8 @@ use Drupal\Core\Database\Database;
 use Drupal\Core\TypedData\DataDefinitionInterface;
 use Drupal\node\Entity\Node;
 use Drupal\node\Entity\NodeType;
-use Drupal\search_api\Query\ResultSetInterface;
 use Drupal\search_api\Utility;
+use Drupal\Tests\search_api\Kernel\ResultsTrait;
 use Drupal\user\Entity\Role;
 use Drupal\user\Entity\User;
 
@@ -24,6 +24,7 @@ use Drupal\user\Entity\User;
 class ContentAccessTest extends ProcessorTestBase {
 
   use CommentTestTrait;
+  use ResultsTrait;
 
   /**
    * The nodes created for testing.
@@ -314,39 +315,6 @@ class ContentAccessTest extends ProcessorTestBase {
   }
 
   /**
-   * Asserts that the search results contain the expected IDs.
-   *
-   * @param \Drupal\search_api\Query\ResultSetInterface $result
-   *   The search results.
-   * @param int[][] $expected
-   *   The expected entity IDs, grouped by entity type and with their indexes in
-   *   this object's respective array properties as the values.
-   */
-  protected function assertResults(ResultSetInterface $result, array $expected) {
-    $results = array_keys($result->getResultItems());
-    sort($results);
-
-    $ids = array();
-    foreach ($expected as $entity_type => $items) {
-      $datasource_id = "entity:$entity_type";
-      foreach ($items as $i) {
-        if ($entity_type == 'user') {
-          $id = $i . ':en';
-        }
-        else {
-          /** @var \Drupal\Core\Entity\EntityInterface $entity */
-          $entity = $this->{"{$entity_type}s"}[$i];
-          $id = $entity->id() . ':en';
-        }
-        $ids[] = Utility::createCombinedId($datasource_id, $id);
-      }
-    }
-    sort($ids);
-
-    $this->assertEquals($ids, $results);
-  }
-
-  /**
    * Creates a new user account.
    *
    * @param string[] $permissions
diff --git a/tests/src/Kernel/ResultsTrait.php b/tests/src/Kernel/ResultsTrait.php
new file mode 100644
index 0000000..7129613
--- /dev/null
+++ b/tests/src/Kernel/ResultsTrait.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace Drupal\Tests\search_api\Kernel;
+
+use Drupal\search_api\Query\ResultSetInterface;
+use Drupal\search_api\Utility;
+
+/**
+ * Defines a trait for testing results.
+ */
+trait ResultsTrait {
+
+  /**
+   * Asserts that the search results contain the expected IDs.
+   *
+   * @param \Drupal\search_api\Query\ResultSetInterface $result
+   *   The search results.
+   * @param int[][] $expected
+   *   The expected entity IDs, grouped by entity type and with their indexes in
+   *   this object's respective array properties as the values.
+   */
+  protected function assertResults(ResultSetInterface $result, array $expected) {
+    $results = array_keys($result->getResultItems());
+    sort($results);
+
+    $ids = array();
+    foreach ($expected as $entity_type => $items) {
+      $datasource_id = "entity:$entity_type";
+      foreach ($items as $i) {
+        if ($entity_type == 'user') {
+          $id = $i . ':en';
+        }
+        else {
+          /** @var \Drupal\Core\Entity\EntityInterface $entity */
+          $entity = $this->{"{$entity_type}s"}[$i];
+          $id = $entity->id() . ':en';
+        }
+        $ids[] = Utility::createCombinedId($datasource_id, $id);
+      }
+    }
+    sort($ids);
+
+    $this->assertEquals($ids, $results);
+  }
+
+}
