Commit 7fb2037b authored by godog's avatar godog

port to latest pyes 0.90 API

parent ecd2f4a7
import datetime
import logging
import os
import pyes
import threading
import time
from lens2 import utils
import pyes
import pyes.utils
import pprint
log = logging.getLogger(__name__)
......@@ -34,28 +36,27 @@ class LogStore(object):
def __init__(self, server_list, timeout=60):
self.conn = pyes.ES(server_list, timeout=timeout,
autorefresh=True,
bulk_size=self.BULK_SIZE)
try:
self.conn.open_index(self.INDEX)
self.conn.indices.open_index(self.INDEX)
log.info('opened index "%s"', self.INDEX)
except pyes.exceptions.IndexMissingException:
self._init()
def clear(self):
""""Remove the entire index."""
self.conn.delete_index(self.INDEX)
self.conn.indices.delete_index(self.INDEX)
def get_status(self):
"""Return the index status."""
status = self.conn.status(indexes=[self.INDEX])
status = self.conn.indices.status(indexes=[self.INDEX])
return status['indices'][self.INDEX]
def _init(self):
"""Create the index and set up the schema."""
log.info('creating index "%s"', self.INDEX)
self.conn.create_index_if_missing(self.INDEX)
self.conn.indices.create_index_if_missing(self.INDEX)
default_mappings = {
'log': {
'_source': {
......@@ -83,7 +84,7 @@ class LogStore(object):
}
self.conn._send_request(
'PUT',
self.conn._make_path(['_template', 'tpl1']),
pyes.utils.make_path('_template', 'tpl1'),
template)
log_mapping = {
'timestamp': {
......@@ -122,7 +123,7 @@ class LogStore(object):
'term_vector': 'with_positions_offsets',
},
}
self.conn.put_mapping('log', {'properties': log_mapping}, self.INDEX)
self.conn.indices.put_mapping('log', {'properties': log_mapping}, self.INDEX)
def insert(self, line_or_lines, parser, filters=None):
"""Insert one or more logs.
......@@ -218,12 +219,11 @@ class LogStore(object):
else:
search.facet.add_term_facet(f, size=fsize)
response = self.conn.search(search,
search_type='query_then_fetch')
total = response['hits']['total']
docs = [x['_source'] for x in response['hits']['hits']]
result_facets = response.get('facets') if facets else {}
return docs, total, result_facets, response['took']
result = self.conn.search(search, model=lambda x,y: y,
search_type='query_then_fetch', indices=self.INDEX)
docs = [x['_source'] for x in result]
result_facets = result.facets if facets else {}
return docs, result.total, result_facets, result.took
def scan(self, query_str, time_range, size=100):
log.info('scan: "%s"', query_str)
......
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