当前位置: 首页>>代码示例>>Python>>正文


Python IndicesClient.exists方法代码示例

本文整理汇总了Python中elasticsearch.client.IndicesClient.exists方法的典型用法代码示例。如果您正苦于以下问题:Python IndicesClient.exists方法的具体用法?Python IndicesClient.exists怎么用?Python IndicesClient.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elasticsearch.client.IndicesClient的用法示例。


在下文中一共展示了IndicesClient.exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestSingleDocSigTerms

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
class TestSingleDocSigTerms(TestCase):
    def setUp(self):
        super(TestSingleDocSigTerms, self).setUp()

        self.es = Elasticsearch(hosts=['localhost:%d' % es_runner.es_state.port])
        self.ic = IndicesClient(self.es)
        self.index = 'single_doc_sigterms_test'
        self.doc_type = 'test-doc'
        self.field = 'text'

        if self.ic.exists(self.index):
            self.ic.delete(self.index)

        self.ic.create(self.index)
        self.es.create(self.index, self.doc_type, {self.field: 'foo ba knark foo knirk knark foo'}, id='doc_1')

    def test_tf_for_doc_id(self):
        sigterms = SingleDocSigTerms(self.es, self.index, self.doc_type, self.field, None)

        resp = dict(sigterms.tf_for_doc_id('doc_1'))
        self.assertEquals(4, len(resp))
        self.assertEquals(3, resp['foo'])
        self.assertEquals(2, resp['knark'])
        self.assertEquals(1, resp['ba'])
        self.assertEquals(1, resp['knirk'])
开发者ID:comperiosearch,项目名称:comperio-text-analytics,代码行数:27,代码来源:test_single_doc_sigterms.py

示例2: handle

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
	def handle(self, *args, **options):

		es = Elasticsearch(hosts=[{'host': 'localhost', 'port': 9200}])

		fop=open('spider/management/commands/'+str(argv[2]), 'r')
		inds = IndicesClient(es)

		mapping={ "mappings": { "product_type":  {  "properties": { "code": { "type" : "string" },"name": {"type" : "string"},"img": {"type" : "string"},"url": {"type" : "string"},"price_reg": {"type" : "float"},"price_discount": {"type" : "float"}}}}}

		if not inds.exists(index='gearbest_index'):
			inds.create(index='gearbest_index',body=mapping)
			print 'gearbest_index created'

		for jsonline in fop:
			jobj=loads(jsonline)
			del jobj["_type"]
			es.index(index="gearbest_index",doc_type='product_type', body=jobj, id=jobj['code'])
			
			disc=0
			reg=0

			if len(jobj['price_discount'])>0:
				disc  = float(jobj['price_discount'][0])
			if len(jobj['price_reg'])>0:
				reg  = float(jobj['price_reg'][0])

			#insert="INSERT into 'price_gb' ('price','price_disc','code','date') values ("+str(reg)+", "+str(disc)+", '"+str(jobj['code'])+"', '"+str(datetime.today())+"')"
			#cursor = connection.cursor()
			#cursor.execute(insert)

			add_price=Price_gb(price=reg,price_disc=disc,code=str(jobj['code']),date=datetime.date.today())
			add_price.save()

			print 'code='+str(jobj['code'])
开发者ID:prodja,项目名称:djascralog,代码行数:36,代码来源:welast.py

示例3: _reset_mapping

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
    def _reset_mapping(self, mapping_path):
        esi = IndicesClient(es.get_es_handle())
        index = settings.ES_INDEX

        if not esi.exists(index):
            raise CommandError("Non existing index : %s"%index)

        self.stdout.write(str(esi.delete(index=index)))
开发者ID:beforebeta,项目名称:dealfu,代码行数:10,代码来源:esmanage.py

示例4: create_index_if_not_exists

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
	def create_index_if_not_exists(self):
		
		""" Check if index exists & if not exists create index & types & store their mappings.  """
		
		ic = IndicesClient(self.es)
		response = ic.exists(index=[self.index_name])
		if not response:
			es_mappings = ElasticSearchController.get_index_mapper_dict()			
			index_response = ic.create(index=self.index_name, body={ "mappings":es_mappings })
开发者ID:arpitjain06,项目名称:propshikhari,代码行数:11,代码来源:elastic_controller.py

