1

我将 Elastisearch 5.x 和 Python 与 elasticsearch-dsl 5.2.0 一起使用

我需要从孩子开始查询,获取几个字段,将其与定义的父亲和祖父匹配(我还需要从祖父那里得到一个字段值)

问题是在我的搜索结果中,Grandfather inner_hits 是空的。我真的可以在这里使用小费。

search = Child.search().source(
    includes=['a', 'b']
).filter(
    'term', child_id=child_id
).query(
    'has_parent',
    type='father',
    inner_hits={'name': 'father'},
    query=Q(
        Q('term', id=father_id) &
        Q(
            'has_parent',
            type='grandfather',
            inner_hits={'name': 'grandfather'},
            query=Q('term', _id=grandfather_id)
        )
    )
)


class Child(DocType):
    child_id = Keyword()
    a = Keyword()
    b = Keyword()

    class Meta:
        doc_type = 'child'
        parent = MetaField(type='father')

class Father(DocType):
    id = Integer()

    class Meta:
        doc_type = 'father'
        parent = MetaField(type='grandfather')

class Grandfather(DocType):
    grandfather_id = String()
    grandfatherFieldNeeded = String() 

    class Meta:
        doc_type = 'grandfather'
        parent = MetaField(type='notimportant')
4

0 回答 0