kopia lustrzana https://github.com/wagtail/wagtail
Ref issue 177, Elasticsearch timeout on Travis: Support passing configuration arguments to Elasticsearch. Also documenting Elasticsearch setup in Wagtail.
rodzic
9bbe3f1c19
commit
580e9130ad
|
@ -220,6 +220,30 @@ The default DB search backend uses Django's ``__icontains`` filter.
|
||||||
|
|
||||||
Elasticsearch Backend
|
Elasticsearch Backend
|
||||||
`````````````````````
|
`````````````````````
|
||||||
|
Prerequisites are the Elasticsearch service itself and, via pip, the `elasticutils`_ and `pyelasticsearch`_ packages:
|
||||||
|
|
||||||
|
.. code-block:: guess
|
||||||
|
|
||||||
|
pip install elasticutils pyelasticsearch
|
||||||
|
|
||||||
|
NB: The dependency on pyelasticsearch is scheduled to be replaced by a dependency on `elasticsearch-py`_.
|
||||||
|
|
||||||
|
The backend is configured in settings:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
WAGTAILSEARCH_BACKENDS = {
|
||||||
|
'default': {
|
||||||
|
'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch.ElasticSearch',
|
||||||
|
'URL': ['http://localhost:9200'],
|
||||||
|
'INDEX': 'wagtail',
|
||||||
|
'TIMEOUT': 5,
|
||||||
|
'FORCE_NEW': False,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Other than `BACKEND` the other keys are optional and default to the values shown. In addition any other keys are passed directly to the Elasticsearch constructor as keyword arguments (e.g. `'max_retries': 1`).
|
||||||
|
|
||||||
If you prefer not to run an Elasticsearch server in development or production, there are many hosted services available, including `Searchly`_, who offer a free account suitable for testing and development. To use Searchly:
|
If you prefer not to run an Elasticsearch server in development or production, there are many hosted services available, including `Searchly`_, who offer a free account suitable for testing and development. To use Searchly:
|
||||||
|
|
||||||
- Sign up for an account at `dashboard.searchly.com/users/sign\_up`_
|
- Sign up for an account at `dashboard.searchly.com/users/sign\_up`_
|
||||||
|
@ -229,6 +253,9 @@ If you prefer not to run an Elasticsearch server in development or production, t
|
||||||
your local settings
|
your local settings
|
||||||
- Run ``./manage.py update_index``
|
- Run ``./manage.py update_index``
|
||||||
|
|
||||||
|
.. _elasticutuils: http://elasticutils.readthedocs.org
|
||||||
|
.. _pyelasticsearch: http://pyelasticsearch.readthedocs.org
|
||||||
|
.. _elasticsearch-py: http://elasticsearch-py.readthedocs.org
|
||||||
.. _Searchly: http://www.searchly.com/
|
.. _Searchly: http://www.searchly.com/
|
||||||
.. _dashboard.searchly.com/users/sign\_up: https://dashboard.searchly.com/users/sign_up
|
.. _dashboard.searchly.com/users/sign\_up: https://dashboard.searchly.com/users/sign_up
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ if not settings.configured:
|
||||||
if has_elasticsearch:
|
if has_elasticsearch:
|
||||||
WAGTAILSEARCH_BACKENDS['elasticsearch'] = {
|
WAGTAILSEARCH_BACKENDS['elasticsearch'] = {
|
||||||
'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch.ElasticSearch',
|
'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch.ElasticSearch',
|
||||||
|
'TIMEOUT': 10,
|
||||||
|
'max_retries': 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.configure(
|
settings.configure(
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
from elasticutils import get_es, S
|
from elasticutils import get_es, S
|
||||||
|
|
||||||
|
@ -58,12 +57,23 @@ class ElasticSearch(BaseSearch):
|
||||||
super(ElasticSearch, self).__init__(params)
|
super(ElasticSearch, self).__init__(params)
|
||||||
|
|
||||||
# Get settings
|
# Get settings
|
||||||
self.es_urls = params.get('URLS', ['http://localhost:9200'])
|
self.es_urls = params.pop('URLS', ['http://localhost:9200'])
|
||||||
self.es_index = params.get('INDEX', 'wagtail')
|
self.es_index = params.pop('INDEX', 'wagtail')
|
||||||
|
self.es_timeout = params.pop('TIMEOUT', 5)
|
||||||
|
self.es_force_new = params.pop('FORCE_NEW', False)
|
||||||
|
|
||||||
# Get ElasticSearch interface
|
# Get ElasticSearch interface
|
||||||
self.es = get_es(urls=self.es_urls)
|
# Any remaining params are passed into the ElasticSearch constructor
|
||||||
self.s = S().es(urls=self.es_urls).indexes(self.es_index)
|
self.es = get_es(
|
||||||
|
urls=self.es_urls,
|
||||||
|
timeout=self.es_timeout,
|
||||||
|
force_new=self.es_force_new,
|
||||||
|
**params)
|
||||||
|
self.s = S().es(
|
||||||
|
urls=self.es_urls,
|
||||||
|
timeout=self.es_timeout,
|
||||||
|
force_new=self.es_force_new,
|
||||||
|
**params).indexes(self.es_index)
|
||||||
|
|
||||||
def reset_index(self):
|
def reset_index(self):
|
||||||
# Delete old index
|
# Delete old index
|
||||||
|
|
Ładowanie…
Reference in New Issue