I'm using elasticsearch-dsl-py 0.0.5 and the example at https://github.com/HonzaKral/es-django-example for usage with Django.
I've got a DocType:
class PageDoc(DocType):
title = String(analyzer='snowball')
index = Index('my_index')
index.doc_type(PageDoc)
And I update my index using the management command below. Page
is the Django model I'm trying to index.
class Command(BaseCommand):
def handle(self, *args, **kwargs):
self.es = connections.get_connection()
index.delete(ignore=404)
index.create()
self.verbose_run(Page)
def verbose_run(self, model, report_every=100):
name = model._meta.verbose_name
print('Indexing %s: ' % name, end='')
start = time.time()
cnt = 0
for _ in streaming_bulk(
self.es,
(m.to_search().to_dict(True) for m in model.objects.all().iterator()),
index=settings.ES_INDEX,
doc_type=name.lower()):
cnt += 1
if cnt % report_every:
print('.', end='')
print('DONE\nIndexing %d %s in %.2f seconds' % (
cnt, name, time.time() - start
))
The (simplified) output of http://127.0.0.1:9200/my_index/_mapping?pretty is:
{
"my_index" : {
"mappings" : {
"page" : {
"properties" : {
"title" : {
"type" : "string"
}
}
}
}
}
}
I can query for exact matches, but stemming is not working. Why is the snowball analyzer not added to the title field?