<commit_before>from __future__ import unicode_literals
from elasticsearch import TransportError

from elasticsearch_dsl import Search, DocType, Date, Text, Keyword, MultiSearch, \
    MetaField, Index, Q

from .test_data import DATA

from pytest import raises

class Repository(DocType):
    created_at = Date()
    description = Text(analyzer='snowball')
    tags = Keyword()

    class Meta:
        index = 'git'
        doc_type = 'repos'

class Commit(DocType):
    class Meta:
        doc_type = 'commits'
        index = 'git'
        parent = MetaField(type='repos')

def test_inner_hits_are_wrapped_in_response(data_client):
    s = Search(index='git', doc_type='commits')[0:1].query('has_parent', type='repos', inner_hits={}, query=Q('match_all'))
    response = s.execute()

    commit = response.hits[0]
    assert isinstance(commit.meta.inner_hits.repos, response.__class__)
    assert repr(commit.meta.inner_hits.repos[0]).startswith("<Result(git/repos/elasticsearch-dsl-py): ")

def test_inner_hits_are_wrapped_in_doc_type(data_client):
    i = Index('git')
    i.doc_type(Repository)
    i.doc_type(Commit)
    s = i.search()[0:1].doc_type(Commit).query('has_parent', type='repos', inner_hits={}, query=Q('match_all'))<commit_msg>Inner hits no longer have index<commit_after>from __future__ import unicode_literals
from elasticsearch import TransportError

from elasticsearch_dsl import Search, DocType, Date, Text, Keyword, MultiSearch, \
    MetaField, Index, Q

from .test_data import DATA

from pytest import raises

class Repository(DocType):
    created_at = Date()
    description = Text(analyzer='snowball')
    tags = Keyword()

    class Meta:
        index = 'git'
        doc_type = 'repos'

class Commit(DocType):
    class Meta:
        doc_type = 'commits'
        index = 'git'
        parent = MetaField(type='repos')

def test_inner_hits_are_wrapped_in_response(data_client):
    s = Search(index='git', doc_type='commits')[0:1].query('has_parent', type='repos', inner_hits={}, query=Q('match_all'))
    response = s.execute()

    commit = response.hits[0]
    assert isinstance(commit.meta.inner_hits.repos, response.__class__)
    r = commit.meta.inner_hits.repos[0]
    assert repr(commit.meta.inner_hits.repos[0]).startswith("<Result(repos/elasticsearch-dsl-py): ")

def test_inner_hits_are_wrapped_in_doc_type(data_client):
    i = Index('git')
    i.doc_type(Repository)
    i.doc_type(Commit)
    s = i.search()[0:1].doc_type(Commit).query('has_parent', type='repos', inner_hits={}, query=Q('match_all'))
{'fraction_non_alphanumeric': 0.1307934014139827, 'fraction_numerical': 0.005106048703849175, 'mean_word_length': 4.47741935483871, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6885064', 'n_tokens_mistral': 866, 'n_tokens_neox': 850, 'n_words': 166}