haystack elasticsearch connection refused - django

When I run python manage.py rebuild_index I get the following error:
Failed to clear Elasticsearch index:
HTTPConnectionPool(host='127.0.0.1', port=9200): Max retries exceeded
with url: /haystack (Caused by : [Errno 111]
Connection refused)
My elasticsearch setting:
> HAYSTACK_CONNECTIONS = {
> 'default': {
> 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
> 'URL': 'http://127.0.0.1:9200/',
> 'INDEX_NAME': 'haystack',
> }, }
It is worth to mention that I have indexed my data once before and all things went correct but I dont know why when came back to project and restarted django project it went wrong!
Thanks in advence

It looks like you've forgotten to start ElasticSearch when you've returned to the project because the local connection is refused.
If you installed from the .deb file, then it should be wired into Ubuntu's service command so you can start it with
$ sudo service elasticsearch start
If you used the tarball, make sure you start it with something like:
$ bin/elasticsearch
More information in Installation docs http://www.elasticsearch.org/guide/reference/setup/installation/

In my case this was solved by just increasing the default timeout of 10s to 60s.
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'index_name',
'TIMEOUT' : 60
},

Related

ElastiCache(redis) cluster mode enabled with django

I configured ElastiCache redis with cluster mode enabled.
I want to connect ElastiCache with local Django.
So I configured bastion host.
I connected ElastiCache(non-cluster mode) with local Django. I tried cache.set(), cache.get(). It's OK.
I installed 'Django-redis-cache' and 'settings.py' is like that.
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': 'localhost:6379',
}
}
But I have problem when I connect ElastiCache(cluster mode) with django.
I tried tunneling with ElastiCache configuration endpoint.
When I use the same 'settings.py', error message is like that.
'SELECT is not allowed in cluster mode'
So, I changed 'settings.py'.
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': 'localhost:6379',
'OPTIONS': {
'DB': 0
},
}
}
And then, error message is like that.
'MOVED 4205 xx.xx.xx.xxx:6379'
What I have to do?
There are no example which connect ElastiCache(cluster mode) with Django.

Error in Postgresql: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "TheGecko"

Im trying to use PostgreSQL with django and I get that error when running python3 manage.py migrate:
connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "TheGecko"
I was following this guide:https://djangocentral.com/using-postgresql-with-django/
Here is my settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'websitedb',
'USER':'TheGecko',
'PASSWORD':'xx',
'HOST':'localhost',
'PORT':5432,
}
}
Also, even though I entered that line: GRANT ALL PRIVILEGES ON DATABASE websitedb TO TheGecko;, when I do \l, I get this output. Shouldn't the owner be TheGecko?
I've looked over the web and nothing I could read worked for me.
Please help.
I also revieved same error and resolved by doing below changes:
DATABASES = { 'default': { 'ENGINE':
'django.db.backends.postgresql', 'NAME': 'websitedb',
'USER':'postgres', 'PASSWORD':'xx', 'HOST':'localhost',
'PORT':'5432', } }

GCP, Django problem connection refused when trying to connect to the server

My django project runns normally on localhost and on heroku also, but when I deployed it to google cloud platform I am getting this error:
could not connect to server: Connection refused
Is the server running locally and accepting connections on Unix domain socket "/cloudsql/<connection_name>/.s.PGSQL.5432"?
The connection to the database in settings.py looks like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'database_name',
'USER': 'postgres',
'PASSWORD': "password",
# production
'HOST': '/cloudsql/connection_name',
'PORT': '5432',
}
Additionally, my app.yaml looks like
runtime: python37
handlers:
- url: /static
static_dir: static/
- url: /.*
script: auto
env_variables:
DJANGO_SETTINGS_MODULE: fes_app.settings
requirements.txt looks like this plus
sqlparse==0.4.2
toml==0.10.2
uritemplate==4.1.1
urllib3==1.25.11
whitenoise==5.2.0
twilio==6.9.0
I have tried using the binary version of psycopg, also gave a role client sql to the service account in the cloud.
**NOTE : ** I am using an app engine standard environment
Likely need more information to help you out, but did you follow the tutorial below in the official Google Docs? That's usually how I get started and then I make modifications from there.
I would compare how Google is deploying a Django app to your own settings and see what's missing. For example, your requirements.txt file does not look complete (unless you only pasted part of it) so I would start there.
https://cloud.google.com/python/django/appengine

Django Haystack connection error using http authentication

I'm using Haystack to connect and interact with an installation of elasticsearch. Elasticsearch is installed on a different box to the main webserver.
I have set up HTTP authentication on the elasticsearch box using nginx. This is to stop unauthorised access to elasticsearch.
The Haystack config looks like this:
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://USERNAME:PASSWORD#DOMAIN:PORT/',
'INDEX_NAME': 'haystack',
},
}
With this set up I get a connection error:
elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection aborted.',
gaierror(-2, 'Name or service not known'))) caused by: ProtocolError(('Connection
aborted.', gaierror(-2, 'Name or service not known')))
If I turn off HTTP authentication and update the URL correspondingly to http://DOMAIN:PORT/ it connects without a problem.
Could it be that Haystack (or elasticsearch-py (http://www.elasticsearch.org/guide/en/elasticsearch/client/python-api/current/) doesn't allow HTTP authentication to be used in the URL? I notice this is a problem with Solr - Solr authentication (using Django Haystack)
For others with the same problem, add kwargs to config:
'KWARGS': {
'port': parsed.port,
'http_auth': (parsed.username, parsed.password),
}
See: https://github.com/toastdriven/django-haystack/issues/1046

Setting up elasticsearch with Haystack

I used to be using Whoosh as a search backend but now I'm switching to elasticsearch and trying to get things working.
When trying to rebuild the index I get the error:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /_bulk?op_type=create (Caused by <class 'socket.error'>: [Errno 61] Connection refused)
The following is in my settings.py:
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://localhost:8000/',
'INDEX_NAME': 'haystack',
},
}
My question is, what is URL used for and what do I put here? I'm running things locally for development and I'm deployed on Heroku.
The port should be 9200.
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}
Also, you have to be sure that you are using the development version (2.0) of haystack.
Edit:
You probably want to make sure first that ElasticSearch is running by executing the following command:
curl -XGET 'http://127.0.0.1:9200/my_index/_mapping?pretty=1'