gpt4 book ai didi

python - 处理 ElasticSearch 最 Pythonic 的方法是什么?

转载 作者:行者123 更新时间:2023-12-01 00:07:48 24 4
gpt4 key购买 nike

我有一个连接到 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 的调用。

可在图书馆获取https://elasticsearch-py.readthedocs.io/en/master/

关于python - 处理 ElasticSearch 最 Pythonic 的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59834323/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com