當前位置: 首頁>>代碼示例>>Python>>正文


Python client.IndicesClient方法代碼示例

本文整理匯總了Python中elasticsearch.client.IndicesClient方法的典型用法代碼示例。如果您正苦於以下問題:Python client.IndicesClient方法的具體用法?Python client.IndicesClient怎麽用?Python client.IndicesClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在elasticsearch.client的用法示例。


在下文中一共展示了client.IndicesClient方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def __init__(self, host=None, port=None, index=None, index_suffix=None):
        self.host = (host or
                     getattr(conf, 'elasticsearch_host', None) or
                     'localhost')
        self.port = (port or
                     getattr(conf, 'elasticsearch_port', None) or
                     9200)
        self.index = (index or
                      getattr(conf, 'elasticsearch_index', None) or
                      'repoxplorer')
        if index_suffix:
            self.index += "-%s" % index_suffix
        self.es = client.Elasticsearch(
            [{"host": self.host, "port": self.port}],
            timeout=60)
        self.ic = client.IndicesClient(self.es)
        if not self.ic.exists(index=self.index):
            self.ic.create(index=self.index)
            # Give some time to have the index fully created
            time.sleep(1) 
開發者ID:morucci,項目名稱:repoxplorer,代碼行數:22,代碼來源:__init__.py

示例2: create

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def create(self):
		#create indexES instance
		indexES = client.IndicesClient(self.es)
		if(self.es.indices.exists(index = self.indexNameES)):
			#logger.info('index %s already exists', self.indexNameES)
			#index already exists but it does not mean that the type exists
			if(self.es.indices.exists_type(index = self.indexNameES, doc_type = [self.typeNameES])):
				#logger.info('type %s already exists', self.typeNameES)
				#type already exists nothing to do
				pass
			else:
				#type does not exists, creating it with the mapping to apply
				#logger.info('type %s does no exist, creating it', self.typeNameES)
				indexES.put_mapping(doc_type = self.typeNameES, body = self.docMapping)
		else:
			#index does not exists, neither type (type can't exist without index)
			#creating both
			#logger.info('index %s and type %s do not exist, creating them', self.indexNameES, self.typeNameES)
			indexES.create(index = self.indexNameES)
			#indicate mapping which applies only on index/type
			indexES.put_mapping(doc_type = self.typeNameES, body = self.docMapping) 
開發者ID:TheHive-Project,項目名稱:Hippocampe,代碼行數:23,代碼來源:Index.py

示例3: init_state

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def init_state(self, index, host, port):
        self._queue = []
        self.index = index
        self.host = host
        self.port = port
        if host is None:
            self.es = Elasticsearch()
        else:
            self.es = Elasticsearch(hosts=[{'host': host, 'port': port}])
        self.idx_manager = IndicesClient(self.es)
        self.mapper = ESQueryMapper()

    # be persistence friendly 
開發者ID:Net-ng,項目名稱:kansha,代碼行數:15,代碼來源:elasticengine.py

示例4: perform_create_index

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def perform_create_index(indexable, logger=None):
    """
    Create a new index in ElasticSearch from an indexable instance
    """
    indices_client = IndicesClient(client=ES_CLIENT)
    # Create a new index name, suffixing its name with a timestamp
    new_index = f"{indexable.index_name:s}_{timezone.now():%Y-%m-%d-%Hh%Mm%S.%fs}"

    # Create the new index
    if logger:
        logger.info(f'Creating a new Elasticsearch index "{new_index:s}"...')
    indices_client.create(index=new_index)

    # The index needs to be closed before we set an analyzer
    indices_client.close(index=new_index)
    indices_client.put_settings(body=ANALYSIS_SETTINGS, index=new_index)
    indices_client.open(index=new_index)

    indices_client.put_mapping(
        body=indexable.mapping, doc_type=indexable.document_type, index=new_index
    )

    # Populate the new index with data provided from our indexable class
    richie_bulk(indexable.get_es_documents(new_index))

    # Return the name of the index we just created in ElasticSearch
    return new_index 
開發者ID:openfun,項目名稱:richie,代碼行數:29,代碼來源:index_manager.py

示例5: setUp

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def setUp(self):
        """
        Make sure all indices are deleted before each new test is run.
        """
        super().setUp()
        self.indices_client = IndicesClient(client=ES_CLIENT)
        self.indices_client.delete(index="_all") 
開發者ID:openfun,項目名稱:richie,代碼行數:9,代碼來源:test_index_manager.py

