mozilla / elasticutils

[deprecated] A friendly chainable ElasticSearch interface for python
http://elasticutils.rtfd.org
BSD 3-Clause "New" or "Revised" License
243 stars 76 forks source link

I have encountered an issue using IP Address but querying data still uses the localhost #246

Closed ghost closed 9 years ago

ghost commented 10 years ago

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))

eire1130 commented 10 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

willkg commented 10 years ago

@alexfrndz Did the above comment help? Are you still having issues?

willkg commented 9 years ago

Assuming the reporter is fine now. Closing this out.