首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用弹性搜索-dsl DocType的映射配置

使用弹性搜索-dsl DocType的映射配置
EN

Stack Overflow用户
提问于 2016-01-18 22:48:18
回答 1查看 3.7K关注 0票数 4

我正在开发一个简单的nlp工具,并将elasticsearch-dsl用作django的es工具。

我将有两个"DocType",实体和意图。我发明了我自己的分析器,就是:

代码语言:javascript
复制
turkish_stop = token_filter('turkish_stop', type='stop', stopwords="_turkish_")
turkish_lowercase = token_filter('turkish_lowercase', type='lowercase', language="turkish")
turkish_stemmer = token_filter('turkish_stemmer', type='stemmer', language='turkish')

turkish_analyzer = analyzer('turkish_analyzer', tokenizer='whitespace', filter=['apostrophe', 'asciifolding',
                                                                                turkish_lowercase, turkish_stop,
                                                                                turkish_stemmer])

例如,在每个文档中,我都有一个自定义映射;

代码语言:javascript
复制
class Entity(DocType):
    entity_synonyms = String(analyzer=es.turkish_analyzer, include_in_all=True)
    entity_key = String(index='not_analyzed', include_in_all=False)

    class Meta:
        index = es.ELASTICSEARCH_INDEX
        doc_type = es.ELASTICSEARCH_ENTITY_DOCTYPE

根据http://elasticsearch-dsl.readthedocs.org/en/latest/persistence.html#persistence文件。Entity.init()将为这个文档创建映射。它实际上是在我的es上创建映射(仅用于实体doc!:( )。但是,在Entity.init()之后,我不能有意图地做同样的事情。它给出了以下错误:

代码语言:javascript
复制
IllegalOperation: You cannot update analysis configuration on an open index, you need to close index nlp first.

有办法解决这个问题吗?如果可能的话,我非常想使用Entity.init()和Intent.init()。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-18 23:02:20

您正在尝试为打开的analyzers上的意图类型定义新的index。这是不允许的,因此您将看到错误。

您必须首先close索引,然后运行

代码语言:javascript
复制
Intent.init()

重新打开索引。您可以参考文档获得更多信息。

编辑1你必须使用低级别的正式客户来关闭索引。

代码语言:javascript
复制
from elasticsearch import Elasticsearch

es = Elasticsearch()
es.indices.close(index="nlp")

甚至dsl library也使用它来创建映射,因为它是在python之上创建的。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34865507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档