Beispiel #1
0
def includeme(config):
    settings = config.registry.settings
    settings.setdefault('es.host', 'http://localhost:9200')
    settings.setdefault('es.index', 'hypothesis')
    settings.setdefault('legacy.es.index', 'annotator')

    # Allow users of this module to register additional search filter and
    # search matcher factories.
    config.registry[FILTERS_KEY] = []
    config.registry[MATCHERS_KEY] = []
    config.add_directive('add_search_filter',
                         lambda c, f: c.registry[FILTERS_KEY].append(f))
    config.add_directive('add_search_matcher',
                         lambda c, m: c.registry[MATCHERS_KEY].append(m))

    # Add a property to all requests for easy access to the elasticsearch
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.add_request_method(lambda r: _get_client(r.registry.settings),
                              name='es',
                              reify=True)

    # request.legacy_es is always a client for the legacy Elasticsearch index,
    # regardless of whether the 'postgres' feature flag is on.
    # This should be used to write to the legacy search index.
    # TODO: Remove when postgres migration is done
    config.add_request_method(
        lambda r: _legacy_get_client(r.registry.settings),
        name='legacy_es',
        reify=True)

    # If requested, automatically configure the index
    if asbool(settings.get('h.search.autoconfig', False)):
        configure_index(_get_client(settings))
        configure_index(_legacy_get_client(settings))
Beispiel #2
0
def includeme(config):
    settings = config.registry.settings
    settings.setdefault('es.host', 'http://localhost:9200')
    settings.setdefault('es.index', 'annotator')

    # Allow users of this module to register additional search filter and
    # search matcher factories.
    config.registry[FILTERS_KEY] = []
    config.registry[MATCHERS_KEY] = []
    config.add_directive('add_search_filter',
                         lambda c, f: c.registry[FILTERS_KEY].append(f))
    config.add_directive('add_search_matcher',
                         lambda c, m: c.registry[MATCHERS_KEY].append(m))

    # Add a property to all requests for easy access to the elasticsearch
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.add_request_method(lambda r: _get_client(r.registry.settings),
                              name='es',
                              reify=True)

    # If requested, automatically configure the index
    if asbool(settings.get('h.search.autoconfig', False)):
        client = _get_client(settings)
        configure_index(client)
Beispiel #3
0
def reindex(args):
    """Reindex the annotations into a new Elasticsearch index."""
    request = bootstrap(args)

    # Configure the new index
    search_config.configure_index(request.es, args.target)

    # Reindex the annotations
    es_helpers.reindex(client=request.es.conn,
                       source_index=request.es.index,
                       target_index=args.target)

    if args.update_alias:
        request.es.conn.indices.update_aliases(
            body={
                'actions': [
                    # Remove all existing aliases
                    {
                        "remove": {
                            "index": "*",
                            "alias": request.es.index
                        }
                    },
                    # Alias current index name to new target
                    {
                        "add": {
                            "index": args.target,
                            "alias": request.es.index
                        }
                    },
                ]
            })
Beispiel #4
0
def includeme(config):
    settings = config.registry.settings
    settings.setdefault('es.host', 'http://localhost:9200')
    settings.setdefault('es.index', 'annotator')

    # Allow users of this module to register additional search filter and
    # search matcher factories.
    config.registry[FILTERS_KEY] = []
    config.registry[MATCHERS_KEY] = []
    config.add_directive('add_search_filter',
                         lambda c, f: c.registry[FILTERS_KEY].append(f))
    config.add_directive('add_search_matcher',
                         lambda c, m: c.registry[MATCHERS_KEY].append(m))

    # Add a property to all requests for easy access to the elasticsearch
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.add_request_method(lambda r: _get_client(r.registry.settings),
                              name='es',
                              reify=True)

    # If requested, automatically configure the index
    if asbool(settings.get('h.search.autoconfig', False)):
        client = _get_client(settings)
        configure_index(client)
Beispiel #5
0
def includeme(config):
    settings = config.registry.settings
    settings.setdefault('es.host', 'http://localhost:9200')
    settings.setdefault('es.index', 'annotator')

    # Add a property to all requests for easy access to the elasticsearch
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.add_request_method(lambda r: _get_client(r.registry.settings),
                              name='es',
                              reify=True)

    # If requested, automatically configure the index
    if asbool(settings.get('h.search.autoconfig', False)):
        client = _get_client(settings)
        configure_index(client)
Beispiel #6
0
def reindex(args):
    """Reindex the annotations into a new ElasticSearch index."""
    request = bootstrap(args)

    # Configure the new index
    search_config.configure_index(request.es, args.target)

    # Reindex the annotations
    es_helpers.reindex(client=request.es.conn,
                       source_index=request.es.index,
                       target_index=args.target)

    if args.update_alias:
        request.es.conn.indices.update_aliases(body={'actions': [
            # Remove all existing aliases
            {"remove": {"index": "*", "alias": request.es.index}},
            # Alias current index name to new target
            {"add": {"index": args.target, "alias": request.es.index}},
        ]})
Beispiel #7
0
def includeme(config):
    settings = config.registry.settings
    settings.setdefault('es.host', 'http://localhost:9200')
    settings.setdefault('es.index', 'hypothesis')
    settings.setdefault('legacy.es.index', 'annotator')

    # Allow users of this module to register additional search filter and
    # search matcher factories.
    config.registry[FILTERS_KEY] = []
    config.registry[MATCHERS_KEY] = []
    config.add_directive('add_search_filter',
                         lambda c, f: c.registry[FILTERS_KEY].append(f))
    config.add_directive('add_search_matcher',
                         lambda c, m: c.registry[MATCHERS_KEY].append(m))

    # Add a property to all requests for easy access to the elasticsearch
    # client. This can be used for direct or bulk access without having to
    # reread the settings.

    # request.legacy_es is always a client for the legacy Elasticsearch index,
    # regardless of whether the 'postgres' feature flag is on.
    # This should be used to write to the legacy search index.
    config.add_request_method(
        lambda r: _legacy_get_client(r.registry.settings),
        name='legacy_es',
        reify=True)

    # request.es is a client for either the new or the legacy Elasticsearch
    # index, depending on the 'postgres' feature flaf.
    # This should always be used to read from the search index.
    config.add_request_method(_get_client_or_legacy_client,
                              name='es',
                              reify=True)

    # If requested, automatically configure the index
    if asbool(settings.get('h.search.autoconfig', False)):
        configure_index(_get_client(settings))
        configure_index(_legacy_get_client(settings))