# NEST/C#: Binary operation on \*QueryDescriptor\<T\>

**URL:** https://discuss.elastic.co/t/nest-c-binary-operation-on-querydescriptor-t/160206
**Category:** Elasticsearch
**Created:** [December 10, 2018, 3:22pm UTC](https://discuss.elastic.co/t/nest-c-binary-operation-on-querydescriptor-t/160206 "2018-12-10T15:22:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![redX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redx/32/21864_2.png) [@redX](https://discuss.elastic.co/u/redX)
#### Post date: [December 10, 2018, 3:22pm UTC](https://discuss.elastic.co/t/nest-c-binary-operation-on-querydescriptor-t/160206/1 "2018-12-10T15:22:20Z")

</div>

I am creating dynamic ES query with NEST like this:

```
var q1 = new MatchQuery() { Field = "similarto.keyword", Query = "55445" };
var q2 = new MatchQuery() { Field = "metatag.keyword", Query = "hot" };
var q3 = q1 || q2;

var response = client.Search<Recommendation>(s => s
	.AllTypes().From(0).Size(10)
	.Query(q => q3));

```

This works fine.  
But doing the same with the `MatchQueryDescriptor<T>` it isn't working:

```
var q1x = new MatchQueryDescriptor<Recommendation>();
q1x.Field(f => f.Similarto.Suffix("keyword"));
q1x.Query("55445");

var q2x = new MatchQueryDescriptor<Recommendation>();
q2x.Field(f => f.Metatag.Suffix("keyword"));
q2x.Query("hot");

var q3x = q1x || q2x;

```

On the last line, the compiler complains about: `Operator '||' cannot be applied to operands of type 'MatchQueryDescriptor<Recommendation>' and 'MatchQueryDescriptor<Recommendation>'`

I can live with the first version. But the second is nicer because of the strongly typed arguments.  
Is it somehow possible to use the binary operators `||`, `&&`, etc. on `*QueryDescriptor<T>`?  
Or is it somehow possible to use binary operators with strongly typed arguments?

---

<div class="post-metadata">

### Author: ![redX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redx/32/21864_2.png) [@redX](https://discuss.elastic.co/u/redX)
#### Post date: [December 11, 2018, 9:23am UTC](https://discuss.elastic.co/t/nest-c-binary-operation-on-querydescriptor-t/160206/2 "2018-12-11T09:23:18Z")

</div>

Got it working:

```
var qx = new QueryContainerDescriptor<Recommendation>();
var q1 = qx.Match(q => q
	.Field(f => f.Similarto.Suffix("keyword"))
	.Query("55445"));
var q2 = qx.Match(q => q
	.Field(f => f.Metatag.Suffix("keyword"))
	.Query("hot"));
var q3 = q1 || q2;

var response2 = client.Search<Recommendation>(s => s
	.AllTypes().From(0).Size(10)
	.Query(q => q3y));

```

Produces:

```
{
	"from": 0,"size": 10,
	"query": {"bool": { "should": [
		{ "match": { "similarto.keyword": { "query": "55445" }}}, 
		{ "match": { "metatag.keyword": { "query": "hot" }}}
	]}}
}
```

---

<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: [January 8, 2019, 9:23am UTC](https://discuss.elastic.co/t/nest-c-binary-operation-on-querydescriptor-t/160206/3 "2019-01-08T09:23:19Z")

</div>

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