# NEST fluent dsl queries - RequestBodyInBytes are always byte\[2\]

**URL:** <https://discuss.elastic.co/t/nest-fluent-dsl-queries-requestbodyinbytes-are-always-byte-2/90925>\
**Category:** Elasticsearch\
**Created:** [June 27, 2017, 8:00am UTC](https://discuss.elastic.co/t/nest-fluent-dsl-queries-requestbodyinbytes-are-always-byte-2/90925 "2017-06-27T08:00:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Zalen](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matt\_Zalen](https://discuss.elastic.co/u/Matt_Zalen)\
**Post date:** [June 27, 2017, 8:00am UTC](https://discuss.elastic.co/t/nest-fluent-dsl-queries-requestbodyinbytes-are-always-byte-2/90925/1 "2017-06-27T08:00:13Z")

</div>

Hi all,

I'm sending a very simple query with the following code, but when I try to debug and see what was actually posted in the body, it's always practically empty (byte[2], to be exact). Could somebody please tell me what I'm missing?

Here's the code :

> ```
> var node = new Uri("http://localhost:9200");
> var settings = new ConnectionSettings(node).DefaultIndex("loandetails");
> settings.EnableDebugMode();
> var client = new ElasticClient(settings);
> 
> ```

> ```
> var results = client.Search<LoanDetail>(s => s
> .Query(a => a
> .Bool(b => b
> .Must(c => c
> .Match(i => i
> .Field(l => l.Id)
> .Name("568e8515fbffa90f107f5083")
> )
> )
> )
> )
> ); 
> 
> ```

And here's how I'm seeing the request:

results.ApiCall.RequestBodyInBytes

...which, when converted, turns into this: {}

Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [June 27, 2017, 8:32am UTC](https://discuss.elastic.co/t/nest-fluent-dsl-queries-requestbodyinbytes-are-always-byte-2/90925/2 "2017-06-27T08:32:00Z")

</div>

The specified `match` query does not have a `query` property. As such, you're hitting a feature in NEST known as [**Conditionless queries**](https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/verbatim-and-strict-query-usage.html); for a `match` query, is is considered conditionless when:

1. the `field` is conditionless (`null` expression, `PropertyInfo`, string or empty string)
2. or the `query` is `null` or empty
3. or both 1. and 2.

> <https://github.com/elastic/elasticsearch-net/blob/5.x/src/Nest/QueryDsl/FullText/Match/MatchQuery.cs#L86>

When a query is considered _conditionless_ it does not form part of the serialized json for the query DSL. You can change this behaviour on a per query basis with [strict and verbatim queries](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/verbatim-and-strict-query-usage.html).

Conditionless queries are useful because it means you don't need to perform all sorts of `if`/`else` branching yourself to include queries in a composite query if values are `null` or empty.

In this particular case, you can fix the issue by providing the `query` part (which I think is what you meant to provide 😄):

```
   var node = new Uri("http://localhost:9200");
    var settings = new ConnectionSettings(node).DefaultIndex("loandetails");
    settings.EnableDebugMode();
    var client = new ElasticClient(settings);

    var results = client.Search<LoanDetail>(s => s
        .Query(a => a
            .Bool(b => b
                .Must(c => c
                        .Match(i => i
                            .Field(l => l.Id)
                            .Query("568e8515fbffa90f107f5083")
                        )
                )
            )
        )
    );
```

---

<div class="post-metadata">

**Author:** ![Matt\_Zalen](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matt\_Zalen](https://discuss.elastic.co/u/Matt_Zalen)\
**Post date:** [June 27, 2017, 8:53am UTC](https://discuss.elastic.co/t/nest-fluent-dsl-queries-requestbodyinbytes-are-always-byte-2/90925/3 "2017-06-27T08:53:31Z")

</div>

> [@Matt\_Zalen](#):
>
> Field(l =\> l.Id)  
> .Name

I understand. I thought that to translate the following using fluent DSL:

"must":  
[  
{  
"match": {  
"Id": "568e8515fbffa90f107f5083"  
}  
}  
]

I had to write:

.Must(c =\> c  
.Match(i =\> i  
.Field(l =\> l.Id)  
.Name("568e8515fbffa90f107f5083")  
)  
)

I didn't realize the Match function doesn't default to forming a "query."

Thanks for yet another amazingly quick reply.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [June 27, 2017, 9:49am UTC](https://discuss.elastic.co/t/nest-fluent-dsl-queries-requestbodyinbytes-are-always-byte-2/90925/4 "2017-06-27T09:49:14Z")

</div>

> [@Matt\_Zalen](#):
>
> I didn't realize the Match function doesn't default to forming a "query."

It does, but you've used `.Name()` which gives a query a name so that you can identify it in a response, useful when you have a complex compound query. To add a query part for a `match` query, you need to use `.Query()`.

```
"match": {
    "Id": "568e8515fbffa90f107f5083"
}

```

is a short form for the longer form

```
"match": {
    "Id": {
       "query": "568e8515fbffa90f107f5083"
    }
}

```

(_As an aside:_ NEST supports only the long form of the query when both serializing to JSON and deserializing from JSON).

---

<div class="post-metadata">

**Author:** ![Matt\_Zalen](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matt\_Zalen](https://discuss.elastic.co/u/Matt_Zalen)\
**Post date:** [June 27, 2017, 9:51am UTC](https://discuss.elastic.co/t/nest-fluent-dsl-queries-requestbodyinbytes-are-always-byte-2/90925/5 "2017-06-27T09:51:39Z")

</div>

Very good to know. Thanks again.

---

<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 25, 2017, 9:51am UTC](https://discuss.elastic.co/t/nest-fluent-dsl-queries-requestbodyinbytes-are-always-byte-2/90925/6 "2017-07-25T09:51:46Z")

</div>

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