def _get_instance(hosts=None, profile=None):
 es = None
 proxies = {}
 use_ssl = False
 ca_certs = False
 verify_certs = False
 if (profile is None):
  profile = 'elasticsearch'
 if isinstance(profile, string_types):
  _profile = __salt__['config.option'](profile, None)
 elif isinstance(profile, dict):
  _profile = profile
 if _profile:
  hosts = _profile.get('host', None)
  if (not hosts):
   hosts = _profile.get('hosts', None)
  proxies = _profile.get('proxies', {})
  use_ssl = _profile.get('use_ssl', False)
  ca_certs = _profile.get('ca_certs', False)
  verify_certs = _profile.get('verify_certs', False)
 if (not hosts):
  hosts = ['127.0.0.1:9200']
 if isinstance(hosts, string_types):
  hosts = [hosts]
 try:
  if (proxies == {}):
   es = elasticsearch.Elasticsearch(hosts, use_ssl=use_ssl, ca_certs=ca_certs, verify_certs=verify_certs)
  else:
   class ProxyConnection(RequestsHttpConnection, ):
    def __init__(self, *args, **kwargs):
     proxies = kwargs.pop('proxies', {})
     super(ProxyConnection, self).__init__(*args, **kwargs)
     self.session.proxies = proxies
   es = elasticsearch.Elasticsearch(hosts, connection_class=ProxyConnection, proxies=_profile.get('proxies', {}), use_ssl=use_ssl, ca_certs=ca_certs, verify_certs=verify_certs)
  if (not es.ping()):
   raise CommandExecutionError('Could not connect to Elasticsearch host/ cluster {0}, is it unhealthy?'.format(hosts))
 except elasticsearch.exceptions.ConnectionError:
  raise CommandExecutionError('Could not connect to Elasticsearch host/ cluster {0}'.format(hosts))
 return es

def _get_instance ( hosts = None , profile = None ) : es = None proxies = { } use_ssl = False ca_certs = False verify_certs = False if ( profile is None ) : profile = 'elasticsearch' if isinstance ( profile , string_types ) : _profile = __salt__ [ 'config.option' ] ( profile , None ) elif isinstance ( profile , dict ) : _profile = profile if _profile : hosts = _profile . get ( 'host' , None ) if ( not hosts ) : hosts = _profile . get ( 'hosts' , None ) proxies = _profile . get ( 'proxies' , { } ) use_ssl = _profile . get ( 'use_ssl' , False ) ca_certs = _profile . get ( 'ca_certs' , False ) verify_certs = _profile . get ( 'verify_certs' , False ) if ( not hosts ) : hosts = [ '127.0.0.1:9200' ] if isinstance ( hosts , string_types ) : hosts = [ hosts ] try : if ( proxies == { } ) : es = elasticsearch . Elasticsearch ( hosts , use_ssl = use_ssl , ca_certs = ca_certs , verify_certs = verify_certs ) else : class ProxyConnection ( RequestsHttpConnection , ) : def __init__ ( self , * args , ** kwargs ) : proxies = kwargs . pop ( 'proxies' , { } ) super ( ProxyConnection , self ) . __init__ ( * args , ** kwargs ) self . session . proxies = proxies es = elasticsearch . Elasticsearch ( hosts , connection_class = ProxyConnection , proxies = _profile . get ( 'proxies' , { } ) , use_ssl = use_ssl , ca_certs = ca_certs , verify_certs = verify_certs ) if ( not es . ping ( ) ) : raise CommandExecutionError ( 'Could not connect to Elasticsearch host/ cluster {0}, is it unhealthy?' . format ( hosts ) ) except elasticsearch . exceptions . ConnectionError : raise CommandExecutionError ( 'Could not connect to Elasticsearch host/ cluster {0}' . format ( hosts ) ) return es
get an instance per hass object .