# How to query linked documents by property

**URL:** <https://community.bloomreach.com/t/how-to-query-linked-documents-by-property/353>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [August 31, 2018, 11:10am UTC](https://community.bloomreach.com/t/how-to-query-linked-documents-by-property/353 "2018-08-31T11:10:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mare\_K](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Mare\_K](https://community.bloomreach.com/u/Mare_K)\
**Post date:** [August 31, 2018, 11:10am UTC](https://community.bloomreach.com/t/how-to-query-linked-documents-by-property/353/1 "2018-08-31T11:10:10Z")

</div>

I have a custom component which should output all NewsDocument (documenttype) which have specific Category (linked documenttype). I will pass category\_id as a parameter.

I found the following query constraint in documentation but it only works if Category is a Compound type. In my case Category is Document Type and linked to NewsDocument.

public void doBeforeRender() {  
// …  
HstQuery newsQuery = HstQueryBuilder.create(scope)  
.ofTypes(NewsDocument.class)  
.where(constraint(“mysite:category/@mysite:category\_id”).contains(‘sport’))  
.build();  
HstQueryResult result = newsQuery.execute();  
// …  
}

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [September 3, 2018, 7:54am UTC](https://community.bloomreach.com/t/how-to-query-linked-documents-by-property/353/2 "2018-09-03T07:54:01Z")

</div>

If your category is a linked document, then it will be represented in your document as a uuid in a property of a subnode (or possibly as a direct property). Your query won’t work because you are looking for a property that doesn’t exist there. It’s not possible to do this with the query builder, and I’m not sure if you can even express it in xpath or sql (but it may be). In any case, I think this would turn out to be difficult to write and maintain even if it is possible and expensive to execute.

You should look into the taxonomy plugin.

> **[Taxonomy Plugin - Bloomreach Experience - Open Source CMS](https://documentation.bloomreach.com/14/library/concepts/plugins/taxonomy/about.html)**
>
> Open Source Enterprise Content Management