示例5: initialize

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
 def initialize(self, idx):
     es_index, es_doctype = self.indexinfo(idx)
     self.logger.info("Initializing %s" % es_index)
     idx_client = IndicesClient(self.es)
     if idx_client.exists(es_index):
         idx_client.delete(es_index)
     idx_client.create(es_index)
     if idx == 'event':
         idx_client.put_mapping(doc_type=es_doctype, index=[es_index], body=event_mapping())
     self.logger.info("%s ready." % es_index)
开发者ID:haleystorm,项目名称:nets-pipeline,代码行数:12,代码来源:ncli.py

示例6: __createIndex

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
 def __createIndex(self):
     es = Elasticsearch([{'host': self.elasticsearch_host, 'port': self.elasticsearch_port}])
     ic = IndicesClient(es)
     if(ic.exists(index='wow')):
         print("deleting old index")
         self.deleteIndex()
     ic.create(index='wow')
     # blah = glob.glob(os.path.join(self.map_directory, '*'))
     for currentFile in glob.glob(os.path.join(self.map_directory, '*')):
         print("MAP FILE: " + currentFile)
         self.__mapFile(currentFile)
开发者ID:wendelfleming,项目名称:USC-LunchNLearn-ElasticSearch,代码行数:13,代码来源:indexer.py

示例7: recreate_index

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
 def recreate_index(self):
     indices_client = IndicesClient(client=settings.ES_CLIENT)
     index_name = Student._meta.es_index_name
     if indices_client.exists(index_name):
         indices_client.delete(index=index_name)
     indices_client.create(index=index_name)
     indices_client.put_mapping(
         doc_type=Student._meta.es_type_name,
         body=Student._meta.es_mapping,
         index=index_name
     )
开发者ID:bugman80,项目名称:djelastic,代码行数:13,代码来源:push-to-index.py

示例8: _remove_index_if_exists

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
 def _remove_index_if_exists():
     es = elasticsearch.Elasticsearch()
     from elasticsearch.client import IndicesClient
     es_index = IndicesClient(es)
     if es_index.exists(STORAGE_INDEX_NAME):
         logger.info(
             "Elasticsearch index '{0}' already exists and "
             "will be deleted".format(STORAGE_INDEX_NAME))
         try:
             es_index.delete(STORAGE_INDEX_NAME)
             logger.info('Verifying Elasticsearch index was deleted...')
             deadline = time.time() + 45
             while es_index.exists(STORAGE_INDEX_NAME):
                 if time.time() > deadline:
                     raise RuntimeError(
                         'Elasticsearch index was not deleted after '
                         '30 seconds')
                 time.sleep(0.5)
         except BaseException as e:
             logger.warn('Ignoring caught exception on Elasticsearch delete'
                         ' index - {0}: {1}'.format(e.__class__, e.message))
开发者ID:nagyist,项目名称:cloudify-manager,代码行数:23,代码来源:elastic.py

示例9: status

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
 def status(self):
     idx_client = IndicesClient(self.es)
     for idx in ['raw-article', 'enhanced-article']:
         es_index = self.indexinfo(idx)[0]
         if idx_client.exists(es_index):
             self.logger.info("%s contains %s documents." % (idx, self.es.count(index=es_index)['count']))
             if idx == 'article':
                 query = {"query": {"term": {"status": 1}}}
                 self.logger.info(
                     "%s articles have been processed." % self.es.count(index=es_index, body=query)['count'])
         else:
             self.logger.info("%s does not exist" % es_index)
开发者ID:haleystorm,项目名称:nets-pipeline,代码行数:14,代码来源:ncli.py

示例10: remove_log_indices

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
 def remove_log_indices():
     es = elasticsearch.Elasticsearch()
     from elasticsearch.client import IndicesClient
     es_index = IndicesClient(es)
     log_index_pattern = '{0}*'.format(LOG_INDICES_PREFIX)
     if es_index.exists(log_index_pattern):
         logger.info(
             "Elasticsearch indices '{0}' already exist and "
             "will be deleted".format(log_index_pattern))
         try:
             es_index.delete(log_index_pattern)
             logger.info('Verifying Elasticsearch index was deleted...')
             deadline = time.time() + 45
             while es_index.exists(log_index_pattern):
                 if time.time() > deadline:
                     raise RuntimeError(
                         'Elasticsearch index was not deleted after '
                         '30 seconds')
                 time.sleep(0.5)
         except BaseException as e:
             logger.warn('Ignoring caught exception on Elasticsearch delete'
                         ' index - {0}: {1}'.format(e.__class__, e.message))
