# Search Api usage and BoolQueryDescriptor - Nest Client

**URL:** <https://discuss.elastic.co/t/search-api-usage-and-boolquerydescriptor-nest-client/48162>\
**Category:** Elasticsearch\
**Created:** [April 22, 2016, 10:48am UTC](https://discuss.elastic.co/t/search-api-usage-and-boolquerydescriptor-nest-client/48162 "2016-04-22T10:48:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavang6](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pavang6](https://discuss.elastic.co/u/pavang6)\
**Post date:** [April 22, 2016, 10:48am UTC](https://discuss.elastic.co/t/search-api-usage-and-boolquerydescriptor-nest-client/48162/1 "2016-04-22T10:48:53Z")

</div>

Hi ,  
Nest Version : 2.10  
[Elasticsearch.Net](http://Elasticsearch.Net) Version : 2.10

I am trying to write a query which goes like below

```auto
BoolQueryDescriptor<ErrorLog> queryParameter;
queryParameter = QueryFilterBuilder.BuildQueryFilter<ErrorLog>(searchInputs.SearchParameters);   

if (queryParameter != null)
{
  var searchResultnew = elasticClient.Search<ErrorLog>(query => query
    .Query(q=>q.Bool(queryParameter))
      .Index("errorlogs")
      .Size(searchInputs.ResultCount)
      .From(searchInputs.From)
      .Sort(s => s.OnField(sortField)
      .Order(sortOrder)
    )
  );
}

```

Here the `query.Query(q=>q.Bool(queryParameter))` is not taking queryParameter as parameter even though queryParameter is of type `BoolQueryDescriptor` . Not sure what is wrong here.

Have copied the Generic class query builder class below ie, `QueryFilterBuilder` Please let me know if you need more details.  
This class was written using Nest 1.x now we are trying to fix the broken thing with Nest 2.0.

```auto
    public static class QueryFilterBuilder
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        public static BoolQueryDescriptor<T> BuildQueryFilter<T>(IList<SearchParameters> searchParameterList) where T : class
        {
            QueryContainer filterContainer = null;
            BoolQueryDescriptor<T> bqd = new BoolQueryDescriptor<T>();
            if (searchParameterList == null)
            {
                throw (new ArgumentNullException("searchParameterList"));
            }

            var fieldGroups = from parameter in searchParameterList
                              group parameter by parameter.FieldName into fieldList
                              orderby fieldList.Key
                              select fieldList;
            foreach (var fgrp in fieldGroups)
            {
                string fieldName = string.Empty;
                string fieldDataType = string.Empty;
                string searchText = string.Empty;
                SearchFilterType operand = SearchFilterType.Unknown;
                foreach (var sp in fgrp.ToList())
                {
                    switch (sp.Operand)
                    {
                        case SearchFilterType.Equals:
                            bqd.Must(EqualTo(searchText, sp.FieldName, sp.Analysed));
                            operand = sp.Operand;
                            break;

                        case SearchFilterType.Contains:
                            bqd.Must(Contains(searchText, sp.FieldName, sp.Analysed, fieldDataType));
                            operand = sp.Operand;
                            break;
                    }
                }
            }

            return bqd;
        }

        public static QueryContainer EqualTo(string searchText, string field, bool fieldanalysis)
        {
            QueryContainer queryContainer = null;
            if (searchText == null)
            {
                throw (new ArgumentNullException("searchText"));
            }

            if (fieldanalysis)
            {
                searchText = searchText.ToLower();
                queryContainer = new TermQuery()
                {
                    Field = field + ".sort",
                    Value = searchText
                };
            }
            else
            {
                queryContainer &= new TermQuery()
                {
                    Field = field,
                    Value = searchText
                };
            }
            return queryContainer;
        }

     
    }

---------------------
 public class SearchParameters
    {
        /// <summary>
        /// Gets or sets SearchText
        /// </summary>
        public String SearchText { get; set; }

        /// <summary>
        /// Gets or sets FieldName
        /// </summary>
        public String FieldName { get; set; }

        /// <summary>
        /// Gets or sets Operand
        /// </summary>
        public SearchFilterType Operand { get; set; }

        /// <summary>
        /// Gets or sets FieldName
        /// </summary>
        public String FieldDataType { get; set; }

        /// <summary>
        /// Gets or sets Analyzed status
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Analysed")]
        public bool Analysed { get; set; }
    }

```

Thanks,  
Pavan

---

<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 5, 2017, 10:56pm UTC](https://discuss.elastic.co/t/search-api-usage-and-boolquerydescriptor-nest-client/48162/2 "2017-07-05T22:56:34Z")

</div>


