# How to index graphs ? And how to search in graphs?

**URL:** <https://discuss.elastic.co/t/how-to-index-graphs-and-how-to-search-in-graphs/187117>\
**Category:** Elasticsearch\
**Created:** [June 24, 2019, 12:18pm UTC](https://discuss.elastic.co/t/how-to-index-graphs-and-how-to-search-in-graphs/187117 "2019-06-24T12:18:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wassim\_Ben\_Amor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wassim_ben_amor/32/39799_2.png) [@Wassim\_Ben\_Amor](https://discuss.elastic.co/u/Wassim_Ben_Amor)\
**Post date:** [June 24, 2019, 12:18pm UTC](https://discuss.elastic.co/t/how-to-index-graphs-and-how-to-search-in-graphs/187117/1 "2019-06-24T12:18:02Z")

</div>

Hello,  
I'm trying to find a way to index a graph.

The idea is :  
I have documents like :  
{ "name": "apple",  
"edges": [  
{  
"type" : "isA",  
"value" : "company"  
} ,  
{  
"type" : "isA",  
"value" : "fruit"  
}  
]  
}

or

{ "name": "happy",  
"edges": [  
{  
"type" : "synonym",  
"value" : "excited"  
} ,  
{  
"type" : "isA",  
"value" : "adjective"  
}  
]  
}

So, as you can see, when I search for the word apple, I have to see the different isA or synonyms relations ...  
the object fruit or company also represents a document.

So what is the best way to index all this graph, so it can be easy after this, to search for all the relations for a given word ?

Thank you !

---

<div class="post-metadata">

**Author:** ![Wassim\_Ben\_Amor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wassim_ben_amor/32/39799_2.png) [@Wassim\_Ben\_Amor](https://discuss.elastic.co/u/Wassim_Ben_Amor)\
**Post date:** [June 26, 2019, 8:47am UTC](https://discuss.elastic.co/t/how-to-index-graphs-and-how-to-search-in-graphs/187117/2 "2019-06-26T08:47:51Z")

</div>

Any help please ?

---

<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:** [June 26, 2019, 9:06am UTC](https://discuss.elastic.co/t/how-to-index-graphs-and-how-to-search-in-graphs/187117/3 "2019-06-26T09:06:01Z")

</div>

If you put all the "nyms" (synonym, hypernym etc) into the same elasticsearch doc then it can become harder to run aggregations because each of the nym objects has two properties - `type` and `value`. You would need to use `nested` docs to avoid muddling the type of one nym with that of another (and Kibana doesn't do nested).  
The alternative is to have separate docs for each nym so you'd repeat the root term in each doc (eg `name:apple`) and have a single `type` and `value` field to associate a single nym to that root term. You can then use query and aggregate on these docs without resorting to more complex `nested` structures.

---

<div class="post-metadata">

**Author:** ![Wassim\_Ben\_Amor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wassim_ben_amor/32/39799_2.png) [@Wassim\_Ben\_Amor](https://discuss.elastic.co/u/Wassim_Ben_Amor)\
**Post date:** [July 15, 2019, 4:50pm UTC](https://discuss.elastic.co/t/how-to-index-graphs-and-how-to-search-in-graphs/187117/4 "2019-07-15T16:50:31Z")

</div>

So, I think it's not the best way to use elasticSearch to build something like conceptNet.  
Because there is no way to have the concept of a document pointing to another document.  
I just wanted to use the power of string searching of elasticsearch.

---

<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:** [August 12, 2019, 4:50pm UTC](https://discuss.elastic.co/t/how-to-index-graphs-and-how-to-search-in-graphs/187117/5 "2019-08-12T16:50:37Z")

</div>

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