# Directed graph (or) merge vertices with same name

**URL:** <https://discuss.elastic.co/t/directed-graph-or-merge-vertices-with-same-name/104959>\
**Category:** Kibana\
**Tags:** elastic-stack-graph\
**Created:** [October 23, 2017, 7:34pm UTC](https://discuss.elastic.co/t/directed-graph-or-merge-vertices-with-same-name/104959 "2017-10-23T19:34:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![krishna\_chaitanya](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@krishna\_chaitanya](https://discuss.elastic.co/u/krishna_chaitanya)\
**Post date:** [October 23, 2017, 7:34pm UTC](https://discuss.elastic.co/t/directed-graph-or-merge-vertices-with-same-name/104959/1 "2017-10-23T19:34:09Z")

</div>

I am trying to create a flow path for different user activities. For example, users can be redirected from url 'A' to url 'B' or to 'C' etc. I would like to calculate the top redirections. I want to show this using graph visualization.

I have created a data model this way:  
`{field:12345, 'from_url':'A', 'to_url': 'B' }`  
`{field:12345, 'from_url':'A', 'to_url': 'C' }`  
`{field:12345, 'from_url':'B', 'to_url': 'C' }`  
`{field:12345, 'from_url':'A', 'to_url': 'B' }`

So, when searching for `field:12345` , a graph like this is what I am looking for(counts on edges is optional):

![elastic1](https://us1.discourse-cdn.com/elastic/original/3X/d/1/d18248f28fa48edf1dfec5376a0d19edd9db9115.JPG)

I modeled my graph with vertices `from_url` and `to_url`. I also want my graph to produce analytics of all data, so I increased `sample_size`, set `use_significance` to false and `min_doc_count` as 1 as mentioned in [here](https://www.elastic.co/guide/en/kibana/5.6/graph-troubleshooting.html).

The problem is with x-pack Graph in Kibana, I am only able to get graph this way:

![image](https://us1.discourse-cdn.com/elastic/original/3X/3/7/375f9d8cd8a75e1b2dfcb0fda0059cc166264db0.png)

I understand the meaning for this graph as vertices are colored. But, this is getting clumsy as the number of vertices increase. The related url (Ex: url 'B') vertices are not close to each other, they are far apart on the graph. Is there any way to merge the vertices which have common name (Ex: url 'B')? and produce a directed graph similar to first visualization?  
If not, do I have to change my data model? or does any other visualization help in my usecase?

Thanks !

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [October 24, 2017, 8:13am UTC](https://discuss.elastic.co/t/directed-graph-or-merge-vertices-with-same-name/104959/2 "2017-10-24T08:13:27Z")

</div>

The elastic Graph is undirected. One way around this is to introduce node terms that represent the route e.g. `A->B`.  
Here's an example mapping and data for your example:

```
DELETE test
PUT test
{
  "settings": {
	"number_of_replicas": 0,
	"number_of_shards": 1
  },
  "mappings": {
	"doc":{
	  "properties": {
		"node":{"type":"keyword"},
		"route":{"type":"keyword"}
	  }
	}
  }
}

POST /test/edge/_bulk
{ "index" : {} }
{ "node" : "A", "route":"A->B" }
{ "index" : {} }
{ "node" : "B", "route":"A->B" }
{ "index" : {} }
{ "node" : "A", "route":"A->C" }
{ "index" : {} }
{ "node" : "C", "route":"A->C" }
{ "index" : {} }
{ "node" : "B", "route":"B->C" }
{ "index" : {} }
{ "node" : "C", "route":"B->C" }
{ "index" : {} }
{ "node" : "A", "route":"A->B" }
{ "index" : {} }
{ "node" : "B", "route":"A->B" }

```

..and here's the resulting graph visualization:

 ![Kibana](https://us1.discourse-cdn.com/elastic/original/3X/8/a/8ae21302d69064bb0d1a89ea1f233861df06998d.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 21, 2017, 8:13am UTC](https://discuss.elastic.co/t/directed-graph-or-merge-vertices-with-same-name/104959/3 "2017-11-21T08:13:43Z")

</div>

Closed on November 21, 2017, 8:13am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
