BrianMu
BrianMu

Reputation: 1

How do I do a raw query using Nest with object initializer syntax?

I am trying to do a search in ElasticSearch using Nest. I want to use the object initializer syntax because I need to build the parts of the search dynamically. I have figured out how to build much of the request, but am not clear how I would initialize a Raw Query. The OIS doesn't seem to have QueryRaw as a parameter to the request.

Code that I have now:

var searchResults = client.Search<dynamic>(s => s
    .Index("myIndex"),
    .Type("myType),
    .Aggregations(a => a
        .DateHistogram("my_date_histogram", h => h
            .Field("DateField")
            .Interval("day")
         )
     )
     .QueryRaw(queryText)
)

Code that I am trying to create:

var request = new SearchRequest<dynamic>
{
    Index = "MyIndex",
    Type = "MyType",
    QueryRaw = <doesn't exist>
};

Upvotes: 0

Views: 3164

Answers (2)

JakeJ
JakeJ

Reputation: 2511

Here's how to do raw queries using the new object structure:

var response = client.Search<dynamic>(s => s
    .Query(qry => qry
        .Raw(yourRawQueryStringHere)
    )
);

Upvotes: 0

Rob
Rob

Reputation: 9979

You can do this by

var searchResponse = client.Search<dynamic>(new SearchRequest
{
    Query = new RawQuery(yourquery)
});

Tested with NEST 2.0.0.alpha2 and ES 2.1.0

Upvotes: 3

Related Questions