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


Python elasticsearch_dsl.MultiSearch方法代码示例

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


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

示例1: execute_searches

# 需要导入模块: import elasticsearch_dsl [as 别名]
# 或者: from elasticsearch_dsl import MultiSearch [as 别名]
def execute_searches(self):
        """Ejecuta la query de todas las series agregadas, e inicializa
        los atributos data y count a partir de las respuestas.
        """

        multi_search = MultiSearch(index=self.index,
                                   doc_type=settings.TS_DOC_TYPE)

        for serie in self.series:
            multi_search = multi_search.add(serie.search)

        responses = multi_search.execute()
        formatter = ResponseFormatter(self.series, responses,
                                      self.args[constants.PARAM_SORT],
                                      self.args[constants.PARAM_PERIODICITY])

        return {
            'data': (formatter.format_response()),
            'count': max([response.hits.total for response in responses])
        } 
开发者ID:datosgobar,项目名称:series-tiempo-ar-api,代码行数:22,代码来源:es_query.py

示例2: _execute_multi_search

# 需要导入模块: import elasticsearch_dsl [as 别名]
# 或者: from elasticsearch_dsl import MultiSearch [as 别名]
def _execute_multi_search(self, **kwargs):
        indices = sorted(self._index_searches.keys(), reverse = True) or self._indices

        if self.CACHED_COUNTS_KEY and not self.previous_search_results.get(self.CACHED_COUNTS_KEY):
            self.previous_search_results[self.CACHED_COUNTS_KEY] = {}

        ms = MultiSearch()
        for index_name in indices:
            start_index = 0
            if self.CACHED_COUNTS_KEY:
                if self.previous_search_results[self.CACHED_COUNTS_KEY].get(index_name):
                    index_total = self.previous_search_results[self.CACHED_COUNTS_KEY][index_name]['total']
                    start_index = self.previous_search_results[self.CACHED_COUNTS_KEY][index_name]['loaded']
                    if start_index >= index_total:
                        continue
                else:
                    self.previous_search_results[self.CACHED_COUNTS_KEY][index_name] = {'loaded': 0, 'total': 0}

            searches = self._get_paginated_searches(index_name, start_index=start_index, **kwargs)
            ms = ms.index(index_name.split(','))
            for search in searches:
                ms = ms.add(search)

        responses = self._execute_search(ms)
        parsed_responses = [self._parse_response(response) for response in responses]
        return self._process_multi_search_responses(parsed_responses, **kwargs) 
开发者ID:macarthur-lab,项目名称:seqr,代码行数:28,代码来源:es_search.py

示例3: multisearch

# 需要导入模块: import elasticsearch_dsl [as 别名]
# 或者: from elasticsearch_dsl import MultiSearch [as 别名]
def multisearch(*models, **params):
    ms = MultiSearch(using=es.client, index=es.index_name)
    queries = []
    for model in models:
        s = search_for(model, **params)
        ms = ms.add(s._s)
        queries.append(s)
    responses = ms.execute()
    return [
        # _d_ is the only way to access the raw data
        # allowing to rewrap response in a FacetedSearch
        # because default multisearch loose facets
        SearchResult(query, response._d_)
        for query, response in zip(queries, responses)
    ] 
开发者ID:opendatateam,项目名称:udata,代码行数:17,代码来源:__init__.py

示例4: __init__

# 需要导入模块: import elasticsearch_dsl [as 别名]
# 或者: from elasticsearch_dsl import MultiSearch [as 别名]
def __init__(self):
        self.field_counts = {}
        self.multi_search = MultiSearch() 
开发者ID:texta-tk,项目名称:texta,代码行数:5,代码来源:multi_search_conductor.py

示例5: _run_multisearch

# 需要导入模块: import elasticsearch_dsl [as 别名]
# 或者: from elasticsearch_dsl import MultiSearch [as 别名]
def _run_multisearch(es, searches):
    """Ejecuta una lista de búsquedas Elasticsearch utilizando la función
    MultiSearch. La cantidad de búsquedas que se envían a la vez es
    configurable vía la variable ES_MULTISEARCH_MAX_LEN.

    Args:
        es (Elasticsearch): Conexión a Elasticsearch.
        searches (list): Lista de elasticsearch_dsl.Search.

    Raises:
        DataConnectionException: Si ocurrió un error al ejecutar las búsquedas.

    Returns:
        list: Lista de respuestas a cada búsqueda.

    """
    step_size = constants.ES_MULTISEARCH_MAX_LEN
    responses = []

    # Partir las búsquedas en varios baches si es necesario.
    for i in range(0, len(searches), step_size):
        end = min(i + step_size, len(searches))
        ms = MultiSearch(using=es)

        for j in range(i, end):
            ms = ms.add(searches[j])

        try:
            responses.extend(ms.execute(raise_on_error=True))
        except elasticsearch.ElasticsearchException as e:
            raise DataConnectionException() from e

    return responses 
