当前位置: 首页>>代码示例>>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;未经允许,请勿转载。