I'm having some trouble writing a query to select items where a descendant of the item has certain properties. I'm using Sitecore 7

I want to select the item with the plane icon where any of the green check items has property X with value Y.
Do I need to do something special to index the children? My query attempt was:
var master = Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_master_index");
using (var context = master.CreateSearchContext())
{
var results = context.GetQueryable<SearchResultItem>()
.Where(x => x.TemplateId == productTemplateId
&& x.GetDescendants<SearchResultItem>(context).Any(y => y["X"] == "Y"))
.GetResults();
var hits = results.Hits.ToArray();
}
This throws the following exception:
System.NotSupportedException: The method 'GetDescendants' is not supported. Declaring type: Sitecore.ContentSearch.SearchTypes.SearchResultItem
Result StackTrace:
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitItemMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitMethodCall(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.Visit(Expression expression)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitAnyMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitQueryableMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitMethodCall(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.Visit(Expression expression)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitBinary(BinaryExpression expression)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.Visit(Expression expression)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitWhereMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitQueryableMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitMethodCall(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.Visit(Expression expression)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitGetResultsMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitQueryableExtensionMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitMethodCall(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.Visit(Expression expression)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.Parse(Expression expression)
at Sitecore.ContentSearch.Linq.Parsing.GenericQueryable`2.GetQuery(Expression expression)
at Sitecore.ContentSearch.Linq.Parsing.GenericQueryable`2.Execute[TResult](Expression expression)
at Sitecore.ContentSearch.Linq.QueryableExtensions.GetResults[TSource](IQueryable`1 source)
I'm not sure why.
You can't use
GetDescendantsbecause it has not been implemented in the ContentSearch expression parser.In Sitecore search you need to look for descendants by item path.
So first get the items that match template productTemplateId, then get the items whose item path start with the path of the first result.
I'm sure there is a way to do this in one expression (probably with a Join), but I wouldn't know how.