Nest Client not allowing default Boolean Queries

I am trying to use the Nest client to create a custom class that can be instantiated with a default request. I am using the following code to create a boolean query that will become part of a default SearchRequest object.


			var bq = new BoolQuery()
			{
				Filter = new QueryContainer[] { },
				Must = new QueryContainer[] { },
				MustNot = new QueryContainer[] { },
				Should = new QueryContainer[] { }
		};

The problem is if I return this as is I get a null object. If I add a default query such as a new MatchAll() query then the object comes back as expected.

Is there a workaround or flag to override this ? QueryContainer doesn't seem to have an IsStrict or Verbatim property to set.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

Hi @jimmymacGA

var client = new ElasticClient(settings);
	
var bq = new BoolQuery()
{
	IsVerbatim = true,
	Filter = new QueryContainer[] { },
	Must = new QueryContainer[] { },
	MustNot = new QueryContainer[] { },
	Should = new QueryContainer[] { }
};

var searchResponse = client.Search<Data>(s => s
	.Index("data")
	.Query(_ => bq)
);

will serialize to

POST /data/_search?pretty=true&typed_keys=true
{
  "query": {
    "bool": {}
  }
}

Is that what you'd like to do?