示例6: test_index_manager_regenerate_indices_from_broken_state

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def test_index_manager_regenerate_indices_from_broken_state(self, *args):
        """
        `regenerate_indices` should succeed and give us a working ElasticSearch
        when it runs and finds a broken state (eg. with an existing, incorrect
        index with the name of an alias).

        This can occur when ES restarts and an update signal is triggered before
        Richie had a chance to bootstrap ES.
        """
        # The indices client will be used to test the actual indices in ElasticSearch
        indices_client = IndicesClient(client=ES_CLIENT)

        # Create a course and trigger a signal to index it. This will create a
        # broken "richie_test_courses" index
        course = CourseFactory(should_publish=True)
        update_course(course.extended_object, "en")
        self.assertIsNotNone(indices_client.get("richie_test_courses"))

        # Call our `regenerate_indices command`
        creation_datetime = datetime(2010, 1, 1, tzinfo=timezone.utc)
        creation_string = creation_datetime.strftime("%Y-%m-%d-%Hh%Mm%S.%fs")
        with mock.patch.object(timezone, "now", return_value=creation_datetime):
            regenerate_indices(None)

        # No error was thrown, the courses index (like all others) was bootstrapped
        self.assertIsNotNone(
            indices_client.get(f"richie_test_courses_{creation_string}")
        )
        # The expected alias is associated with the index
        self.assertEqual(
            list(indices_client.get_alias("richie_test_courses").keys())[0],
            f"richie_test_courses_{creation_string}",
        )

    # pylint: disable=unused-argument 
開發者ID:openfun,項目名稱:richie,代碼行數:37,代碼來源:test_index_manager.py

示例7: prepare_index

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def prepare_index(self, courses):
        """
        Not a test.
        This method is doing the heavy lifting for the tests in this class:
        - prepare the Elasticsearch index,
        - execute the query.
        """
        self.create_filter_pages()
        # Index these 4 courses in Elasticsearch
        indices_client = IndicesClient(client=ES_CLIENT)
        # Delete any existing indices so we get a clean slate
        indices_client.delete(index="_all")
        # Create an index we'll use to test the ES features
        indices_client.create(index="test_courses")
        indices_client.close(index="test_courses")
        indices_client.put_settings(body=ANALYSIS_SETTINGS, index="test_courses")
        indices_client.open(index="test_courses")

        # Use the default courses mapping from the Indexer
        indices_client.put_mapping(
            body=CoursesIndexer.mapping, doc_type="course", index="test_courses"
        )
        # Add the sorting script
        ES_CLIENT.put_script(id="state", body=CoursesIndexer.scripts["state"])
        # Actually insert our courses in the index
        actions = [
            {
                "_id": course["id"],
                "_index": "test_courses",
                "_op_type": "create",
                "_type": "course",
                **course,
            }
            for course in courses
        ]
        bulk(actions=actions, chunk_size=500, client=ES_CLIENT)
        indices_client.refresh() 
開發者ID:openfun,項目名稱:richie,代碼行數:39,代碼來源:test_query_courses_edge_cases.py

示例8: setUp

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def setUp(self):
        """
        Instantiate our ES client and make sure all indices are deleted before each test
        """
        super().setUp()
        self.indices_client = IndicesClient(client=ES_CLIENT)
        self.indices_client.delete(index="_all") 
開發者ID:openfun,項目名稱:richie,代碼行數:9,代碼來源:test_partial_mappings.py

示例9: checkData

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def checkData(checkList):
	#checkList is the list of types to check

	#check if the hippocampe's index exists in ES
	#and check if ES type exists according to checkList
	logger.info('ES.checkData launched')
	logger.info(checkList)
	ES = getES()
	index = IndicesClient(ES)

	cfg = getHippoConf()
	
	indexName = cfg.get('elasticsearch', 'indexNameES')
	#references contains the name of types used in Hippocampe
	references = dict()
	references['sourceType'] = cfg.get('elasticsearch', 'typeNameESSource')
	references['newType'] = cfg.get('elasticsearch', 'typeNameESNew')
	references['jobsType'] = cfg.get('elasticsearch', 'typeNameESJobs')

	#listType = list()
	#listType.append(sourceType)
	#listType.append(newType)
	#listType.append(jobsType) 	

	#check index
	if index.exists(index = indexName):
		#check types
		for check in checkList:
			if index.exists_type(index = indexName, doc_type = references[check]):
				logger.info('index %s and type %s exist', indexName, references[check])
			else:
				logger.info('index %s exists but type %s does not', indexName, references[check] )
				return False
		return True
	else:
		logger.info('index %s does not exist', indexName)
		return False 
開發者ID:TheHive-Project,項目名稱:Hippocampe,代碼行數:39,代碼來源:ES.py

