我开始使用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()发布于 2016-03-15 02:57:15
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 to @Maresh):
字典插入DSL get:ChildDoc.get(id=child_id, routing=parent_id)
child.save(id=child_id, routing=parent_id)
'_parent': parent_id in 发布于 2016-11-27 21:46:36
好的,谢谢大家。对我有效的简单而混乱的解决方案是使用:
from elasticsearch_dsl import Mapping
mcc = Mapping(typeChild)
mcc.meta('_parent', type=typeParent)
mcc.field(fieldName, 'string', fielddata=True, store=True)
mcc.save(index)在创建父单据类型之前
https://stackoverflow.com/questions/35068869
复制相似问题