如何在Elasticsearch DSL中将文档添加到自定义索引中

时间:2015-10-05 08:34:30

标签: elasticsearch-dsl

我尝试过类似的方法来创建自定义索引(包含10个分片),然后添加文档:

  from elasticsearch_dsl import DocType, Index, String, Analyzer, token_filter


  class User(DocType):
        class Meta:
            index = 'test_index'

        name = String(required=True, analyzer=analyzer(
                    'german_analyzer',
                    tokenizer="standard",
                    filter=["standard",
                            "lowercase",
                            token_filter('german_snowball',
                                         type='snowball',
                                         language='German'),
                            token_filter('german_excluded_words',
                                         type='stop',
                                         stopwords='_german_')
                    ]))

    current_index = Index('test_index')
    # Set default settings:
    current_index.settings(number_of_shards=10)
    # Delete the index or ignore if it doesn't exist.
    current_index.delete(ignore=404)
    # Execute the request (Create Index)
    current_index.create()

    # Add document:
    User.init()
    user = User(name= 'Jaime Williams')
    user.meta.id = 1
    user.save()

但是我收到以下错误: elasticsearch_dsl.exceptions.IllegalOperation: You cannot update analysis configuration on an open index, you need to close index test_index first.

有没有办法用自定义数量的分片创建索引然后再添加文档?

0 个答案:

没有答案