ElasticSearch - python 中完成建议器的批量索引

ElasticSearch - bulk indexing for a completion suggester in python

我正在尝试添加一个完成建议器,以便在我的 Django 应用程序中为搜索字段启用“按类型搜索”(使用 Elastic Search 5.2.x 和 elasticseach-dsl)。在长时间尝试解决这个问题之后,我还无法弄清楚如何对建议者进行批量索引。这是我的代码:

class SchoolIndex(DocType):
    name = Text()
    school_type = Keyword()
    name_suggest = Completion()

批量索引如下:

def bulk_indexing():
    SchoolIndex.init(index="school_index")
    es = Elasticsearch()
    bulk(client=es, actions=(a.indexing() for a in models.School.objects.all().iterator()))

并在models.py中定义了索引方法:

def indexing(self):
       obj = SchoolIndex(
          meta = {'id': self.pk},
          name = self.name,
          school_type = self.school_type,
          name_suggest = {'input': self.name } <--- # what goes in here?
       )
       obj.save(index="school_index")
       return obj.to_dict(include_meta=True)

根据 ES docs, suggestions are indexed like any other field. So I could just put a few terms in the name_suggest = statement above in my code which will match the corresponding field, when searched. But my question is how to do that with a ton of records? I was guessing there would be a standard way for ES to automatically come up with a few terms that could be used as suggestions. For example: using each word in the phrase as a term. I could come up something like that on my own (by breaking each phrase into words) but it seems counter-intuitive to do that on my own since I'd guess there would already be a default way that the user could further tweak if needed. But couldn't find anything like that on SO/blogs/ES docs/elasticsearch-dsl docs after searching for quite sometime. (This post,Adam Wattis 对我的入门非常有帮助)。将不胜感激。

我想我明白了 (..phew)

在索引功能中,我需要使用以下来启用前缀补全建议器:

name_suggest = self.name

而不是:

name_suggest = {'input': something.here }

这似乎用于更多自定义案例。

感谢 this video 的帮助!