Example #1
0
def get_entity(entity_id):
    """Fetch an entity from the index."""
    if entity_id is None:
        return None
    for index in entities_index_list():
        result = es.get(index=index,
                        doc_type='doc',
                        id=entity_id,
                        ignore=[404],
                        _source_exclude=['text'])
        result = unpack_result(result)
        if result is not None:
            return result
    def _resolve_index(self, cache):
        queries = []
        for (type_, id_) in cache.keys():
            if type_ in [Collection]:
                index = collections_index()
                query = {'_index': index, '_id': id_}
                queries.append(((type_, id_), query))
            elif type_ in [Document, Entity]:
                for index in entities_index_list():
                    query = {'_index': index, '_id': id_}
                    queries.append(((type_, id_), query))

        if not len(queries):
            return

        results = es.mget(body={'docs': [q[1] for q in queries]},
                          _source_exclude=['text'])
        for (key, _), doc in zip(queries, results['docs']):
            if cache.get(key) is None:
                cache[key] = unpack_result(doc)
Example #3
0
def delete_entity(entity_id, sync=False):
    """Delete an entity from the index."""
    refresh = 'wait_for' if sync else False
    for index in entities_index_list():
        es.delete(index=index, doc_type='doc', id=str(entity_id),
                  refresh=refresh, ignore=[404])
Example #4
0
def delete_entity(entity_id):
    """Delete an entity from the index."""
    for index in entities_index_list():
        es.delete(index=index, doc_type='doc', id=entity_id, ignore=[404])