From fd8e3706bc7c15f4469d5d4621444f934920d0af Mon Sep 17 00:00:00 2001 From: James Turk Date: Thu, 10 May 2012 11:38:02 -0400 Subject: [PATCH] elasticsearch v1 --- oyster/ext/elasticsearch.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 oyster/ext/elasticsearch.py diff --git a/oyster/ext/elasticsearch.py b/oyster/ext/elasticsearch.py new file mode 100644 index 0000000..8b1a5a6 --- /dev/null +++ b/oyster/ext/elasticsearch.py @@ -0,0 +1,24 @@ +from celery.task.base import Task + +from ..core import kernel +from ..conf import settings + +from pyes import ES + +es = ES(settings.ELASTICSEARCH_HOST) + +class ElasticSearchPush(Task): + # results go straight to elasticsearch + ignore_result = True + + def run(self, doc_id): + doc = kernel.db.tracked.find_one({'_id': doc_id}) + text = kernel.extract_text(doc) + + self.get_logger().debug('adding {1} to ElasticSearch'.format(doc_id)) + + for i, piece in enumerate(pieces): + es.index(dict(doc['metadata'], text=text), + settings.ELASTICSEARCH_INDEX, + settings.ELASTICSEARCH_DOC_TYPE, + id=doc_id)