Skip to content

Instantly share code, notes, and snippets.

@saevarom
Last active October 14, 2022 12:53
Show Gist options
  • Save saevarom/e2ab1f746a42873b7081a865490f8008 to your computer and use it in GitHub Desktop.
Save saevarom/e2ab1f746a42873b7081a865490f8008 to your computer and use it in GitHub Desktop.
Elasticsearch config for Icelandic in Wagtail
  1. pip install requests-aws4auth
  2. Add AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, ELASTICSEARCH_INDEX_NAME and ELASTICSEARCH_HOST variables to your environment
  3. Import the variables to your settings file
  4. Add the WAGTAILSEARCH_BACKENDS configuration to your settings file
# production settings file
from elasticsearch import RequestsHttpConnection
from requests_aws4auth import AWS4Auth
# You will need to import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, ELASTICSEARCH_INDEX_NAME and ELASTICSEARCH_HOST from your environment
# You will also need to allow connections from your server to the elasticsearch instance in AWS
WAGTAILSEARCH_BACKENDS = {
'default': {
'BACKEND': 'wagtail.search.backends.elasticsearch6',
'INDEX': ELASTICSEARCH_INDEX_NAME,
'TIMEOUT': 120,
'HOSTS': [{
'host': ELASTICSEARCH_HOST,
'port': 443,
'use_ssl': True,
'verify_certs': True,
'http_auth': AWS4Auth(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, 'eu-west-1', 'es'),
}],
'OPTIONS': {
'connection_class': RequestsHttpConnection,
},
'INDEX_SETTINGS': {
'settings': {
'analysis': {
'analyzer': {
'ngram_analyzer': {
'type': 'custom',
'tokenizer': 'lowercase',
'filter': ['folding', 'ngram']
},
'edgengram_analyzer': {
'type': 'custom',
'tokenizer': 'lowercase',
'filter': ['folding', 'edgengram']
}
},
'tokenizer': {
'ngram_tokenizer': {
'type': 'nGram',
'min_gram': 3,
'max_gram': 15,
},
'edgengram_tokenizer': {
'type': 'edgeNGram',
'min_gram': 2,
'max_gram': 15,
'side': 'front'
}
},
'filter': {
'ngram': {
'type': 'nGram',
'min_gram': 3,
'max_gram': 15
},
'edgengram': {
'type': 'edgeNGram',
'min_gram': 1,
'max_gram': 15
},
'folding': {
'type': 'standard',
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment