# Nesting search queries in object form This article describes which search queries in object form can be nested in each other. The table below shows all combinations of nesting search queries in object form with an indication of their possibility (+) or impossibility (–).
Nested query type Parent query type
Field PhraseSearch Not Or And
Word + + + + +
WordPattern + + + + +
NumericRange + + + + +
Regex + + + + +
Field + – + + +
DateRange + + + + +
PhraseSearch + + + + +
Not + – + + +
Or + – + + +
And + – + + +
Wildcard – + – – –
An attempt to create an impossible combination throws ArgumentException with the message "Query of type '...' can not be a child of '...'.". A wildcard query created with the [CreateWildcardQuery](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/createwildcardquery/) method can be used only as a child of a phrase search query; passing it to the [Search](https://reference.groupdocs.com/search/net/groupdocs.search/index/search/) method directly throws ArgumentException. Since version 26.11, a query can nest other queries up to 128 levels deep. The AND and OR queries nested in one another are not counted, so a chain of any number of AND and OR queries can be searched, whatever the order in which the chain is built. The search of a deeper query finds nothing: the result is empty, its [Warnings](https://reference.groupdocs.com/search/net/groupdocs.search.results/searchresult/warnings/) start with "Search failed: ", and the error is reported by the [ErrorOccurred](https://reference.groupdocs.com/search/net/groupdocs.search.events/eventhub/erroroccurred/) event of the index. Before, a deeply nested query could terminate the process with StackOverflowException. The [CreatePhraseSearchQuery](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/createphrasesearchquery/), [CreateAndQuery](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/createandquery/) and [CreateOrQuery](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/createorquery/) methods take an array of child queries (params), which must contain at least two queries. The [CreateAndQuery](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/createandquery/) and [CreateOrQuery](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/createorquery/) methods also have overloads with two child queries. A created query can be examined with the following members of the [SearchQuery](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/) class: * The [ChildCount](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/childcount/) property returns the number of child queries. * The [GetChild](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/getchild/) method returns a child query by its index; the [FirstChild](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/firstchild/) and [SecondChild](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/secondchild/) properties return the first and the second child queries. * The [FieldName](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/fieldname/) property returns the name of the field to search in, specified by a field query that contains this query, or null. * The [SearchOptions](https://reference.groupdocs.com/search/net/groupdocs.search/searchquery/searchoptions/) property gets or sets the search options of this query. * The ToString method returns the query in text form. The following example demonstrates the creation of a nested query and the traversal of the query tree. **C#** ```csharp string indexFolder = @"c:\MyIndex\"; string documentsFolder = @"c:\MyDocuments\"; // Creating an index in the specified folder Index index = new Index(indexFolder); // Indexing documents from the specified folder index.Add(documentsFolder); // Creating a query that searches for the phrase 'theory of * relativity' in the content field SearchQuery phraseQuery = SearchQuery.CreatePhraseSearchQuery( SearchQuery.CreateWordQuery("theory"), SearchQuery.CreateWordQuery("of"), SearchQuery.CreateWildcardQuery(0, 1), SearchQuery.CreateWordQuery("relativity")); SearchQuery fieldQuery = SearchQuery.CreateFieldQuery(CommonFieldNames.Content, phraseQuery); // Printing the query tree Console.WriteLine(fieldQuery.ToString()); for (int i = 0; i < phraseQuery.ChildCount; i++) { SearchQuery child = phraseQuery.GetChild(i); Console.WriteLine("\t" + child.ToString() + " (field: " + child.FieldName + ")"); } // Searching in the index SearchResult result = index.Search(fieldQuery); ``` ## More resources ### GitHub examples You may easily run the code from documentation articles and see the features in action in our GitHub examples: * [GroupDocs.Search for .NET examples](https://github.com/groupdocs-search/GroupDocs.Search-for-.NET) * [GroupDocs.Search for Java examples](https://github.com/groupdocs-search/GroupDocs.Search-for-Java) ### Free online document search App Along with full featured .NET library we provide simple, but powerful free Apps. You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online [Free Online Document Search App](https://products.groupdocs.app/search).