コード例 #1
0
ファイル: test_api.py プロジェクト: rismalrv/ElasticQuery
    def test_nested_aggregate(self):
        q = ElasticQuery()
        q.aggregate(Aggregate.terms('agg_name', 'field').aggregate(
            Aggregate.sum('sub_agg_name', 'sub_field')
        ))

        assert_equal(self, q.dict(), {
            'aggregations': {
                'agg_name': {
                    'terms': {
                        'field': 'field'
                    },
                    'aggregations': {
                        'sub_agg_name': {
                            'sum': {
                                'field': 'sub_field'
                            }
                        }
                    }
                }
            }
        })
コード例 #2
0
test('Aggregate.stats', aggregate, AGGREGATES['STATS'])

aggregate = Aggregate.extended_stats('field_name1')
test('Aggregate.extended_stats', aggregate, AGGREGATES['EXTENDED_STATS'])

aggregate = Aggregate.histogram('field_name1', interval=100)
test('Aggregate.histogram', aggregate, AGGREGATES['HISTOGRAM'])

aggregate = Aggregate.date_histogram('field_name1')
test('Aggregate.date_histogram', aggregate, AGGREGATES['DATE_HISTOGRAM'])

aggregate = Aggregate.terms('field_name1')
test('Aggregate.terms', aggregate, AGGREGATES['TERMS'])

aggregate = Aggregate.sub(Aggregate.terms('field_name1'),
                          **{'sub_aggregate1': Aggregate.sum('sub_field1')})
test('Aggregate.sum + sub aggregate', aggregate, AGGREGATES['SUB_AGGREGATES'])

aggregate = Aggregate.sub(
    Aggregate.filter(musts=[Filter.term(**{'key': 'value'})]), **{
        'price_histogram':
        Aggregate.sub(
            Aggregate.terms('bp_now'),
            **{'option_count': Aggregate.sum('option_count_current')})
    })
test('Aggregate.filter + sub aggregate', aggregate,
     AGGREGATES['FILTER_SUB_AGGREGATES'])

# Queries
QUERIES = {
    'RANGE_AGGTERMS_AGGSTATS': {