对于w document类,我想更改为\u id,它以前是slug或其他选项
@registry.register_document
class TestDocument(Document):
id = fields.IntegerField(attr='id', multi=True)
name = fields.TextField(
analyzer=html_strip,
fields={
'raw': fields.TextField(analyzer='keyword'),
}
)
built_area = fields.TextField(
analyzer=html_strip,
fields={
'raw': fields.TextField(analyzer='keyword'),
}
)
living_area = fields.TextField(
analyzer=html_strip,
fields={
'raw': fields.TextField(analyzer='keyword'),
}
)
project = fields.ObjectField(properties={
'name': fields.TextField(),
'pk': fields.TextField(),
})
这个线程提到了meta,但是不起作用
1条答案
按热度按时间pvabu6sv1#
正确的方法是使用document函数
generate_id
```def generate_id(self, object_instance):
return self.project.id
...
project = fields.ObjectField(properties={
'name': fields.TextField(),
'pk': fields.TextField(),
})
def generate_id(self, object_instance):
return self.project.id
class Index:
# Name of the Elasticsearch index
name = 'typologies_test'