示例#1
0
def index_record(recid, json):
    """Index a record in elasticsearch."""
    es.index(
        index='records',
        doc_type='record',
        body=json,
        id=recid
    )
示例#2
0
def index_record(recid, json):
    """Index a record in elasticsearch."""
    index = get_record_index(json) or cfg['SEARCH_ELASTIC_DEFAULT_INDEX']
    es.index(
        index=index,
        doc_type='record',
        body=json,
        id=recid
    )
示例#3
0
def index_collection_percolator(name, dbquery):
    """Create an elasticsearch percolator for a given query."""
    indices = set(cfg["SEARCH_ELASTIC_COLLECTION_INDEX_MAPPING"].values())
    indices.add(cfg['SEARCH_ELASTIC_DEFAULT_INDEX'])
    for index in indices:
        es.index(
            index=index,
            doc_type='.percolator',
            body={'query': Query(dbquery).query.accept(ElasticSearchDSL())},
            id=name)
示例#4
0
def index_collection_percolator(name, dbquery):
    """Create an elasticsearch percolator for a given query."""
    from invenio_search.api import Query
    from invenio_search.walkers.elasticsearch import ElasticSearchDSL
    es.index(
        index='records',
        doc_type='.percolator',
        body={'query': Query(dbquery).query.accept(ElasticSearchDSL())},
        id=name
    )
示例#5
0
def index_collection_percolator(name, dbquery):
    """Create an elasticsearch percolator for a given query."""
    indices = set(cfg["SEARCH_ELASTIC_COLLECTION_INDEX_MAPPING"].values())
    indices.add(cfg["SEARCH_ELASTIC_DEFAULT_INDEX"])
    for index in indices:
        es.index(
            index=index,
            doc_type=".percolator",
            body={"query": Query(dbquery).query.accept(ElasticSearchDSL())},
            id=name,
        )
示例#6
0
def index_collection_percolator(name, dbquery):
    """Create an elasticsearch percolator for a given query."""
    from invenio_ext.es import es
    indices = set(cfg["SEARCH_ELASTIC_COLLECTION_INDEX_MAPPING"].values())
    indices.add(cfg['SEARCH_ELASTIC_DEFAULT_INDEX'])
    for index in indices:
        es.index(
            index=index,
            doc_type='.percolator',
            body={'query': Query(dbquery).query.accept(ElasticSearchDSL())},
            id=name
        )
示例#7
0
def index_record(recid, json):
    """Index a record in elasticsearch."""
    from invenio_ext.es import es
    index = get_record_index(json) or cfg['SEARCH_ELASTIC_DEFAULT_INDEX']
    before_record_index.send(recid, json=json, index=index)
    index_result = es.index(
        index=index,
        doc_type='record',
        body=json,
        id=recid
    )
    if index_result['_shards']['successful'] > 0:
        after_record_index.send(recid, json=json)
示例#8
0
def index_record(recid, json):
    """Index a record in elasticsearch."""
    before_record_index.send(recid, json=json)
    index = get_record_index(json) or cfg["SEARCH_ELASTIC_DEFAULT_INDEX"]
    es.index(index=index, doc_type="record", body=json, id=recid)
示例#9
0
def index_record(recid, json):
    """Index a record in elasticsearch."""
    index = get_record_index(json) or cfg['SEARCH_ELASTIC_DEFAULT_INDEX']
    es.index(index=index, doc_type='record', body=json, id=recid)
示例#10
0
def index_holdingpen_record(sender, **kwargs):
    """Index a Holding Pen record."""
    from invenio_ext.es import es
    from invenio_records.api import Record
    from invenio_records.signals import before_record_index
    from invenio_records.recordext.functions.get_record_collections import (
        get_record_collections,
    )
    from invenio_records.tasks.index import get_record_index

    from invenio_workflows.registry import workflows

    if not sender.workflow:
        # No workflow registered to object yet. Skip indexing
        return

    if sender.version == ObjectVersion.INITIAL:
        # Ignore initial versions
        return

    workflow = workflows.get(sender.workflow.name)
    if not workflow:
        current_app.logger.info(
            "Workflow {0} not found for sender: {1}".format(
                sender.workflow.name, sender.id
            )
        )
        return

    if not hasattr(sender, 'data'):
        sender.data = sender.get_data()
    if not hasattr(sender, 'extra_data'):
        sender.extra_data = sender.get_extra_data()

    record = Record({})
    record["version"] = ObjectVersion.name_from_version(sender.version)
    record["type"] = sender.data_type
    record["status"] = sender.status
    record["created"] = sender.created.isoformat()
    record["modified"] = sender.modified.isoformat()
    record["uri"] = sender.uri
    record["id_workflow"] = sender.id_workflow
    record["id_user"] = sender.id_user
    record["id_parent"] = sender.id_parent
    record["workflow"] = sender.workflow.name
    try:
        record.update(workflow.get_record(sender))
    except Exception as err:
        current_app.logger.exception(err)

    try:
        record.update(workflow.get_sort_data(sender))
    except Exception as err:
        current_app.logger.exception(err)

    # Add collection to get correct mapping
    record["_collections"] = get_record_collections(record)

    # Depends on "_collections" being filled correctly for record
    record_index = get_record_index(record) or current_app.config["SEARCH_ELASTIC_DEFAULT_INDEX"]

    # Trigger any before_record_index receivers
    before_record_index.send(sender.id, json=record, index=record_index)

    if record_index:
        index = current_app.config['WORKFLOWS_HOLDING_PEN_ES_PREFIX'] + record_index
        es.index(
            index=index,
            doc_type=current_app.config["WORKFLOWS_HOLDING_PEN_DOC_TYPE"],
            body=dict(record),
            id=sender.id
        )