예제 #1
0
파일: snapshot.py 프로젝트: tofler/toflerdb
def get_related_nodes(nodeid):
    query = {"query": {"match": {"id": nodeid}}}
    es = Common.get_elasticsearch_connection()
    response = es.search(index=SNAPSHOT_INDEX,
                         doc_type=SNAPSHOT_DOC_TYPE,
                         body=query)
    # response = response[1]
    if response['hits']['total'] < 1:
        return None
    node = response['hits']['hits'][0]
    references = _gather_references(node['_source'])
    if len(references) == 0:
        return None
    match_segments = []
    for ref in references:
        match_segments.append({"match": {"id": ref[1]}})

    query = {"query": {"bool": {"should": match_segments}}}
    response = es.search(index=SNAPSHOT_INDEX,
                         doc_type=SNAPSHOT_DOC_TYPE,
                         body=query)
    # response = response[1]
    if response['hits']['total'] < 1:
        return None
    return {'relationships': references, 'nodes': response['hits']['hits']}
예제 #2
0
파일: snapshot.py 프로젝트: tofler/toflerdb
def get_snapshot_nodes(**kwargs):
    for key, val in kwargs.iteritems():
        break

    if not isinstance(val, list):
        val = [val]
    es = Common.get_elasticsearch_connection()
    q_string_arr = []
    for elem in val:
        q_string_arr.append(
            {"query_string": {
                "fields": [key, "*.%s" % key],
                "query": elem
            }})
    try:
        query = {"query": {"bool": {"should": q_string_arr}}}
        response = es.search(index=SNAPSHOT_INDEX,
                             doc_type=SNAPSHOT_DOC_TYPE,
                             body=query)
        entities = {}
        if response['hits']['total'] > 0:
            for hit in response['hits']['hits']:
                entities[hit['_id']] = hit['_source']
            return entities
        return None
    except Exception as e:
        logger = Common.get_logger()
        logger.error(str(e))
        return None
예제 #3
0
파일: dbutils.py 프로젝트: tofler/toflerdb
def get_complete_snapshot_mapping():
    es = Common.get_elasticsearch_connection()
    complete_mapping = es.indices.get_mapping(index=SNAPSHOT_INDEX,
                                              doc_type=SNAPSHOT_DOC_TYPE)

    return complete_mapping[SNAPSHOT_INDEX]['mappings'][SNAPSHOT_DOC_TYPE][
        'properties']
예제 #4
0
파일: snapshot.py 프로젝트: tofler/toflerdb
def find_nodes_with_incoming_references(nodeid):
    query = {"query": {"match": {"_all": nodeid}}}
    es = Common.get_elasticsearch_connection()
    response = es.search(index=SNAPSHOT_INDEX,
                         doc_type=SNAPSHOT_DOC_TYPE,
                         body=query)
    # response = response[1]
    if response['hits']['total'] < 1:
        return []
    hits = response['hits']['hits']
    return hits
예제 #5
0
 def create_es_mappings(self):
     self.log("Creating Index Mapping ...")
     es = Common.get_elasticsearch_connection()
     es.indices.delete(
         index=config.SNAPSHOT_INDEX, ignore=[400, 404])
     mapping = open(self.INDEX_MAPPING_FILE).read()
     es.indices.create(
         index=config.SNAPSHOT_INDEX, ignore=400, body=mapping)
     mapping = open(self.DOCTYPE_MAPPING_FILE).read()
     es.indices.put_mapping(
         index=config.SNAPSHOT_INDEX,
         doc_type=config.SNAPSHOT_DOC_TYPE,
         ignore=400, body=mapping)
예제 #6
0
파일: snapshot.py 프로젝트: tofler/toflerdb
def freetextsearch(query):
    elastic_query = {"query": {"match": {"_all": query}}}
    es = Common.get_elasticsearch_connection()
    response = es.search(index=SNAPSHOT_INDEX,
                         doc_type=SNAPSHOT_DOC_TYPE,
                         body=elastic_query)
    output = []
    hits = response['hits']['hits']
    for hit in hits:
        src = hit['_source']
        opsrc = {}
        _create_freetextsearch_output(src, src, opsrc)
        output.append(opsrc)
    return output
예제 #7
0
파일: dbutils.py 프로젝트: tofler/toflerdb
def insert_entity(entity_id, entity_body):
    es = Common.get_elasticsearch_connection()
    es.index(SNAPSHOT_INDEX, 'entity', body=entity_body, id=entity_id)
예제 #8
0
파일: dbutils.py 프로젝트: tofler/toflerdb
def create_snapshot_mapping(mapping):
    es = Common.get_elasticsearch_connection()
    es.indices.put_mapping(index=SNAPSHOT_INDEX,
                           doc_type=SNAPSHOT_DOC_TYPE,
                           body=mapping)