Closed ghost closed 9 years ago
The get_es function returns the underlying python-elasticsearch object that elasticutils uses.
What you want to do is something like this:
import elasticutils
def get_s(index=settings.ES_CASTING_INDEX, doctype=settings.ES_DEFAULT_TYPE):
return elasticutils.S().indexes(index).doctypes(doctype)\
.es(urls=settings.ELASTICSEARCH)
Everytime you need an S, just call get_es (And define all those fun settings above).
In your case, you're creating an ElasticSearch object, which is cool, but then you do nothing with it the es variable). Even so, you would still have to do all the heavy lifting yourself, which is why you want to use S to begin with.
See documentation here for get_es:
http://elasticutils.readthedocs.org/en/latest/api.html#elasticutils.get_es
@alexfrndz Did the above comment help? Are you still having issues?
Assuming the reporter is fine now. Closing this out.
from elasticsearch import Elasticsearch
from elasticutils import get_es, S es = Elasticsearch() from elasticsearch.helpers import bulk_index
URL = '172.16.91.142:9200' INDEX = 'fooindex' DOCTYPE = 'testdoc'
es = get_es(urls=[URL])
mapping = { DOCTYPE: { 'properties': { 'id': {'type': 'integer'}, 'title': {'type': 'string', 'analyzer': 'snowball'}, 'topics': {'type': 'string'}, 'product': {'type': 'string', 'index': 'not_analyzed'}, } } }
s = S().query(title__match='Websites') for obj in s.execute(): print obj['id']
Elasticsearch.exceptions.ConnectionError: ConnectionError(HTTPConnectionPool(host='localhost', port=9200): Max retries exceeded with url: /_search (Caused by <class 'socket.error'>: [Errno 61] Connection refused)) caused by: MaxRetryError(HTTPConnectionPool(host='localhost', port=9200): Max retries exceeded with url: /_search (Caused by <class 'socket.error'>: [Errno 61] Connection refused))