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


Python Index.delete方法代码示例

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


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

示例1: es_delete_cmd

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
def es_delete_cmd(index_name):
    """Delete a specified index

    :arg index_name: name of index to delete

    """
    indexes = [name for name, count in get_indexes()]

    if index_name not in indexes:
        log.error('Index "%s" is not a valid index.', index_name)
        if not indexes:
            log.error('There are no valid indexes.')
        else:
            log.error('Valid indexes: %s', ', '.join(indexes))
        return

    ret = raw_input(
        'Are you sure you want to delete "%s"? (yes/no) ' % index_name
    )
    if ret != 'yes':
        return

    log.info('Deleting index "%s"...', index_name)
    index = Index(name=index_name, using='default')
    try:
        index.delete()
    except NotFoundError:
        pass
    log.info('Done!')
开发者ID:digideskio,项目名称:sentiment-analysis,代码行数:31,代码来源:index.py

示例2: BaseSearchTestCase

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
class BaseSearchTestCase(TestCase):

    def setUp(self):
        from django.conf import settings
        SEARCH = getattr(settings, 'SEARCH')

        connections.create_connection('testing', **SEARCH['default']['connections'])
        self.index = Index(SEARCH['default']['index'], using='testing')
        # This is needed for test_documents, but has side effects in all running tests
        doctypes_list = (
            value for name, value
            in inspect.getmembers(documents)
            if not name.startswith('_') and
            inspect.isclass(value) and
            issubclass(value, DocType) and
            name != DocType.__name__
        )

        for doctype in doctypes_list:
            # Remove assigned index
            doctype._doc_type.index = None
            # Associate docs with test index
            self.index.doc_type(doctype)

        if self.index.exists():
            self.index.delete(ignore=404)
        self.index.create()

        self.search = Search(index=SEARCH['default']['index'])

    def tearDown(self):
        self.index.delete()
        queue = django_rq.get_queue()
        queue.empty()
开发者ID:CSIS-iLab,项目名称:new-silk-road,代码行数:36,代码来源:base.py

示例3: test_delete

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
def test_delete(write_client):
    write_client.indices.create(
        index='test-index',
        body={'settings': {'number_of_replicas': 0, 'number_of_shards': 1}}
    )

    i = Index('test-index', using=write_client)
    i.delete()
    assert not write_client.indices.exists(index='test-index')
开发者ID:elastic,项目名称:elasticsearch-dsl-py,代码行数:11,代码来源:test_index.py

示例4: drop_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
def drop_index(silent=True):
    """Remove the ElasticSearch index.
    """
    index = Index(elasticsearch_config['index'])
    try:
        index.delete()
    except Exception as exc:
        if not silent:
            raise exc
开发者ID:mfournier,项目名称:v6_api,代码行数:11,代码来源:initializees.py

示例5: recreate_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
    def recreate_index(self):
        """ Delete and then create a given index and set a default mapping.

        :param index: [string] name of the index. If None a default is used
        """
        submission = Index(self.index)
        submission.delete(ignore=404)

        ESSubmission.init()
开发者ID:HEPData,项目名称:hepdata3,代码行数:11,代码来源:api.py

示例6: run

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
 def run(self, *args, **options):
     self.confirm(
         u"Are you really sure you want to delete the index '{0}' ?"
         .format(self.index_name)
     )
     index = Index(self.index_name)
     if not self.dry_run:
         index.delete()
     self.print_success(u"Index {0} deleted.".format(self.index_name))
开发者ID:laurentguilbert,项目名称:django-trampoline,代码行数:11,代码来源:es_delete_index.py

