# Quering generic tree structures

**URL:** https://discuss.elastic.co/t/quering-generic-tree-structures/16998
**Category:** Elasticsearch
**Created:** [April 14, 2014, 10:29am UTC](https://discuss.elastic.co/t/quering-generic-tree-structures/16998 "2014-04-14T10:29:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mariusz\_Donigiewicz](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@Mariusz\_Donigiewicz](https://discuss.elastic.co/u/Mariusz_Donigiewicz)
#### Post date: [April 14, 2014, 10:29am UTC](https://discuss.elastic.co/t/quering-generic-tree-structures/16998/1 "2014-04-14T10:29:04Z")

</div>

Hi  
I believe this is not the first topic for this sort of questions.

What i wanted to achieve is to be able to effectively query for in generic  
structure of entities (lets say categories)

{  
"mdm" : {  
"mappings" : {  
"categories" : {  
"\_parent" : {  
"type" : "categories"  
},  
"\_routing" : {  
"required" : true  
},  
"properties" : {  
"category\_description" : {  
"type" : "string"  
},  
"category\_id" : {  
"type" : "long"  
},  
"category\_parent" : {  
"type" : "string"  
},  
"category\_path" : {  
"type" : "string"  
},  
"category\_title" : {  
"type" : "string"  
}  
}  
}  
}  
}  
}

If put some data to index

{"category\_id":10000,"category\_title":"clothes","category\_description":"all  
clothes", "category\_path" :"10000"}  
{"category\_id":10001,"category\_title":"shirts","category\_description":"just  
shirts clothes", "category\_parent" : "10000" ,"category\_path"  
:"10000/10001"}  
{"category\_id":10002,"category\_title":"summer  
shirt","category\_description":"just summer clothes", "category\_parent" :  
"10001", "category\_path" :"10000/10001/10002"}  
{"category\_id":10003,"category\_title":"baby  
shirt","category\_description":"just baby clothes", "category\_parent" :  
"10001", "category\_path" :"10000/10001/10003"}  
{"category\_id":10004,"category\_title":"boys baby  
","category\_description":"just a boy baby shirts", "category\_parent" :  
"10003", "category\_path" :"10000/10001/10003/10004"}  
{"category\_id":10005,"category\_title":"girls baby  
","category\_description":"just a girl baby shirts", "category\_parent" :  
"10003", "category\_path" :"10000/10001/10003/10005"}

{"category\_id":10006,"category\_title":"trouses","category\_description":"all  
trouses", "category\_parent" : "10000" ,"category\_path" :"10000/10006"}  
{"category\_id":10007,"category\_title":"jeans","category\_description":"all  
jeans", "category\_parent" : "10006" ,"category\_path" :"10000/10006/10007"}  
{"category\_id":10008,"category\_title":"chinos","category\_description":"chinos  
jeans", "category\_parent" : "10006" ,"category\_path" :"10000/10006/10008"}  
{"category\_id":10009,"category\_title":"chinos +  
tshirt","category\_description":"chinos jeans", "category\_parent" : "10009"  
,"category\_path" :"10000/10006/10008/10009"}

I wan't to fullfill my business use case

UC1 : Give me all sub categories of the given one for its title,  
description ....

Addtionally I have put the calculated category\_path to be able to easier  
navigate through out the tree.

The question is this possible (ideally only query time, without providing  
any flatting fields) to query and fullfill the UC1.

I have tried a query like

{  
"query" : {  
"match\_all" : { }  
},  
"post\_filter" : {  
"has\_parent" : {  
"query" : {  
"match" : {  
"category\_title" : {  
"query" : "\*shirt",  
"type" : "boolean"  
}  
}  
},  
"parent\_type" : "categories"  
}  
},  
"explain" : true  
}

{  
"query" : {  
"match\_all" : { }  
},  
"post\_filter" : {  
"has\_parent" : {  
"query" : {  
"regexp" : {  
"category\_title" : {  
"value" : ".\*shirt"  
}  
}  
},  
"parent\_type" : "categories"  
}  
},  
"explain" : true  
}

But it is not working as it should - reading documentation it also has no  
capabilities to work in tree like manner.

Is it possible to get within one query for criteria like : "category\_title"  
: "\*shirt"

And retrieve the data from different sub tree branches with in one query  
???

{"category\_id":10002,"category\_title":"summer  
shirt","category\_description":"just summer clothes", "category\_parent" :  
"10001", "category\_path" :"10000/10001/10002"}  
{"category\_id":10003,"category\_title":"baby  
shirt","category\_description":"just baby clothes", "category\_parent" :  
"10001", "category\_path" :"10000/10001/10003"}  
{"category\_id":10004,"category\_title":"boys baby  
","category\_description":"just a boy baby shirts", "category\_parent" :  
"10003", "category\_path" :"10000/10001/10003/10004"}  
{"category\_id":10005,"category\_title":"girls baby  
","category\_description":"just a girl baby shirts", "category\_parent" :  
"10003", "category\_path" :"10000/10001/10003/10005"}  
{"category\_id":10009,"category\_title":"chinos +  
t-shirt","category\_description":"chinos jeans", "category\_parent" : "10009"  
,"category\_path" :"10000/10006/10008/10009"}

Regards M.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/11faba43-6ba3-434b-b123-e105b5b71752%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/11faba43-6ba3-434b-b123-e105b5b71752%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Amit\_Tripathi](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@Amit\_Tripathi](https://discuss.elastic.co/u/Amit_Tripathi)
#### Post date: [April 14, 2014, 12:33pm UTC](https://discuss.elastic.co/t/quering-generic-tree-structures/16998/2 "2014-04-14T12:33:15Z")

</div>

Json for Indexing Data in Elastic Search using C#.Net

pl help

On Monday, April 14, 2014 3:59:04 PM UTC+5:30, Mariusz Donigiewicz wrote:

> Hi  
> I believe this is not the first topic for this sort of questions.
> 
> What i wanted to achieve is to be able to effectively query for in generic  
> structure of entities (lets say categories)
> 
> {  
> "mdm" : {  
> "mappings" : {  
> "categories" : {  
> "\_parent" : {  
> "type" : "categories"  
> },  
> "\_routing" : {  
> "required" : true  
> },  
> "properties" : {  
> "category\_description" : {  
> "type" : "string"  
> },  
> "category\_id" : {  
> "type" : "long"  
> },  
> "category\_parent" : {  
> "type" : "string"  
> },  
> "category\_path" : {  
> "type" : "string"  
> },  
> "category\_title" : {  
> "type" : "string"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> If put some data to index
> 
> {"category\_id":10000,"category\_title":"clothes","category\_description":"all  
> clothes", "category\_path" :"10000"}  
> {"category\_id":10001,"category\_title":"shirts","category\_description":"just  
> shirts clothes", "category\_parent" : "10000" ,"category\_path"  
> :"10000/10001"}  
> {"category\_id":10002,"category\_title":"summer  
> shirt","category\_description":"just summer clothes", "category\_parent" :  
> "10001", "category\_path" :"10000/10001/10002"}  
> {"category\_id":10003,"category\_title":"baby  
> shirt","category\_description":"just baby clothes", "category\_parent" :  
> "10001", "category\_path" :"10000/10001/10003"}  
> {"category\_id":10004,"category\_title":"boys baby  
> ","category\_description":"just a boy baby shirts", "category\_parent" :  
> "10003", "category\_path" :"10000/10001/10003/10004"}  
> {"category\_id":10005,"category\_title":"girls baby  
> ","category\_description":"just a girl baby shirts", "category\_parent" :  
> "10003", "category\_path" :"10000/10001/10003/10005"}
> 
> {"category\_id":10006,"category\_title":"trouses","category\_description":"all  
> trouses", "category\_parent" : "10000" ,"category\_path" :"10000/10006"}  
> {"category\_id":10007,"category\_title":"jeans","category\_description":"all  
> jeans", "category\_parent" : "10006" ,"category\_path" :"10000/10006/10007"}  
> {"category\_id":10008,"category\_title":"chinos","category\_description":"chinos  
> jeans", "category\_parent" : "10006" ,"category\_path" :"10000/10006/10008"}  
> {"category\_id":10009,"category\_title":"chinos +  
> tshirt","category\_description":"chinos jeans", "category\_parent" : "10009"  
> ,"category\_path" :"10000/10006/10008/10009"}
> 
> I wan't to fullfill my business use case
> 
> UC1 : Give me all sub categories of the given one for its title,  
> description ....
> 
> Addtionally I have put the calculated category\_path to be able to easier  
> navigate through out the tree.
> 
> The question is this possible (ideally only query time, without providing  
> any flatting fields) to query and fullfill the UC1.
> 
> I have tried a query like
> 
> {  
> "query" : {  
> "match\_all" : { }  
> },  
> "post\_filter" : {  
> "has\_parent" : {  
> "query" : {  
> "match" : {  
> "category\_title" : {  
> "query" : "\*shirt",  
> "type" : "boolean"  
> }  
> }  
> },  
> "parent\_type" : "categories"  
> }  
> },  
> "explain" : true  
> }
> 
> {  
> "query" : {  
> "match\_all" : { }  
> },  
> "post\_filter" : {  
> "has\_parent" : {  
> "query" : {  
> "regexp" : {  
> "category\_title" : {  
> "value" : ".\*shirt"  
> }  
> }  
> },  
> "parent\_type" : "categories"  
> }  
> },  
> "explain" : true  
> }
> 
> But it is not working as it should - reading documentation it also has no  
> capabilities to work in tree like manner.
> 
> Is it possible to get within one query for criteria like : "category\_title"  
> : "\*shirt"
> 
> And retrieve the data from different sub tree branches with in one query  
> ???
> 
> {"category\_id":10002,"category\_title":"summer  
> shirt","category\_description":"just summer clothes", "category\_parent" :  
> "10001", "category\_path" :"10000/10001/10002"}  
> {"category\_id":10003,"category\_title":"baby  
> shirt","category\_description":"just baby clothes", "category\_parent" :  
> "10001", "category\_path" :"10000/10001/10003"}  
> {"category\_id":10004,"category\_title":"boys baby  
> ","category\_description":"just a boy baby shirts", "category\_parent" :  
> "10003", "category\_path" :"10000/10001/10003/10004"}  
> {"category\_id":10005,"category\_title":"girls baby  
> ","category\_description":"just a girl baby shirts", "category\_parent" :  
> "10003", "category\_path" :"10000/10001/10003/10005"}  
> {"category\_id":10009,"category\_title":"chinos +  
> t-shirt","category\_description":"chinos jeans", "category\_parent" : "10009"  
> ,"category\_path" :"10000/10006/10008/10009"}
> 
> Regards M.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f52b3910-7a6c-47cd-819c-cd485bc6925f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f52b3910-7a6c-47cd-819c-cd485bc6925f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:35am UTC](https://discuss.elastic.co/t/quering-generic-tree-structures/16998/3 "2017-07-06T01:35:59Z")

</div>


