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


Python elasticsearch_dsl.A屬性代碼示例

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


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

示例1: _get_markets_with_dsl

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def _get_markets_with_dsl(self, from_date, to_date):
        # TODO: This could be fixed now as ES has closed the issue:
        # https://github.com/elastic/elasticsearch-dsl-py/issues/963

        s = Search(using='operations', index="bitshares-*")
        s = s.extra(size=0)
        s = s.query('bool', filter = [
            Q('term', operation_type=4),
            Q("range", block_data__block_time={'gte': from_date, 'lte': to_date})
        ])

        sources = [ 
            { 'base': A('terms', field='operation_history.op_object.fill_price.base.asset_id.keyword') },
            { 'quote': A('terms', field='operation_history.op_object.fill_price.quote.asset_id.keyword') }
        ]

        # Bug here as 'sources' does not support a list.
        a = A('composite', sources=sources, size=10000).metric('volume', 'sum', field='operation_history.op_object.fill_price.quote.amount')
        s.aggs.bucket('pairs', a)
        response = s.execute()

        # TODO... 
開發者ID:bitshares,項目名稱:bitshares-explorer-api,代碼行數:24,代碼來源:bitshares_elasticsearch_client.py

示例2: get_daily_volume

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def get_daily_volume(self, from_date, to_date):
        s = Search(using='operations', index="bitshares-*")
        s = s.extra(size=0)
        s = s.query('bool', filter = [
            Q('term', operation_type=4),
            Q('range', block_data__block_time={'gte': from_date, 'lte': to_date}),
            Q('term', operation_history__op_object__fill_price__quote__asset_id__keyword=config.CORE_ASSET_ID)
        ])

        a = A('date_histogram', field='block_data.block_time', interval='1d', format='yyyy-MM-dd') \
                .metric('volume', 'sum', field='operation_history.op_object.fill_price.quote.amount')
        s.aggs.bucket('volume_over_time', a)

        response = s.execute()

        daily_volumes = []
        for daily_volume in response.aggregations.volume_over_time.buckets:
            daily_volumes.append({ 'date': daily_volume.key_as_string, 'volume': daily_volume.volume.value })
        
        return daily_volumes 
開發者ID:bitshares,項目名稱:bitshares-explorer-api,代碼行數:22,代碼來源:bitshares_elasticsearch_client.py

示例3: get_elasticsearch_index_samples

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def get_elasticsearch_index_samples(elasticsearch_index, dataset_type=Sample.DATASET_TYPE_VARIANT_CALLS):
    es_client = get_es_client()

    index_metadata = get_index_metadata(elasticsearch_index, es_client).get(elasticsearch_index)

    s = elasticsearch_dsl.Search(using=es_client, index=elasticsearch_index)
    s = s.params(size=0)
    s.aggs.bucket('sample_ids', elasticsearch_dsl.A('terms', field=SAMPLE_FIELDS_MAP[dataset_type], size=10000))
    response = s.execute()
    return [agg['key'] for agg in response.aggregations.sample_ids.buckets], index_metadata 
開發者ID:macarthur-lab,項目名稱:seqr,代碼行數:12,代碼來源:dataset_utils.py

示例4: get_most_loaned_documents

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def get_most_loaned_documents(from_date, to_date, bucket_size):
    """Return aggregation of document_pids with most loans."""
    search_cls = current_circulation.loan_search_cls

    # Query
    states = (
        current_app.config["CIRCULATION_STATES_LOAN_ACTIVE"]
        + current_app.config["CIRCULATION_STATES_LOAN_COMPLETED"]
    )

    from_date = from_date or None
    to_date = to_date or None

    search = search_cls().query(
        "bool",
        must=[
            Q("terms", state=states),
            Q("range", start_date=dict(gte=from_date, lte=to_date)),
        ],
    )

    # Aggregation with sub-aggregation to calculate the extension count sum
    aggs = A("terms", field="document_pid", size=bucket_size)
    aggs = aggs.metric("extensions", "sum", field="extension_count")
    search.aggs.bucket("most_loaned_documents", aggs)

    # No need for the loan hits
    search = search[:0]

    return search 
開發者ID:inveniosoftware,項目名稱:invenio-app-ils,代碼行數:32,代碼來源:search.py

示例5: get_aggregation

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def get_aggregation(self):
        field = self._params['field']
        a = A('nested', path=field)
        a.metric('min_start', 'min', field='{0}.start'.format(field))
        a.metric('max_end', 'max', field='{0}.end'.format(field))
        return a 
開發者ID:opendatateam,項目名稱:udata,代碼行數:8,代碼來源:fields.py

