# Extract edges between terms of a field based on another field\[s\]

**URL:** <https://discuss.elastic.co/t/extract-edges-between-terms-of-a-field-based-on-another-field-s/57415>\
**Category:** Kibana\
**Tags:** elastic-stack-graph\
**Created:** [August 7, 2016, 6:38am UTC](https://discuss.elastic.co/t/extract-edges-between-terms-of-a-field-based-on-another-field-s/57415 "2016-08-07T06:38:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvadood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvadood/32/92740_2.png) [@mvadood](https://discuss.elastic.co/u/mvadood)\
**Post date:** [August 7, 2016, 6:38am UTC](https://discuss.elastic.co/t/extract-edges-between-terms-of-a-field-based-on-another-field-s/57415/1 "2016-08-07T06:38:35Z")

</div>

I illustrate my question with an example. Assume having a type named "post". Each post has a userid field which indicates its author. This is how the post is stored:

{  
"\_index": "test",  
"\_type": "post",  
"\_id": "10098259467307",  
"\_score": 1,  
"\_source": {  
"text": "user 1 message",  
"userid": 1,  
"id": 10098259467307,  
}}  
Is there a way to extract the relationship between the users based on the co-occurrence of terms within the "text" field of posts which they have authored? For example, if there are two posts containing the word "elastic", what I would like to see is an edge between the posts' authors.  
[StackOverflow Link](http://stackoverflow.com/questions/38693291/extract-edges-between-terms-of-a-field-based-on-another-fields-in-elastic-grap)

---

<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:** [August 7, 2016, 12:14pm UTC](https://discuss.elastic.co/t/extract-edges-between-terms-of-a-field-based-on-another-field-s/57415/2 "2016-08-07T12:14:54Z")

</div>

This demo is based on stack overflow posts and graphs the tags and people involved in them: [https://m.youtube.com/watch?v=1QwmJ\_FCMqU&feature=youtu.be](https://m.youtube.com/watch?v=1QwmJ_FCMqU&feature=youtu.be)

---

<div class="post-metadata">

**Author:** ![mvadood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvadood/32/92740_2.png) [@mvadood](https://discuss.elastic.co/u/mvadood)\
**Post date:** [August 10, 2016, 3:01pm UTC](https://discuss.elastic.co/t/extract-edges-between-terms-of-a-field-based-on-another-field-s/57415/3 "2016-08-10T15:01:16Z")

</div>

Thanks @Mark_Harwood  
I watched the video but my question still remains.  
In the stack overflow case for example, is this hypothetical graph achievable?  
"A graph where the vertices stand for (just) the user names and a relationship between any two nodes summarizes the number of common tags they have contributed to"

---

<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:** [August 10, 2016, 3:31pm UTC](https://discuss.elastic.co/t/extract-edges-between-terms-of-a-field-based-on-another-field-s/57415/4 "2016-08-10T15:31:03Z")

</div>

> I watched the video but my question still remains

Hopefully the video demonstrated that there's often a need to cherry-pick _which_ terms you use as the glue between people - you typically shouldn't use them all. In the StackOverflow data, tags like Javascript and Java are super-common and are not a useful basis on which to link people. That is why I advocated a solution where only selected tags are made visible in the graph and are used to explain the connection between people.

> [@mvadood](#):
>
> is this hypothetical graph achievable?

Let's assume then that all tags are equally interesting so you want to remove them from being visible in your graph in the way you describe. The important points to remember is that in elastic Graph the vertices are always terms and the edges represent one or more docs. Clicking on an edge will show how many docs a pair of terms have in common. To present the model you describe you'd need tag-centric docs e.g.

```
POST test/tag
{
	"tag": "elasticsearch",
	"contributors":["Shay", "Uri"]
}
POST test/tag
{
	"tag": "kibana",
	"contributors":["Rashid", "Uri"]
}

```

There are a few of concerns with this approach:

1. You probably need to write code to re-orient your source data in this fashion (see "entity centric indexing")
2. Some tags e.g. Java or Javascript could have prohibitively large lists of contributors
3. The common-place (boring) tags like "Java" or "Javascript" will link everyone together in the diagram
4. The interesting (rare) tags will not be emphasised (2 people sharing a rare topic counts for the same as 2 people sharing a common one)
5. The specialisms a person has (_repeated_ posts tagged with neo4j) will not be emphasised in this model.

So you can do it this way, but I'm not sure it makes sense.

---

<div class="post-metadata">

**Author:** ![mvadood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvadood/32/92740_2.png) [@mvadood](https://discuss.elastic.co/u/mvadood)\
**Post date:** [August 10, 2016, 6:59pm UTC](https://discuss.elastic.co/t/extract-edges-between-terms-of-a-field-based-on-another-field-s/57415/5 "2016-08-10T18:59:09Z")

</div>

I get it now  
Many thanks

---

<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:** [July 6, 2017, 1:42pm UTC](https://discuss.elastic.co/t/extract-edges-between-terms-of-a-field-based-on-another-field-s/57415/6 "2017-07-06T13:42:42Z")

</div>


