def map_raw_results(cls, raw_results, instance=None):
        '''
        Maps raw results to database model objects.
        :param raw_results: list raw results as returned from elasticsearch-dsl-py.
        :param instance: Bungiesearch instance if you want to make use of `.only()` or `optmize_queries` as defined in the ModelIndex.
        :return: list of mapped results in the *same* order as returned by elasticsearch.
        '''
        # Let's iterate over the results and determine the appropriate mapping.
        model_results = defaultdict(list)
        # Initializing the list to the number of returned results. This allows us to restore each item in its position.
        if hasattr(raw_results, 'hits'):
            results = [None] * len(raw_results.hits)
        else:
            results = [None] * len(raw_results)
        found_results = {}
        for pos, result in enumerate(raw_results):
            model_name = result.meta.doc_type
            if model_name not in Bungiesearch._model_name_to_index or result.meta.index not in Bungiesearch._model_name_to_index[model_name]:
                logger.warning('Returned object of type {} ({}) is not defined in the settings, or is not associated to the same index as in the settings.'.format(model_name, result))
                results[pos] = result
            else:
                meta = Bungiesearch.get_model_index(model_name).Meta
                model_results['{}.{}'.format(result.meta.index, model_name)].append(result.meta.id)
                found_results['{1.meta.index}.{0}.{1.meta.id}'.format(model_name, result)] = (pos, result.meta)

        # Now that we have model ids per model name, let's fetch everything at once.
        for ref_name, ids in iteritems(model_results):
            index_name, model_name = ref_name.split('.')
            model_idx = Bungiesearch._idx_name_to_mdl_to_mdlidx[index_name][model_name]
            model_obj = model_idx.get_model()
            items = model_obj.objects.filter(pk__in=ids)
            if instance:
                if instance._only == '__model' or model_idx.optimize_queries:
                    desired_fields = model_idx.fields_to_fetch
                elif instance._only == '__fields':
                    desired_fields = instance._fields
                else:
                    desired_fields = instance._only

                if desired_fields: # Prevents setting the database fetch to __fields but not having specified any field to elasticsearch.
                    items = items.only(
                        *[field.name
                          for field in model_obj._meta.get_fields()
                          # For complete backwards compatibility, you may want to exclude
                          # GenericForeignKey from the results.
                          if field.name in desired_fields and \
                             not (field.many_to_one and field.related_model is None)
                         ]
                    )
            # Let's reposition each item in the results and set the _searchmeta meta information.
            for item in items:
                pos, meta = found_results['{}.{}.{}'.format(index_name, model_name, item.pk)]
                item._searchmeta = meta
                results[pos] = item

        return results