当前位置: 首页>>代码示例>>Python>>正文


Python Index.settings方法代码示例

本文整理汇总了Python中elasticsearch_dsl.Index.settings方法的典型用法代码示例。如果您正苦于以下问题:Python Index.settings方法的具体用法?Python Index.settings怎么用?Python Index.settings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elasticsearch_dsl.Index的用法示例。


在下文中一共展示了Index.settings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_index_can_be_created_with_settings_and_mappings

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
def test_index_can_be_created_with_settings_and_mappings(write_client):
    i = Index('test-blog', using=write_client)
    i.document(Post)
    i.settings(number_of_replicas=0, number_of_shards=1)
    i.create()

    assert {
        'test-blog': {
            'mappings': {
                'properties': {
                    'title': {'type': 'text', 'analyzer': 'my_analyzer'},
                    'published_from': {'type': 'date'}
                }
            }
        }
    } == write_client.indices.get_mapping(index='test-blog')

    settings = write_client.indices.get_settings(index='test-blog')
    assert settings['test-blog']['settings']['index']['number_of_replicas'] == '0'
    assert settings['test-blog']['settings']['index']['number_of_shards'] == '1'
    assert settings['test-blog']['settings']['index']['analysis'] == {
        'analyzer': {
            'my_analyzer': {
                'type': 'custom',
                'tokenizer': 'keyword'
            }
        }
    }
开发者ID:elastic,项目名称:elasticsearch-dsl-py,代码行数:30,代码来源:test_index.py

示例2: setup_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
def setup_index(year):
    index = Index(f'{INDEX_NAME}-{year}')
    index.settings(number_of_shards=2, number_of_replicas=0)
    index.aliases(politicians={})
    index.document(Politicians)
    index.analyzer(brazilian_analyzer)
    index.create()
开发者ID:olhoneles,项目名称:politicos,代码行数:9,代码来源:models.py

示例3: setup_es

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
def setup_es():
    """Create the ElasticSearch index and configure the mapping.
    """
    client = elasticsearch_config['client']
    index_name = elasticsearch_config['index']

    info = client.info()
    print('ElasticSearch version: {0}'.format(info['version']['number']))

    if client.indices.exists(index_name):
        print('Index "{0}" already exists. To re-create the index, manually '
              'delete the index and run this script again.'.format(index_name))
        print('To delete the index run:')
        print('curl -XDELETE \'http://{0}:{1}/{2}/\''.format(
            elasticsearch_config['host'], elasticsearch_config['port'],
            index_name))
        sys.exit(0)

    index = Index(index_name)
    index.settings(analysis=analysis_settings)

    index.doc_type(SearchArea)
    index.doc_type(SearchBook)
    index.doc_type(SearchImage)
    index.doc_type(SearchOuting)
    index.doc_type(SearchXreport)
    index.doc_type(SearchRoute)
    index.doc_type(SearchTopoMap)
    index.doc_type(SearchUser)
    index.doc_type(SearchWaypoint)
    index.doc_type(SearchArticle)

    index.create()

    print('Index "{0}" created'.format(index_name))
开发者ID:c2corg,项目名称:v6_api,代码行数:37,代码来源:initializees.py

示例4: test_index_can_be_saved_even_with_settings

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
def test_index_can_be_saved_even_with_settings(write_client):
    i = Index('test-blog', using=write_client)
    i.settings(number_of_shards=3, number_of_replicas=0)
    i.save()
    i.settings(number_of_replicas=1)
    i.save()

    assert '1' == i.get_settings()['test-blog']['settings']['index']['number_of_replicas']
开发者ID:elastic,项目名称:elasticsearch-dsl-py,代码行数:10,代码来源:test_index.py

示例5: get_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
def get_index(name, doc_types, *, using, shards=1, replicas=0, interval="1s"):
    index = Index(name, using=using)
    for doc_type in doc_types:
        index.doc_type(doc_type)
    index.settings(
        number_of_shards=shards, number_of_replicas=replicas, refresh_interval=interval
    )
    return index
开发者ID:craig5,项目名称:warehouse,代码行数:10,代码来源:utils.py

