处理 ElasticSearch 的最 pythonic 方式是什么?
What is the most pythonic way to handle ElasticSearch?
我有一个现有的存储库连接到 MySQL。为清楚起见,省略了详细信息。
class Person(object):
def __init__(self):
# This is entity is mapped to the DB using SQLAlchemy's classical mapping.
It also includes an Address
pass
class Address(object):
def __init__(self):
pass
class PersonRepository(object):
def __init__(self, DBSession):
self.session = DBSession
def persist(self, entity):
self.session.add(entity)
self.session.flush()
return entity
class AddressEditor(object):
def __init__(self):
pass
def add_address(self, person, address):
person.address = address
#We can either inject the session into this method, or
#obtain it from a configuration file.
repository = PersonRepository(DBSession)
person = repository.persist(person)
return person.address
我想将存储库转换为 ElasticSearch。
前进的最佳方式是什么?
使用 Elasticsearch() 实例而不是 DBSession。并在 PersonRepository API 中实现对 ElasticSearch 的调用。
我有一个现有的存储库连接到 MySQL。为清楚起见,省略了详细信息。
class Person(object):
def __init__(self):
# This is entity is mapped to the DB using SQLAlchemy's classical mapping.
It also includes an Address
pass
class Address(object):
def __init__(self):
pass
class PersonRepository(object):
def __init__(self, DBSession):
self.session = DBSession
def persist(self, entity):
self.session.add(entity)
self.session.flush()
return entity
class AddressEditor(object):
def __init__(self):
pass
def add_address(self, person, address):
person.address = address
#We can either inject the session into this method, or
#obtain it from a configuration file.
repository = PersonRepository(DBSession)
person = repository.persist(person)
return person.address
我想将存储库转换为 ElasticSearch。 前进的最佳方式是什么?
使用 Elasticsearch() 实例而不是 DBSession。并在 PersonRepository API 中实现对 ElasticSearch 的调用。