示例6: as_request_parser_kwargs

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def as_request_parser_kwargs(self):
        return {
            'type': self.validate_parameter,
            'help': _('A date range expressed as start-end '
                      'where both dates are in iso format '
                      '(ie. YYYY-MM-DD-YYYY-MM-DD)')
        } 
開發者ID:opendatateam,項目名稱:udata,代碼行數:9,代碼來源:fields.py

示例7: test_aggregation

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def test_aggregation(self):
        expected = A({'terms': {'field': 'boolean'}})
        assert self.facet.get_aggregation() == expected 
開發者ID:opendatateam,項目名稱:udata,代碼行數:5,代碼來源:test_facets.py

示例8: test_get_aggregation

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def test_get_aggregation(self):
        expected = A({
            'nested': {
                'path': 'some_field'
            },
            'aggs': {
                'min_start': {'min': {'field': 'some_field.start'}},
                'max_end': {'max': {'field': 'some_field.end'}}
            }
        })
        assert self.facet.get_aggregation() == expected 
開發者ID:opendatateam,項目名稱:udata,代碼行數:13,代碼來源:test_facets.py

示例9: add_default_aggregation

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def add_default_aggregation(s):
    a = A("terms", field="request.url.keyword", size=args.size)
    s.aggs.bucket("urls", a) 
開發者ID:thomaspatzke,項目名稱:WASE,代碼行數:5,代碼來源:WASEQuery.py

示例10: get_statistics

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def get_statistics(index,pattern=None):
	conn = connections.get_connection()
	stats = {}
	fields = {
			'computer_name.keyword':'computers',
			'strings_parsed.source_user_name.keyword': 'srcuser',
			'strings_parsed.target_user_name.keyword': 'dstuser',
			'strings_parsed.target_machine_name.keyword': 'dstsrvname',
			'strings_parsed.target_machine_ip.keyword': 'dstsrvip',
		}
	scheme = {
			"size" : 0,
			"aggs" : {
			"count" : {
				"cardinality" : {
					"field" : None
					}
				}
			}
		}

	s = Search(using=conn,index=index)
	for f in fields.keys():
		s.aggs.bucket(fields[f],A('cardinality',field=f))
	resp = s.execute()
	res = resp.aggregations.to_dict()
	for agg in res.keys():
		stats[agg] = res[agg]['value']

	stats['total'] = resp['hits']['total']
	return stats 
開發者ID:THIBER-ORG,項目名稱:userline,代碼行數:33,代碼來源:utils.py

示例11: test_scan_aggs_exhausts_all_files

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def test_scan_aggs_exhausts_all_files(data_client):
    s = Search(index='flat-git')
    key_aggs = {'files': A('terms', field='files')}
    file_list = list(scan_aggs(s, key_aggs))

    assert len(file_list) == 26 
開發者ID:elastic,項目名稱:elasticsearch-dsl-py,代碼行數:8,代碼來源:test_composite_aggs.py

示例12: test_scan_aggs_with_multiple_aggs

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def test_scan_aggs_with_multiple_aggs(data_client):
    s = Search(index='flat-git')
    key_aggs = [
        {'files': A('terms', field='files')},
        {'months': {'date_histogram': {'field': 'committed_date', 'interval': 'month'}}},
    ]
    file_list = list(scan_aggs(s, key_aggs))

    assert len(file_list) == 47 
開發者ID:elastic,項目名稱:elasticsearch-dsl-py,代碼行數:11,代碼來源:test_composite_aggs.py

示例13: _get_aggregation

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def _get_aggregation(self, **extra):
        params = {'field': self.field}
        params.update(self.kwargs)
        params.update(extra)
        return A('terms', **params) 
開發者ID:imsweb,項目名稱:django-seeker,代碼行數:7,代碼來源:facets.py

示例14: apply

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def apply(self, search, **extra):
        top = A('global')
        top[self.field] = self._get_aggregation(**extra)
        search.aggs[self.field] = top
        return search 
開發者ID:imsweb,項目名稱:django-seeker,代碼行數:7,代碼來源:facets.py

示例15: handle_composition_aggregation

# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import A [as 別名]
def handle_composition_aggregation(search: Search, aggregation_dict: dict, after: dict):
        s = Search().from_dict(search).using(Elasticsearch(es_url))
        sources = aggregation_dict["sources"]
        size = aggregation_dict.get("size", 10)

        aggregations = [{source["bucket_name"]: A(source["agg_type"], field="{}.keyword".format(source["field"]))} for source in sources]
        if after:
            s.aggs.bucket(aggregation_dict["bucket_name"], "composite", size=size, sources=aggregations, after=after)
            return s
        else:
            s.aggs.bucket(aggregation_dict["bucket_name"], "composite", size=size, sources=aggregations)
            return s 
開發者ID:texta-tk,項目名稱:texta,代碼行數:14,代碼來源:es_manager.py


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