示例10: execute_query

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def execute_query(self, kind, querystring=""):
        """
        Not a test.
        This method is doing the heavy lifting for the tests in this class: create and fill the
        index with our categories so we can run our queries and check the results.
        It also executes the query and returns the result from the API.
        """
        # Index these categories in Elasticsearch
        indices_client = IndicesClient(client=ES_CLIENT)
        # Delete any existing indices so we get a clean slate
        indices_client.delete(index="_all")
        # Create an index we'll use to test the ES features
        indices_client.create(index="test_categories")
        indices_client.close(index="test_categories")
        indices_client.put_settings(body=ANALYSIS_SETTINGS, index="test_categories")
        indices_client.open(index="test_categories")

        # Use the default categories mapping from the Indexer
        indices_client.put_mapping(
            body=CategoriesIndexer.mapping, doc_type="category", index="test_categories"
        )

        # Actually insert our categories in the index
        actions = [
            {
                "_id": category["id"],
                "_index": "test_categories",
                "_op_type": "create",
                "_type": "category",
                "absolute_url": {"en": "en/url"},
                "description": {"en": "en/description"},
                "icon": {"en": "en/icon"},
                "is_meta": False,
                "logo": {"en": "en/logo"},
                "nb_children": 0,
                "path": category["id"],
                **category,
            }
            for category in CATEGORIES
        ]
        bulk(actions=actions, chunk_size=500, client=ES_CLIENT)
        indices_client.refresh()

        response = self.client.get(f"/api/v1.0/{kind:s}/?{querystring:s}")
        self.assertEqual(response.status_code, 200)

        return json.loads(response.content) 
開發者ID:openfun,項目名稱:richie,代碼行數:49,代碼來源:test_query_categories.py

示例11: execute_query

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def execute_query(self, querystring=""):
        """
        Not a test.
        This method is doing the heavy lifting for the tests in this class: create and fill the
        index with our organizations so we can run our queries and check the results.
        It also executes the query and returns the result from the API.
        """
        # Index these organizations in Elasticsearch
        indices_client = IndicesClient(client=ES_CLIENT)
        # Delete any existing indices so we get a clean slate
        indices_client.delete(index="_all")
        # Create an index we'll use to test the ES features
        indices_client.create(index="test_organizations")
        indices_client.close(index="test_organizations")
        indices_client.put_settings(body=ANALYSIS_SETTINGS, index="test_organizations")
        indices_client.open(index="test_organizations")

        # Use the default organizations mapping from the Indexer
        indices_client.put_mapping(
            body=OrganizationsIndexer.mapping,
            doc_type="organization",
            index="test_organizations",
        )

        # Actually insert our organizations in the index
        actions = [
            {
                "_id": organization["id"],
                "_index": "test_organizations",
                "_op_type": "create",
                "_type": "organization",
                "absolute_url": {"en": "en/url"},
                "description": {"en": "en/description"},
                "logo": {"en": "en/image"},
                **organization,
            }
            for organization in ORGANIZATIONS
        ]
        bulk(actions=actions, chunk_size=500, client=ES_CLIENT)
        indices_client.refresh()

        response = self.client.get(f"/api/v1.0/organizations/?{querystring:s}")
        self.assertEqual(response.status_code, 200)

        return json.loads(response.content) 
開發者ID:openfun,項目名稱:richie,代碼行數:47,代碼來源:test_query_organizations.py

示例12: execute_query

# 需要導入模塊: from elasticsearch import client [as 別名]
# 或者: from elasticsearch.client import IndicesClient [as 別名]
def execute_query(self, querystring=""):
        """
        Not a test.
        This method is doing the heavy lifting for the tests in this class: create and fill the
        index with our persons so we can run our queries and check the results.
        It also executes the query and returns the result from the API.
        """
        # Index these persons in Elasticsearch
        indices_client = IndicesClient(client=ES_CLIENT)
        # Delete any existing indices so we get a clean slate
        indices_client.delete(index="_all")
        # Create an index we'll use to test the ES features
        indices_client.create(index="test_persons")
        indices_client.close(index="test_persons")
        indices_client.put_settings(body=ANALYSIS_SETTINGS, index="test_persons")
        indices_client.open(index="test_persons")

        # Use the default persons mapping from the Indexer
        indices_client.put_mapping(
            body=PersonsIndexer.mapping, doc_type="person", index="test_persons"
        )

        # Actually insert our persons in the index
        actions = [
            {
                "_id": person["id"],
                "_index": "test_persons",
                "_op_type": "create",
                "_type": "person",
                "absolute_url": {"en": "en/url"},
                "bio": {"en": "en/bio"},
                "portrait": {"en": "en/image"},
                **person,
            }
            for person in PERSONS
        ]
        bulk(actions=actions, chunk_size=500, client=ES_CLIENT)
        indices_client.refresh()

        response = self.client.get(f"/api/v1.0/persons/?{querystring:s}")
        self.assertEqual(response.status_code, 200)

        return json.loads(response.content) 
開發者ID:openfun,項目名稱:richie,代碼行數:45,代碼來源:test_query_persons.py


注:本文中的elasticsearch.client.IndicesClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。