# Cannot convert lambda expression to type 'PostData' because it is not a delegate type

**URL:** https://discuss.elastic.co/t/cannot-convert-lambda-expression-to-type-postdata-because-it-is-not-a-delegate-type/138724
**Category:** Elasticsearch
**Created:** [July 5, 2018, 1:28pm UTC](https://discuss.elastic.co/t/cannot-convert-lambda-expression-to-type-postdata-because-it-is-not-a-delegate-type/138724 "2018-07-05T13:28:14Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![StephM](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@StephM](https://discuss.elastic.co/u/StephM)
#### Post date: [July 5, 2018, 1:28pm UTC](https://discuss.elastic.co/t/cannot-convert-lambda-expression-to-type-postdata-because-it-is-not-a-delegate-type/138724/1 "2018-07-05T13:28:14Z")

</div>

I have this code in my .net core app

```
var searchResponse = client.Search<Person>(s => s
.From(0)
.Size(10)
.Query(q => q
     .Match(m => m
        .Field(f => f.FirstName)
        .Query("Martijn")
     )
)

```

);

which I got from this page [https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/nest-getting-started.html](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/nest-getting-started.html)

I'm getting an error at design time "Cannot convert lambda expression to type 'PostData' because it is not a delegate type". I have referenced Elasticsearch and System.Linq.

What am I missing?

---

<div class="post-metadata">

### Author: ![StephM](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@StephM](https://discuss.elastic.co/u/StephM)
#### Post date: [July 5, 2018, 2:55pm UTC](https://discuss.elastic.co/t/cannot-convert-lambda-expression-to-type-postdata-because-it-is-not-a-delegate-type/138724/2 "2018-07-05T14:55:23Z")

</div>

I've also tried this syntax from https://www.elastic.co/guide/en/elasticsearch/client/net-api/1.x/nest-quick-start.html

```
QueryContainer query = new TermQuery

```

{  
Field = "firstName",  
Value = "martijn"  
};

var searchRequest = new SearchRequest  
{  
From = 0,  
Size = 10,  
Query = query  
};

And now I get an error "cannot convert from 'Nest.SearchRequest' to 'Elasticsearch.Net.PostData"

I'm not sure why it is so hard to make a simple API call here.

---

<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: [July 5, 2018, 8:42pm UTC](https://discuss.elastic.co/t/cannot-convert-lambda-expression-to-type-postdata-because-it-is-not-a-delegate-type/138724/3 "2018-07-05T20:42:14Z")

</div>

First thing to check, are the NEST and [Elasticsearch.Net](http://Elasticsearch.Net) NuGet packages referenced both the same version number?

---

<div class="post-metadata">

### Author: ![StephM](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@StephM](https://discuss.elastic.co/u/StephM)
#### Post date: [July 6, 2018, 8:26am UTC](https://discuss.elastic.co/t/cannot-convert-lambda-expression-to-type-postdata-because-it-is-not-a-delegate-type/138724/4 "2018-07-06T08:26:00Z")

</div>

Yes, they are both Version 6.2.0.

I've managed to use the ElasticLowLevelClient successfully to Index, but if I use that to Count or Search since it seems to just do a post, I can't map the response object to actually use the data I'm trying to get.

---

<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: [July 6, 2018, 8:41am UTC](https://discuss.elastic.co/t/cannot-convert-lambda-expression-to-type-postdata-because-it-is-not-a-delegate-type/138724/5 "2018-07-06T08:41:53Z")

</div>

Ok. What is the type of `client` above? Would you be able to provide a short, but complete, example of the issue?

Also, would you be able to provide more details of the environment

- Windows, MacOS, Linux?
- framework TFM e.g. netcoreapp2.0

---

<div class="post-metadata">

### Author: ![StephM](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@StephM](https://discuss.elastic.co/u/StephM)
#### Post date: [July 11, 2018, 3:19pm UTC](https://discuss.elastic.co/t/cannot-convert-lambda-expression-to-type-postdata-because-it-is-not-a-delegate-type/138724/6 "2018-07-11T15:19:19Z")

</div>

Hi, so this is embarrassing. I was wanting to use the Low Level Client, but that was obviously not right. I then tried adding the Nest reference and changing to High Level Client but that didn't work either.  
Then I closed VS Code, reopened it and all of a sudden it works. Frustrating!

For info, in case anyone else has this -  
Running on Windows  
Elasticsearch v6.3.0 running locally (just for dev purposes)  
Developing in C# (dotnet core), using VSCode.

Code now looks like:

```
var node = new Uri(Config.Configuration["elasticsearch:0:uri"]);
var settings = new ConnectionSettings( node );
Client = new ElasticClient(settings);
QueryContainer query = new MatchQuery
{
	Field = keyValue.Key,
    Query = keyValue.Value.ToString()
};
var searchRequest = new SearchRequest(index.IndexName, index.IndexType)
	{
		Query = query
	};
var searchResults = Client.Search<object>(searchRequest);

```

Thanks again!

---

<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: [July 12, 2018, 1:18am UTC](https://discuss.elastic.co/t/cannot-convert-lambda-expression-to-type-postdata-because-it-is-not-a-delegate-type/138724/7 "2018-07-12T01:18:44Z")

</div>

Glad you figured it out @StephM 👍

---

<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: [August 9, 2018, 1:18am UTC](https://discuss.elastic.co/t/cannot-convert-lambda-expression-to-type-postdata-because-it-is-not-a-delegate-type/138724/8 "2018-08-09T01:18:51Z")

</div>

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