Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple match query to C# Nest

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.

like image 997
Dipesh Avatar asked Feb 22 '16 16:02

Dipesh


1 Answers

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")
        )));
like image 148
Rob Avatar answered Oct 24 '22 01:10

Rob