def generate_index(self, indexName):
"""Generates the index on Elasticsearch
This method is intended to be used internally. It creates an index
using certains parameters to get a better search performance.
:params str indexName: Name of the new index
"""
body = {'mappings': {
self.type: {
'properties': {},
'dynamic': True
}
},
'settings': {
'analysis': {
'analyzer': {
'my_custom_analyzer': {
'type': 'custom',
'tokenizer': 'standard',
'filter': ['lowercase', 'my_ascii_folding']
}
},
'filter': {
'my_ascii_folding': {
'type': 'asciifolding',
'preserve_original': True
}
}
}
}}
suggest_field = {
'type': 'completion',
'analyzer': 'my_custom_analyzer',
'search_analyzer': 'standard',
'preserve_separators': False,
'preserve_position_increments': False
}
body['mappings'][self.type]['properties'] = {
'entity_id': {'type': 'string'},
'entity_uri': {'type': 'string'},
'description': {'type': 'object'},
'label': {'type': 'object'},
'alt_label': {'type': 'object'},
'label_suggest': suggest_field
}
try:
self.es.indices.delete(index=indexName)
except es_exceptions.NotFoundError:
pass
self.es.indices.create(index=indexName, body=body)
评论列表
文章目录