24 lines
684 B
Python
24 lines
684 B
Python
class EsSourceMixin:
|
|
__table__ = None
|
|
__tablename__ = ''
|
|
|
|
def to_es(self):
|
|
primary_key_name = [str(i.name) for i in self.__table__.columns if i.primary_key][0]
|
|
es_data = {
|
|
'meta': {
|
|
'id': '{}/{}'.format(self.__tablename__, getattr(self, primary_key_name)),
|
|
},
|
|
'table': self.__tablename__,
|
|
'create_time': self.now() * 1000,
|
|
}
|
|
return es_data
|
|
|
|
@classmethod
|
|
def get_es_data(cls):
|
|
for item in cls.query.yield_per(500):
|
|
yield item.to_es()
|
|
|
|
@classmethod
|
|
def es_join_str(cls, str_list):
|
|
return ' '.join(str(i or '') for i in str_list if i)
|