예제 #1
0
def remove_from_index(instance, mapping):
    """
    Utility function for signal listeners to remove from Elasticsearch.
    Currently uses synchronous tasks. And because of that all exceptions are
    caught, so failures will not interfere with the regular model updates.
    """
    if settings.ES_DISABLED:
        return
    logger.info(u'Removing instance %s: %s' %
                (instance.__class__.__name__, instance.pk))
    # Extract all aliases available.
    aliases = list(
        itertools.chain(*[
            v['aliases'].keys() for v in es.indices.get_aliases().itervalues()
            if 'aliases' in v
        ]))
    for index in [DEFAULT_INDEX, NEW_INDEX]:
        try:
            if index in aliases:
                tasks.unindex_objects(mapping, [instance.id],
                                      es=es,
                                      index=index)
                es.indices.refresh(index)
        except NotFoundError, e:
            logger.warn('Not found in index instance %s: %s' %
                        (instance.__class__.__name__, instance.pk))
        except Exception, e:
            logger.error(traceback.format_exc(e))
예제 #2
0
def remove_from_index(instance, mapping):
    """
    Utility function for signal listeners to remove from Elasticsearch.
    Currently uses synchronous tasks. And because of that all exceptions are
    caught, so failures will not interfere with the regular model updates.
    """
    logger.info('Removing instance %s' % instance)
    try:
        tasks.unindex_objects(mapping, [instance.id], index=settings.ES_INDEXES['default'])
    except Exception, e:
        logger.error(traceback.format_exc(e))
예제 #3
0
파일: index.py 프로젝트: rmoorman/hellolily
 def unindex(self, index_name):
     '''
     Removing deleted objects from our index-enabled models.
     '''
     for mappingClass in self.MAPPINGS:
         model = mappingClass.get_model()
         self.stdout.write('Removing deleted %s objects from index %s' % (model,
                                                                          index_name))
         model_objs = model.objects.filter(is_deleted=True)
         model_ids = list(model_objs.values_list('pk', flat=True))
         if model_ids:
             try:
                 tasks.unindex_objects(mappingClass, model_ids, index=index_name)
             except:
                 pass
예제 #4
0
파일: indexing.py 프로젝트: Fokko/hellolily
def remove_from_index(instance, mapping):
    """
    Utility function for signal listeners to remove from Elasticsearch.
    Currently uses synchronous tasks. And because of that all exceptions are
    caught, so failures will not interfere with the regular model updates.
    """
    if settings.ES_DISABLED:
        return
    logger.info(u'Removing instance %s: %s' % (instance.__class__.__name__, instance.pk))

    try:
        main_index_with_type = get_index_name(main_index, mapping)
        tasks.unindex_objects(mapping, [instance.id], es=es, index=main_index_with_type)
        es.indices.refresh(main_index_with_type)
    except NotFoundError, e:
        logger.warn('Not found in index instance %s: %s' % (instance.__class__.__name__, instance.pk))
예제 #5
0
    def test_tasks(self):
        documents = [
            {'id': 1, 'name': 'odin skullcrusher'},
            {'id': 2, 'name': 'heimdall kneebiter'},
            {'id': 3, 'name': 'erik rose'}
            ]

        for doc in documents:
            FakeModel(**doc)

        # Test index_objects task
        index_objects(FakeDjangoMappingType, [1, 2, 3])
        FakeDjangoMappingType.refresh_index()
        eq_(FakeDjangoMappingType.search().count(), 3)

        # Test unindex_objects task
        unindex_objects(FakeDjangoMappingType, [1, 2, 3])
        FakeDjangoMappingType.refresh_index()
        eq_(FakeDjangoMappingType.search().count(), 0)
예제 #6
0
    def test_tasks(self):
        documents = [
            {'id': 1, 'name': 'odin skullcrusher'},
            {'id': 2, 'name': 'heimdall kneebiter'},
            {'id': 3, 'name': 'erik rose'}
            ]

        for doc in documents:
            FakeModel(**doc)

        # Test index_objects task
        index_objects(FakeDjangoMappingType, [1, 2, 3])
        FakeDjangoMappingType.refresh_index()
        eq_(FakeDjangoMappingType.search().count(), 3)

        # Test unindex_objects task
        unindex_objects(FakeDjangoMappingType, [1, 2, 3])
        FakeDjangoMappingType.refresh_index()
        eq_(FakeDjangoMappingType.search().count(), 0)
예제 #7
0
    def test_tasks(self):
        documents = [
            {"id": 1, "name": "odin skullcrusher"},
            {"id": 2, "name": "heimdall kneebiter"},
            {"id": 3, "name": "erik rose"},
        ]

        for doc in documents:
            FakeModel(**doc)

        # Test index_objects task
        index_objects(FakeDjangoMappingType, [1, 2, 3])
        FakeDjangoMappingType.refresh_index()
        eq_(FakeDjangoMappingType.search().count(), 3)

        # Test unindex_objects task
        unindex_objects(FakeDjangoMappingType, [1, 2, 3])
        FakeDjangoMappingType.refresh_index()
        eq_(FakeDjangoMappingType.search().count(), 0)
예제 #8
0
def remove_from_index(instance, mapping):
    """
    Utility function for signal listeners to remove from Elasticsearch.
    Currently uses synchronous tasks. And because of that all exceptions are
    caught, so failures will not interfere with the regular model updates.
    """
    if settings.ES_DISABLED:
        return
    logger.info(u'Removing instance %s: %s' %
                (instance.__class__.__name__, instance.pk))

    try:
        main_index_with_type = get_index_name(main_index, mapping)
        tasks.unindex_objects(mapping, [instance.id],
                              es=es,
                              index=main_index_with_type)
        es.indices.refresh(main_index_with_type)
    except NotFoundError, e:
        logger.warn('Not found in index instance %s: %s' %
                    (instance.__class__.__name__, instance.pk))
예제 #9
0
def remove_from_index(instance, mapping):
    """
    Utility function for signal listeners to remove from Elasticsearch.
    Currently uses synchronous tasks. And because of that all exceptions are
    caught, so failures will not interfere with the regular model updates.
    """
    if settings.ES_DISABLED:
        return
    logger.info(u'Removing instance %s: %s' % (instance.__class__.__name__, instance.pk))
    # Extract all aliases available.
    aliases = list(itertools.chain(*[v['aliases'].keys() for v in es.indices.get_aliases().itervalues() if 'aliases' in v]))
    for index in [DEFAULT_INDEX, NEW_INDEX]:
        try:
            if index in aliases:
                tasks.unindex_objects(mapping, [instance.id], es=es, index=index)
                es.indices.refresh(index)
        except NotFoundError, e:
            logger.warn('Not found in index instance %s: %s' % (instance.__class__.__name__, instance.pk))
        except Exception, e:
            logger.error(traceback.format_exc(e))