示例7: initialize_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [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

示例8: test_create_index_manually

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
    def test_create_index_manually(self):
        out = io.StringIO()
        index_name = 'test_manually_created_index'
        call_command('create_index', index_name, stdout=out)
        self.assertIn("Created search index '{}'".format(index_name), out.getvalue())

        index = Index(index_name)
        self.assertTrue(index.exists())

        index.delete()
        self.assertFalse(index.exists())
开发者ID:CSIS-iLab,项目名称:new-silk-road,代码行数:13,代码来源:test_commands.py

示例9: create_search_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
def create_search_index(index_name, doc_types=None, connection='default', delete_if_exists=False):
    index = Index(index_name, using=connection)
    if delete_if_exists:
        index.delete(ignore=404)
    if doc_types:
        for dt in doc_types:
            if isinstance(dt, str):
                dt = get_document_class(dt)
            index.doc_type(dt)
    if not index.exists():
        index.create()
    return index
开发者ID:CSIS-iLab,项目名称:new-silk-road,代码行数:14,代码来源:tasks.py

示例10: test_create_index_usings_settings

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
    def test_create_index_usings_settings(self):
        out = io.StringIO()
        call_command('create_index', stdout=out)

        self.assertIn("Creating search indices from settings", out.getvalue())
        self.assertIn("Created search index '{}'".format(self.settings['default']['index']), out.getvalue())

        index = Index(self.settings['default']['index'])
        self.assertTrue(index.exists())

        index.delete()
        self.assertFalse(index.exists())
开发者ID:CSIS-iLab,项目名称:new-silk-road,代码行数:14,代码来源:test_commands.py

示例11: create_indices

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [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

示例12: recreate_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
def recreate_index():
    """Delete index if it's there and creates a new one"""
    index = Index(name=get_index_name(), using='default')

    for name, doc_type in get_doctypes().items():
        index.doc_type(doc_type)

    # Delete the index if it exists.
    try:
        index.delete()
    except NotFoundError:
        pass

    # Note: There should be no mapping-conflict race here since the
    # index doesn't exist. Live indexing should just fail.

    # Create the index with the mappings all at once.
    index.create()
开发者ID:digideskio,项目名称:sentiment-analysis,代码行数:20,代码来源:index.py

示例13: build_search_index

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
    def build_search_index(cls, reset=True):
        if reset:
            index = ES_Index(cls._es_doctype._doc_type.index)
            index.delete(ignore=404)
            cls._es_doctype.init()


        def add_to_index(id_, db, app):
            with app.app_context():
                obj = db.session.query(cls).get(id_)
                obj.add_to_search_index()

        app = db.get_app()

        with futures.ThreadPoolExecutor(max_workers=10) as executor:
            future_to_id = dict((executor.submit(add_to_index, id_, db, app),
                                 id_) for id_ in xrange(1, cls.count() + 1))

            for future in futures.as_completed(future_to_id):
                id = future_to_id[future]
                if future.exception() is not None:
                    print('%r generated an exception: %s' % (
                        id, future.exception()))
开发者ID:VitorPizzuto,项目名称:gastos_abertos,代码行数:25,代码来源:models.py

示例14: handle

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
 def handle(self, *args, **options):
     from searching.utils import autodiscover
     for _class in autodiscover():
         index = Index(_class.get_model_index().Meta.index)
         index.delete()
开发者ID:bleedjent,项目名称:ab_searching,代码行数:7,代码来源:clear_index_new.py

示例15: SearchByFieldTestCase

# 需要导入模块: from elasticsearch_dsl import Index [as 别名]
# 或者: from elasticsearch_dsl.Index import delete [as 别名]
class SearchByFieldTestCase(TestCase):

    def setUp(self):
        self.es_conn = connections.get_connection()
        self.test_crecs = []
        for i in range(20):
            self.test_crecs.append(
                CRECDoc(
                    title=str(i),
                    content='foo bar baz Foo',
                    date_issued=datetime(2017, 1, i % 5 + 1)
                )
            )
        self.index = Index(settings.ES_CW_INDEX)
        CRECDoc.init()
        for c in self.test_crecs:
            c.save(refresh=True)
        self.client = Client()

    def tearDown(self):
        self.index.delete()
    
    def test_search_by_title(self):
        c = CRECDoc(
            title='foo',
            content='blah',
            date_issued=datetime(2017, 1, 1)
        )
        c.save(refresh=True)
        start_date = datetime(2017, 1, 1)
        end_date = datetime(2017, 1, 30)
        query_args = {
            'start_date': start_date.strftime('%Y-%m-%d'),
            'end_date': end_date.strftime('%Y-%m-%d'),
            'title': 'foo',
        }
        response = self.client.get('/cwapi/search/', query_args)
        response_content = response.json()
        results = response_content['data']
        self.assertEquals(1, len(results))
        self.assertEquals('foo', results[0]['title'])
        self.assertEquals('blah', results[0]['content'])
    
    def test_search_by_content(self):
        c = CRECDoc(
            title='foo',
            content='blah',
            date_issued=datetime(2017, 1, 1)
        )
        c.save(refresh=True)
        start_date = datetime(2017, 1, 1)
        end_date = datetime(2017, 1, 30)
        query_args = {
            'start_date': start_date.strftime('%Y-%m-%d'),
            'end_date': end_date.strftime('%Y-%m-%d'),
            'content': 'blah',
        }
        response = self.client.get('/cwapi/search/', query_args)
        response_content = response.json()
        results = response_content['data']
        self.assertEquals(1, len(results))
        self.assertEquals('foo', results[0]['title'])
        self.assertEquals('blah', results[0]['content'])
    
        
    def test_date_filter(self):
        c = CRECDoc(
            title='should be in results',
            content='blah',
            date_issued=datetime(2017, 1, 1)
        )
        c2 = CRECDoc(
            title='should NOT be in results',
            content='blah',
            date_issued=datetime(2016, 1, 1)
        )
        c.save(refresh=True)
        c2.save(refresh=True)
        start_date = datetime(2017, 1, 1)
        end_date = datetime(2017, 1, 30)
        query_args = {
            'start_date': start_date.strftime('%Y-%m-%d'),
            'end_date': end_date.strftime('%Y-%m-%d'),
            'content': 'blah',
        }
        response = self.client.get('/cwapi/search/', query_args)
        response_content = response.json()
        results = response_content['data']
        self.assertEquals(1, len(results))
        self.assertEquals('should be in results', results[0]['title'])
    
            
    def test_multi_field(self):
        c = CRECDoc(
            title='foo',
            content='bar',
            date_issued=datetime(2017, 1, 1)
        )
        c2 = CRECDoc(
            title='foo',
#.........这里部分代码省略.........
开发者ID:sunlightlabs,项目名称:Capitol-Words,代码行数:103,代码来源:tests.py


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