4

私は単純な nlp ツールを開発しており、elasticsearch-dsl を django の es ツールとして使用しています。

Entity と Intent の 2 つの「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])

各ドキュメントには、たとえばカスタム マッピングがあります。

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にマッピングを作成します(エンティティドキュメントのみ! :( )。ただし、Entity.init()の後、インテントで同じことを行うことができませんでした。以下のエラーが発生します:

IllegalOperation: You cannot update analysis configuration on an open index, you need to close index nlp first.

これを解決するアイデアはありますか?可能であれば、本当に Entity.init() と Intent.init() を使いたいです。

4

1 に答える 1

8

analyzersopen で Intent タイプのnew を定義しようとしていますindex。これは許可されていないため、エラーが表示されています。

最初closeにインデックスを作成してから実行する必要があります

Intent.init()

インデックスを再度開きます。詳細については、ドキュメントを参照してください。

EDIT 1 You have to use low level python official client to close the index.

from elasticsearch import Elasticsearch

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

Even the dsl library uses it to test the mapping since it is created on top of python client.

于 2016-01-18T23:02:20.467 に答える