开发者ID:01000101,项目名称:cloudify-manager,代码行数:24,代码来源:elastic.py

示例11: RedisEsSetupMixin

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
class RedisEsSetupMixin(object):

    def setUp(self):
        self.settings = TEST_SETTINGS_OBJECT
        self.es = get_es(self.settings)
        self.esi = IndicesClient(self.es)

        self.index = self.settings.get("ES_INDEX")

        #create the index firstly
        if self.esi.exists(self.index):
            self.esi.delete(index=self.index)

        self.esi.create(index=self.index)

        mapping_path = os.path.join(SCRAPY_ROOT,
                                 "resources/mappings.json")

        mapping_str = open(mapping_path, "r").read()
        mappings = json.loads(mapping_str)


        for k,v in mappings.iteritems():
            res = self.esi.put_mapping(self.index, k, {k:mappings[k]})
            #print res


        self.redis_conn = get_redis(self.settings)


    def tearDown(self):
        if self.esi.exists(self.index):
            self.esi.delete(index=self.index)
            print "ES INDEX DELETED"

        #remove redis stuff
        self.redis_conn.flushdb()
        print "REDIS DB DELETED"
开发者ID:beforebeta,项目名称:dealfu,代码行数:40,代码来源:test_geo.py

示例12: initialize

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
    def initialize(self, conf, context):
        host = conf.get('zeit.recommend.elasticsearch.host', 'localhost')
        port = conf.get('zeit.recommend.elasticsearch.port', 9200)
        self.es = Elasticsearch(hosts=[{'host': host, 'port': port}])
        self.match = re.compile('seite-[0-9]|komplettansicht').match
        self.index = '%s-%s' % date.today().isocalendar()[:2]
        ic = IndicesClient(self.es)

        try:
            if not ic.exists(self.index):
                ic.create(self.index)
        except ConnectionError, e:
            log('[UserIndexBolt] ConnectionError, index unreachable: %s' % e)
            return
开发者ID:cutoffthetop,项目名称:recommender,代码行数:16,代码来源:user.py

示例13: _create_weight_index

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
    def _create_weight_index(es, index):
        """
        Creates the index with the right mapping if it doesn't exist.

        :param es:
        :type es:elasticsearch.Elasticsearch
        :param index:
        :type index:str|unicode
        """
        ic = IndicesClient(es)

        if ic.exists(index):
            logging.info('Index %s already exists ...' % index)
        else:
            ic.create(index=index, body=ES_TERMWEIGHTING_INDEX_SETTINGS)
开发者ID:comperiosearch,项目名称:comperio-text-analytics,代码行数:17,代码来源:term_weight_provider.py

示例14: import_ontology

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
def import_ontology(ontology: lib.obo.Ontology, index_name: str):
    es = elasticsearch.Elasticsearch()

    ies = IndicesClient(es)

    actions = [dict(
        _index=index_name,
        _type=index_name,
        _source=dict(
            id=item.id,
            names=item.names()
        )
    ) for item in ontology.items()]

    if ies.exists(index_name):
        ies.delete(index_name)
    ies.create(index_name)
    return bulk(es, actions=actions)
开发者ID:lpenguin,项目名称:python-notebooks,代码行数:20,代码来源:import_ontology_es.py

示例15: _init_mapping

# 需要导入模块: from elasticsearch.client import IndicesClient [as 别名]
# 或者: from elasticsearch.client.IndicesClient import exists [as 别名]
    def _init_mapping(self, mapping_path):
        esi = IndicesClient(es.get_es_handle())
        index = settings.ES_INDEX

        #first create index if not exists
        if not esi.exists(index):
            self.stdout.write("Creating index for db : %s"%index)
            esi.create(index=index)
            self.stdout.write("Index Created for : %s"%index)


        if not mapping_path or not os.path.exists(mapping_path):
            raise CommandError("not existing mapping path")

        mapping_str = open(mapping_path, "r").read()
        mappings = json.loads(mapping_str)


        for k,v in mappings.iteritems():
            res = esi.put_mapping(index, k, {k:mappings[k]})
            self.stdout.write(str(res))
开发者ID:beforebeta,项目名称:dealfu,代码行数:23,代码来源:esmanage.py


注:本文中的elasticsearch.client.IndicesClient.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。