erh*_*tlu 4 django elasticsearch django-rest-framework elasticsearch-dsl
我正在开发一个简单的nlp工具,并使用elasticsearch-dsl作为django的es工具。
我将有两个“ DocType”,实体和意图。我创建了自己的分析器,它是:
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])
Run Code Online (Sandbox Code Playgroud)
例如,在每个文档中,我都有一个自定义映射。
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
Run Code Online (Sandbox Code Playgroud)
根据文档http://elasticsearch-dsl.readthedocs.org/en/latest/persistence.html#persistence。Entity.init()将为此文档创建映射。它确实在我的es上创建了映射(仅用于实体doc!:()。但是,在Entity.init()之后,我无法使用Intent做同样的事情。它给出以下错误:
IllegalOperation: You cannot update analysis configuration on an open index, you need to close index nlp first.
Run Code Online (Sandbox Code Playgroud)
有解决的办法吗?如果可能的话,我真的想使用Entity.init()和Intent.init()。
您正在尝试analyzers
在open上为您的Intent类型定义new index
。不允许这样做,因此您会看到错误。
您必须先创建close
索引,然后运行
Intent.init()
Run Code Online (Sandbox Code Playgroud)
并重新打开索引。您可以参考文档以获取更多信息。
编辑1您必须使用低级python 官方客户端来关闭索引。
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.indices.close(index="nlp")
Run Code Online (Sandbox Code Playgroud)
由于它是在python客户端之上创建的,dsl library
因此即使使用它也可以测试映射。
归档时间: |
|
查看次数: |
1828 次 |
最近记录: |