开发者ID:datosgobar,项目名称:georef-ar-api,代码行数:35,代码来源:data.py

示例6: get_multi_search

# 需要导入模块: import elasticsearch_dsl [as 别名]
# 或者: from elasticsearch_dsl import MultiSearch [as 别名]
def get_multi_search(self):
        multi_search = MultiSearch()
        search = self.get_search()
        multi_search = multi_search.add(search)

        if self.args.get(constants.PARAM_AGGREGATIONS) is not None:
            multi_search = self.add_terms_aggregations(multi_search)

        return multi_search 
开发者ID:datosgobar,项目名称:series-tiempo-ar-api,代码行数:11,代码来源:query.py

示例7: test_no_querystring_is_valid

# 需要导入模块: import elasticsearch_dsl [as 别名]
# 或者: from elasticsearch_dsl import MultiSearch [as 别名]
def test_no_querystring_is_valid(self):
        query = FieldSearchQuery(args={})

        with mock.patch.object(MultiSearch, 'execute', return_value=get_mock_search()):
            result = query.execute()

        self.assertFalse(result.get('errors')) 
开发者ID:datosgobar,项目名称:series-tiempo-ar-api,代码行数:9,代码来源:query_tests.py

示例8: test_query_response_size

# 需要导入模块: import elasticsearch_dsl [as 别名]
# 或者: from elasticsearch_dsl import MultiSearch [as 别名]
def test_query_response_size(self):
        query = FieldSearchQuery(args={'q': 'aceite'})

        with mock.patch.object(MultiSearch, 'execute', return_value=get_mock_search()):
            result = query.execute()

        self.assertEqual(len(result['data']), result['count']) 
开发者ID:datosgobar,项目名称:series-tiempo-ar-api,代码行数:9,代码来源:query_tests.py

示例9: test_response_params

# 需要导入模块: import elasticsearch_dsl [as 别名]
# 或者: from elasticsearch_dsl import MultiSearch [as 别名]
def test_response_params(self):
        limit = '10'
        offset = '15'
        query = FieldSearchQuery(args={'q': 'aceite',
                                       'limit': limit,
                                       'start': offset})

        with mock.patch.object(MultiSearch, 'execute', return_value=get_mock_search()):
            result = query.execute()

        self.assertEqual(result['limit'], int(limit))
        self.assertEqual(result['start'], int(offset)) 
开发者ID:datosgobar,项目名称:series-tiempo-ar-api,代码行数:14,代码来源:query_tests.py

示例10: run_searches

# 需要导入模块: import elasticsearch_dsl [as 别名]
# 或者: from elasticsearch_dsl import MultiSearch [as 别名]
def run_searches(es, searches):
        """Ejecuta una lista de búsquedas ElasticsearchSearch.

        Para ejecutar las búsquedas, se obtiene un iterador de búsquedas
        elasticsearch_dsl.Search por cada elemento de 'searches'. Utilizando
        los iteradores, se construyen listas de elasticsearch_dsl.Search, que
        son luego ejecutadas utilizando '_run_multisearch'. Después, los
        resultados son devueltos a cada iterador, que pueden o no generar una
        nueva búsqueda elasticsearch_dsl.Search. El proceso se repite hasta que
        todos los iteradores hayan finalizado. Con todo este proceso se logra:

            1) Ejecutar cualquier tipo de búsquedas bajo una mismas interfaz.
            2) Ejecutar búsquedas que requieren distintas cantides de pasos
               bajo una misma interfaz.
            3) Utilizar la funcionalidad de MultiSearch para hacer la menor
               cantidad de consultas posible a Elasticsearch.

        Los resultados de cada búsqueda pueden ser accedidos vía el campo
        '.result' de cada una.

        Args:
            es (Elasticsearch): Conexión a Elasticsearch.
            searches (list): Lista de búsquedas ElasticsearchSearch o
                derivados. La lista puede ser de cualquier largo ya que sus
                contenidos son fraccionados por '_run_multisearch' para evitar
                consultas demasiado extensas a Elasticsearch.

        """
        iterators = [search.search_steps() for search in searches]
        iteration_data = []
        for iterator in iterators:
            search = utils.step_iterator(iterator)

            if search:
                iteration_data.append((iterator, search))

        while iteration_data:
            responses = _run_multisearch(es, [
                search for _, search in iteration_data
            ])

            iterators = (iterator for iterator, _ in iteration_data)
            iteration_data = []

            for iterator, response in zip(iterators, responses):
                search = utils.step_iterator(iterator, response)
                if search:
                    iteration_data.append((iterator, search)) 
开发者ID:datosgobar,项目名称:georef-ar-api,代码行数:50,代码来源:data.py


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