class Scroll(): @staticmethod def __get_url(hashid, name): return f'/api/v2/search_engines/{hashid}/indices/{name}/items/' def __init__(self, hashid, name, rpp=None, **opts): super(Scroll, self).__init__() self.scroll_id = None self.rpp = rpp self.hashid = hashid self.name = name self.api_client = ManagementAPIClient(**opts) def __iter__(self): scroll_page = self.new() while scroll_page['items']: for item in scroll_page['items']: yield item scroll_page = self.__next_with_retry() def __next_with_retry(self): tries = 0 while True: try: return self.next() except TooManyRequestsError: if tries < 3: tries += 1 sleep(1) else: raise @property def _query_params(self): params = {} if self.scroll_id: params['scroll_id'] = self.scroll_id if self.rpp: params['rpp'] = self.rpp return params def new(self): scroll_page = self.api_client.get( self.__get_url(self.hashid, self.name), self._query_params) self.scroll_id = scroll_page['scroll_id'] return scroll_page def next(self): return self.api_client.get(self.__get_url(self.hashid, self.name), self._query_params)
def searches(from_, to, hashids=None, device=None, query_name=None, source=None, total_hits=None, tz=None, format_=None, **opts): """ Return number of searches in a period grouped by date. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'device': device, 'query_name': query_name, 'source': source, 'total_hits': total_hits, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/searches', query_params)
def searches_top(from_, to, hashids=None, device=None, query_name=None, exclude=None, total_hits=None, tz=None, format_=None, **opts): """ Returns list of most common searches in a period. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'device': device, 'query_name': query_name, 'exclude': exclude, 'total_hits': total_hits, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/searches/top', query_params)
def inits(from_, to, hashids=None, device=None, tz=None, format_=None, **opts): """ Returns number of total unique search sessions in a period group by date. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'device': device, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/inits', query_params)
def sales(from_, to, hashids=None, tz=None, format_=None, **opts): """ Returns the total price for sales checkouts in a period, where session_id identifies every sale. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/sales', query_params)
def usage(from_, to, hashids=None, type_=None, format_=None, **opts): """ Returns usage to search engines during a period. It sums the query and API requests made to the service. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'type': type_, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/usage', query_params)
def facets_top(from_, to, hashids=None, tz=None, format_=None, **opts): """ Returns most common facets filters used, how many times they have been used, and which filter has been applied in a period. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/facets/top', query_params)
def facets(from_, to, hashids=None, tz=None, format_=None, **opts): """ Returns how many times facets filters have been used in a period, grouped by facet field name. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/facets', query_params)
def clicks(from_, to, hashids=None, device=None, tz=None, format_=None, **opts): """ Returns number of times a user clicked an item in a period grouped by date. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'device': device, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/clicks', query_params)
def inits_locations(from_, to, hashids=None, device=None, tz=None, format_=None, **opts): """ Returns all unique sessions geolocation(longituted and latitude pairs) for a period. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'device': device, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/inits/locations', query_params)
def redirects(from_, to, hashids=None, redirect_id=None, tz=None, format_=None, **opts): """ Returns how many times users have been redirected by a custom redirections, and to which url in a period. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'id': redirect_id, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/redirects', query_params)
def banners(from_, to, hashids=None, banner_id=None, tz=None, format_=None, **opts): """ Returns how many times banners have been displayed and clicked in a period, grouped by banner id. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'id': banner_id, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/banners', query_params)
def clicked_items_searches(from_, to, dfid, hashids=None, device=None, tz=None, format_=None, **opts): """ Returns the most common searched for a clicked item, and how many times it has been clicked from those searches. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'dfid': dfid, 'hashid': hashids, 'device': device, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/clicked_items/searches', query_params)
def clicked_items(from_, to, hashids=None, query=None, device=None, limit=None, tz=None, format_=None, **opts): """ Returns most commonly clicked items in a period. """ query_params = parse_query_params({ 'from': from_, 'to': to, 'hashid': hashids, 'query': query, 'device': device, 'limit': limit, 'tz': tz, 'format': format_ }) api_client = ManagementAPIClient(**opts) return api_client.get('/api/v2/stats/clicked_items', query_params)
def searchengine_mappings(searchengine_hashid, indices=None, **opts): api_client = ManagementAPIClient(**opts) return api_client.get( _get_searchengine_url(searchengine_hashid) + '/mappings', query_params=parse_query_params({'indices': indices}))
def get(hashid, name, item_id, temp=False, **opts): api_client = ManagementAPIClient(**opts) return api_client.get(_get_item_url(hashid, name, item_id, temp))
def searchengine_stats_blocked_ips(searchengine_hashid, **opts): api_client = ManagementAPIClient(**opts) return api_client.get( _get_searchengine_url(searchengine_hashid) + '/stats_blocked_ips')
def get(hashid, **opts): api_client = ManagementAPIClient(**opts) return api_client.get(_get_searchengine_url(hashid))
def list(**opts): api_client = ManagementAPIClient(**opts) return api_client.get(_get_searchengines_url())
def get_process_status(hashid, **opts): api_client = ManagementAPIClient(**opts) return api_client.get(_get_process_url(hashid))
def list(hashid, **opts): api_client = ManagementAPIClient(**opts) return api_client.get(_get_indices_url(hashid))
def get(hashid, name, **opts): api_client = ManagementAPIClient(**opts) return api_client.get(_get_index_url(hashid, name))
def get_reindex_status(hashid, name, **opts): api_client = ManagementAPIClient(**opts) return api_client.get(_get_index_url(hashid, name) + '/_reindex_to_temp')
def facets_terms(searchengine_hashid, fields, **opts): api_client = ManagementAPIClient(**opts) return api_client.get(_get_searchengine_url(searchengine_hashid) + '/facets_terms', query_params=parse_query_params({'fields': fields}))