Skip to content

Elastic Configuration

sbarzilay edited this page Oct 10, 2017 · 1 revision

Mapping Elasticsearch

In order to map data from elasticsearch our mapping file will look something like this:

{
  "class": "org.unipop.elastic.ElasticSourceProvider",
  "addresses": "http://localhost:9200",
  "vertices": [],
  "edges": []
}

Mapping Elements From Elasticsearch

Each element we map requires some more information from us about it's whereabouts,
we'll need to provide an index and if we want a type.

So elements will look like:

{
  "index": "my_elastic_index"
}

A vertex will look like:

{
  "index": "my_vertex_index",
  "id": "@_id",
  "label": "@_type",
  "properties": {}
}

In elasticsearch we have several ways you can map edges depending on how your data is structured.

Document Edges

Each edge is represented by it's own document in elasticsearch:

{
  "index": "my_edge_index",
  "id": "@_id",
  "label": "edge_label",
  "properties": {},
  "outVertex": {
    "ref": true,
    "id": "@out_vertex_id",
    "label": "@out_vertex_label"
  },
  "inVertex": {
      "ref": true,
      "id": "@in_vertex_id",
      "label": "@in_vertex_label"
    }
}
Inner edges

Each edge is represented by a set of fields from a document containing a vertex:

{
  "index":"my_vertex_index",
  "id": "@_id",
  "label": "my_vertex_label",
  "properties": {},
  "edges": [
    {
      "id": "@edgeId",
      "label": "@edgeLabel",
      "direction": "OUT",
      "properties": {},
      "vertex":{
        "ref": true,
        "id": "@inner_vertex_id",
        "label": "@inner_vertex_label"
      }
    }
  ]
}

Because this edge is a child within our vertex we need to specify its direction.
Our elastic document will look something like:

{
  "_index": "my_vertex_index",
  "_type": "my_type",
  "_id": "an id",
  "_source":{
    "edgeId": "an edge id",
    "edgeLabel": "an edge label",
    "inner_vertex_id": "an inner vertex id",
    "inner_vertex_label": "an inner vertex label"
  }
}
Nested Edges

Each edge is represented by a nested document within a our vertex document:

{
  "index":"my_vertex_index",
  "id": "@_id",
  "label": "my_vertex_label",
  "properties": {},
  "edges": [
    {
      "path": "myEdges",
      "id": "@edgeId",
      "label": "@edgeLabel",
      "direction": "OUT",
      "properties": {},
      "vertex":{
        "ref": true,
        "id": "@inner_vertex_id",
        "label": "@inner_vertex_label"
      }
    }
  ]
}

Because this edge is a child within our vertex we need to specify its direction.
Our elastic document will look something like:

{
  "_index": "my_vertex_index",
  "_type": "my_type",
  "_id": "an id",
  "_source":{
    "myEdges":[
      {
        "edgeId": "an edge id",
        "edgeLabel": "an edge label",
        "inner_vertex_id": "an inner vertex id",
        "inner_vertex_label": "an inner vertex label"
      }
    ]
  }
}

This requires myEdges to be mapped as a nested object in your elasticsearch _mapping.