示例6: initialize_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
    def initialize_index(self, delete_if_exists=False):
        """
        Initialize index with mapping in ElasticSearch

        :param delete_if_exists: delete index, if exists
        :return: None
        """

        def update_index_settings():
            """
            Function updates settings for slovenian lemmatization of words.
            As far as we know, elasticsearch-dsl library does not support
            custom filter settings.

            :return: None
            """
            analysis_settings = {
                "analysis": {
                    "filter": {
                        "lemmagen_filter_sl": {
                            "type": "lemmagen",
                            "lexicon": "sl"
                        }
                    },
                    "analyzer": {
                        "lemmagen_sl": {
                            "type": "custom",
                            "tokenizer": "uax_url_email",
                            "filter": [
                                "lemmagen_filter_sl",
                                "lowercase"
                            ]
                        }
                    }
                }
            }
            self.client.cluster.health(index=self.index_name,
                                       wait_for_status='green',
                                       request_timeout=2)
            self.client.indices.close(index=self.index_name)
            self.client.indices.put_settings(json.dumps(analysis_settings),
                                             index=self.index_name)
            self.client.indices.open(index=self.index_name)

        index = Index(self.index_name, using=self.client)
        if delete_if_exists and index.exists():
            index.delete()

        index.settings(
            # use higher number in production
            number_of_replicas=0
        )

        # register models
        index.doc_type(Document)
        index.create()
        update_index_settings()  # set lemmanizer
开发者ID:romanorac,项目名称:elastic_localized_search,代码行数:59,代码来源:controller_elastic.py

示例7: create_index_if_not_exists

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
 def create_index_if_not_exists(self, index_name):
     self.index = index_name
     idx = Index(index_name)
     idx.settings(number_of_shards=1, number_of_replicas=1)
     idx.doc_type(LogType)
     try:
         idx.create()
     except:
         pass
开发者ID:gustavohenrique,项目名称:elasticlog,代码行数:11,代码来源:elasticlog.py

示例8: test_cloned_index_has_copied_settings_and_using

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
def test_cloned_index_has_copied_settings_and_using():
    client = object()
    i = Index('my-index', using=client)
    i.settings(number_of_shards=1)

    i2 = i.clone('my-other-index')

    assert 'my-other-index' == i2._name
    assert client is i2._using
    assert i._settings == i2._settings
    assert i._settings is not i2._settings
开发者ID:gvaldez81,项目名称:elasticsearch-dsl-py,代码行数:13,代码来源:test_index.py

示例9: test_settings_are_saved

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
def test_settings_are_saved():
    i = Index('i')
    i.settings(number_of_replicas=0)
    i.settings(number_of_shards=1)

    assert {
        'settings': {
            'number_of_shards': 1,
            'number_of_replicas': 0,
        }
    } == i.to_dict()
开发者ID:gvaldez81,项目名称:elasticsearch-dsl-py,代码行数:13,代码来源:test_index.py

示例10: create_indices

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
def create_indices(endpoint):
    """
    Creates constituent and address indices in PIC
    """
    connections.connections.create_connection(hosts=[endpoint], timeout=360, max_retries=10, retry_on_timeout=True)
    pic_index = Index('pic')
    pic_index.doc_type(Constituent)
    pic_index.doc_type(Address)
    pic_index.delete(ignore=404)

    pic_index.settings(
        number_of_shards=5,
        number_of_replicas=2
    )
    pic_index.create()
开发者ID:NYPL,项目名称:pic-data,代码行数:17,代码来源:index_builder.py

示例11: _create_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
    def _create_index(self):
        # https://github.com/csirtgadgets/massive-octo-spice/blob/develop/elasticsearch/observables.json
        # http://elasticsearch-py.readthedocs.org/en/master/api.html#elasticsearch.Elasticsearch.bulk

        # every time we check it does a HEAD req
        if self.last_index_value and (datetime.utcnow() - self.last_index_check) < timedelta(minutes=2):
            return self.last_index_value

        idx = self._current_index()

        if not self.handle.indices.exists(idx):
            index = Index(idx)
            index.aliases(live={})
            index.doc_type(Indicator)
            index.settings(max_result_window=WINDOW_LIMIT)
            index.create()
            self.handle.indices.flush(idx)

        self.last_index_check = datetime.utcnow()
        self.last_index_value = idx
        return idx
开发者ID:csirtgadgets,项目名称:bearded-avenger,代码行数:23,代码来源:indicator.py

