Beispiel #1
0
    def setUp(self):
        self.body_build = SearchBodyBuild()
        self.body_build.range('time', 'start', 'end')\
                       .must('ip', '10.10.0.0')\
                       .groupby_date('time', '1d')\
                       .groupby('domain')\
                       .sum('pv')

        self.res = {
            'hits': {},
            '_shards': {},
            'took': 100,
            'aggregations': {
                'time-date_histogram': {
                    'buckets': [
                        {
                            'domain-terms': {
                                'buckets': [
                                    {
                                        'pv-sum': {
                                            'value': 2000
                                        },
                                        'key': 'www.xxxx.com',
                                        'doc_count': 1000
                                    }
                                ],
                                'sum_other_doc_count': 0,
                                'doc_count_error_upper_bound': 0
                            },
                            'key_as_string': '1111-11-11',
                            'key': 11111111,
                            'doc_count': 11111111
                        },
                        {
                            'domain-terms': {
                                'buckets': [
                                    {
                                        'pv-sum': {
                                            'value': 2000
                                        },
                                        'key': 'www.xxxx.com',
                                        'doc_count': 1000
                                    }
                                ],
                                'sum_other_doc_count': 0,
                                'doc_count_error_upper_bound': 0
                            },
                            'key_as_string': '2222-22-22',
                            'key': 22222222,
                            'doc_count': 22222222
                        }
                    ],
                }
            }
        }
        self.pre_parser = parse_aggs.parse(self.body_build, self.res)
Beispiel #2
0
 def setUp(self):
     self.esbody = SearchBodyBuild()
     self.testquery = {
         'query': {
             'bool': {
                 'must': [
                     {
                         'bool': {
                             'should': []
                         }
                     },
                 ]
             }
         }
     }
     self.testaggs = {}
Beispiel #3
0
import datetime
from esearch.query import SearchBodyBuild
from esearch import parse_aggs

# Construct the search body
body_build = SearchBodyBuild()
end = datetime.datetime.now()
start = end - datetime.timedelta(days=10)

body = body_build.range('time', start, end)\
                 .must('ip', '10.10.0.0')\
                 .groupby_date('time', '1d')\
                 .groupby('domain')\
                 .sum('pv')\
                 .get_body()

print body

# Search
# import elasticsearch
# es_client = elasticsearch.Elasticsearch()
# res = es_client.search(index='test', body=body, doc_type='test')
res = {
    'hits': {},
    '_shards': {},
    'took': 100,
    'aggregations': {
        'time-date_histogram': {
            'buckets': [{
                'domain-terms': {
                    'buckets': [{