5

I new to Elasticsearch I have cURL

GET /index/type/_search
{
    "query": {
        "match": {
            "TextID": "WT"
        }
    }
}

I want to convert it to lambda expression in C# . I managed to build some code but it is throwing runtime exception.

var searchQID = client.Search<string>(sd => sd
                     .Index("index")
                     .Type("type")
                     .Size(10000)
                     .Query(q => q
                        .Match(m => m.OnField("TextID").Query("WT")
                        )));

Please help.

0

1 Answer 1

18

Create a class to represent your document stored in elasticsearch, and use it as generic argument in the Search method.

public class Document
{
    public string TextID { get; set; }
}

var searchResponse = client.Search<Document>(sd => sd
    .Index("index")
    .Type("type")
    .Size(10000)
    .Query(q => q
        .Match(m => m.Field("TextID").Query("WT")
        )));
Sign up to request clarification or add additional context in comments.

2 Comments

Hey thanks bro it working but is there any other way without creating a class? Waiting for your reply bro
You can experiment with .Search<dynamic>(..), hope it helps bro.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.