示例12: test_index_can_be_created_with_settings_and_mappings

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
def test_index_can_be_created_with_settings_and_mappings(write_client):
    i = Index('test-blog', using=write_client)
    i.doc_type(Post)
    i.doc_type(User)
    i.settings(number_of_replicas=0, number_of_shards=1)
    i.create()

    assert {
        'test-blog': {
            'mappings': {
                'post': {
                    'properties': {
                        'title': {'type': 'string', 'analyzer': 'my_analyzer'},
                        'published_from': {'type': 'date', 'format': 'dateOptionalTime',},
                    }
                },
                'user': {
                    'properties': {
                        'username': {'type': 'string', 'index': 'not_analyzed'},
                        'joined_date': {'type': 'date', 'format': 'dateOptionalTime',},
                    }
                },
            }
        }
    } == write_client.indices.get_mapping(index='test-blog')

    settings = write_client.indices.get_settings(index='test-blog')
    assert settings['test-blog']['settings']['index']['number_of_replicas'] == '0'
    assert settings['test-blog']['settings']['index']['number_of_shards'] == '1'
    assert settings['test-blog']['settings']['index']['analysis'] == {
        'analyzer': {
            'my_analyzer': {
                'type': 'custom',
                'tokenizer': 'keyword'
            }
        }
    }
开发者ID:rohan1gupta,项目名称:elasticsearch-dsl-py,代码行数:39,代码来源:test_index.py

示例13: register

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
    def register(self, name=None, version=None, settings=None):
        """
        Register an index locally.

        Note that `createall` is needed to save the index to Elasticsearch.

        The index will be named per convention such that:
         -  The graph's name is used by default
         -  The "test" suffix is added for unit testing (to avoid clobbering real data)

        If version is provided, it will be used to create generate an alias (to the unversioned name).

        """
        if version is None:
            index_name = IndexRegistry.name_for(self.graph, name=name)
            alias_name = None
        else:
            # create index with full version, alias to shortened version
            index_name = IndexRegistry.name_for(self.graph, name=name, version=version)
            alias_name = IndexRegistry.name_for(self.graph, name=name)

        if index_name in self.indexes:
            raise Exception("Index already registered for name: {}".format(index_name))

        index = Index(
            name=index_name,
            using=self.graph.elasticsearch_client,
        )

        if settings:
            index.settings(**settings)

        if alias_name is not None:
            index.aliases(**{alias_name: {}})

        self.indexes[index_name] = index
        return index
开发者ID:globality-corp,项目名称:microcosm-elasticsearch,代码行数:39,代码来源:registry.py

示例14: Nested

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
    comments = Nested(properties={'owner': user_field})
    body = String(analyzer=html_strip)

class Question(Post):
    tags = String(index='not_analyzed', multi=True)
    last_editor = user_field
    last_edit_date = Date()


class Answer(Post):
    class Meta:
        parent = MetaField(type='question')

# create an index and register the doc types
index = Index(settings.ES_INDEX)
index.settings(number_of_shards=1, number_of_replicas=0)
index.doc_type(Answer)
index.doc_type(Question)


class QASearch(FacetedSearch):
    doc_types = [Question]
    index = settings.ES_INDEX

    fields = ['tags', 'title', 'body']

    facets = {
        'tags': TermsFacet(field='tags', size=5),

        'months': DateHistogramFacet(
            field='creation_date',
开发者ID:MUDASSARHASHMI,项目名称:es-django-example,代码行数:33,代码来源:search.py

示例15: Index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import settings [as 别名]
from elasticsearch_dsl import DocType, Index, String
from django.core.urlresolvers import reverse

visnyk_index = Index('visnyk')

visnyk_index.settings(
    index={
        "analysis": {
            "filter": {
                "lemmagen_filter_uk": {
                    "type": "lemmagen",
                    "lexicon": "uk"
                }
            },
            "analyzer": {
                "html_uk_analyzer": {
                    "type": "custom",
                    "tokenizer": "uax_url_email",
                    "filter": ["lemmagen_filter_uk", "lowercase", "stop"],
                    "char_filter": ["html_strip"]
                }
            }
        }
    }
)


@visnyk_index.doc_type
class VisnykDocument(DocType):
    """Visnyk document."""
    plain_content = String(analyzer="html_uk_analyzer")
开发者ID:dchaplinsky,项目名称:visnyk,代码行数:33,代码来源:elastic_models.py


注:本文中的elasticsearch_dsl.Index.settings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。