繁体   English   中英

python elasticsearch-dsl父子关系

[英]python elasticsearch-dsl parent child relationship

我开始使用python库elasticsearch-dsl

我正在尝试实现父子关系,但它无法正常工作:

    class Location(DocType):
        name = String(analyzer='snowball', fields={'raw': String(index='not_analyzed')})
        latitude = String(analyzer='snowball')
        longitude = String(analyzer='snowball')
        created_at = Date()

   class Building(DocType):
       parent = Location()

elasticsearch-dsl使用MetaField构建了父子关系:

class Location(DocType):
    name = String(analyzer='snowball', fields={'raw': String(index='not_analyzed')})
    latitude = String(analyzer='snowball')
    longitude = String(analyzer='snowball')
    created = Date()

    class Meta:
        doc_type = 'location' 

class Building(DocType):

    class Meta:
        doc_type = 'building'
        parent = MetaField(type='location')

如何插入和查询(HT到@Maresh):
- DSL get: ChildDoc.get(id=child_id, routing=parent_id)
- DSL插入:我相信它是child.save(id=child_id, routing=parent_id)
- 字典插入:在字典中指定'_parent': parent_id

好的,谢谢大家。 对我有用的简单而凌乱的解决方案是使用:

from elasticsearch_dsl import Mapping

mcc = Mapping(typeChild)
mcc.meta('_parent', type=typeParent)
mcc.field(fieldName, 'string', fielddata=True, store=True)
mcc.save(index)

在创建父doc-type之前

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM