Commit cba64792 authored by ale's avatar ale

use a scan, not a search, for queries

parent 0285ed35
......@@ -6,6 +6,8 @@ import threading
import time
from lens2 import utils
import pprint
log = logging.getLogger(__name__)
......@@ -149,7 +151,7 @@ class LogStore(object):
self.conn.deleteByQuery(q)
self.conn.optimize(self.INDEX)
def search(self, query_str, time_range):
def scan(self, query_str, time_range):
log.info('search: "%s"', query_str)
query = pyes.query.StringQuery(query_str)
if time_range:
......@@ -160,10 +162,11 @@ class LogStore(object):
f = pyes.filters.NumericRangeFilter(trange)
query = pyes.query.FilteredQuery(query, f)
search = pyes.query.Search(query, track_scores=False,
search = pyes.query.Search(query, track_scores=False, size=100,
sort={'timestamp': 'asc'})
results = self.conn.search(search)
print results
return (x['_source'] for x in results['hits']['hits'])
results = self.conn.scan(search)
for batch in results:
for doc in batch['hits']['hits']:
yield doc['_source']
......@@ -58,7 +58,7 @@ def do_search(lens, opts, args):
time_range = None
if opts.time_range:
time_range = utils.parse_time_range(opts.time_range)
for doc in lens.search(query, time_range):
for doc in lens.scan(query, time_range):
sys.stdout.write(utils.format_log(doc).encode('utf-8', 'replace'))
sys.stdout.flush()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment