Elasticsearch DSL多级父查询

时间:2017-04-04 12:48:31

标签: python elasticsearch elasticsearch-dsl elasticsearch-dsl-py

我正在使用Elastisearch 5.x和Python与elasticsearch-dsl 5.2.0

我需要从孩子开始查询,带几个字段,与定义的父亲和祖父匹配(祖父我也需要字段值)

问题是,在我的搜索结果中,祖父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')

0 个答案:

没有答案