def find_object(self, username, secret, domain=None, host_ip=None, service_id=None):
<EOL>search = Credential.search()<EOL>search = search.filter("<STR_LIT>", username=username)<EOL>search = search.filter("<STR_LIT>", secret=secret)<EOL>if domain:<EOL><INDENT>search = search.filter("<STR_LIT>", domain=domain)<EOL><DEDENT>else:<EOL><INDENT>search = search.exclude("<STR_LIT>", field="<STR_LIT>")<EOL><DEDENT>if host_ip:<EOL><INDENT>search = search.filter("<STR_LIT>", host_ip=host_ip)<EOL><DEDENT>else:<EOL><INDENT>search = search.exclude("<STR_LIT>", field="<STR_LIT>")<EOL><DEDENT>if service_id:<EOL><INDENT>search = search.filter("<STR_LIT>", service_id=service_id)<EOL><DEDENT>else:<EOL><INDENT>search = search.exclude("<STR_LIT>", field="<STR_LIT>")<EOL><DEDENT>if search.count():<EOL><INDENT>result = search[<NUM_LIT:0>].execute()[<NUM_LIT:0>]<EOL>return result<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
Searches elasticsearch for objects with the same username, password, optional domain, host_ip and service_id.