0

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>
};

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Rob. It looks like maybe this does not work with Nest 1.7.1? I tried upgrading to Nest 2.0.0 alpha 2, but that caused an update to Newtonsoft 8.0.1 (which then broken other installed Azure packages) and DateHistogramAggregator no longer resolved.
I wasn't able to handle this with 1.7.1. Looks like DateHistogramAggregator has been renamed to DateHistogramAggregation. Regarding Json 8.0.1 ... yeah :/
0

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

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

Comments

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.