1

I have an existing repository connected to MySQL. Details have been omitted for clarity.

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

I want to convert the repository to ElasticSearch. What is the best way to move forward?

1 Answer 1

2

Use an Elasticsearch() instance instead of DBSession. And implement in the PersonRepository API calls to ElasticSearch.

Available in the library https://elasticsearch-py.readthedocs.io/en/master/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.