Reputation: 110
Is there any way to query Elasticsearch with NEST client using linq or lambda expressions.
I Want to do somthing like this :
client.Search<MyClass>(s => s.MyProperty.Contains("value") &&
(s.MySecondProperty == 123 ||
s.ThirdProperty > 12)) ;
Or
var query = from m in MyContext.MyClass
where ...
select m
I read a little about ElasticLinq but it seems that it is no more active. the last nuget package were published on october 2015
What i want to do is to create a method that get an Expression as parameter from the caller and search on elastic with it. the caller should not depend on ES or NEST API
Upvotes: 9
Views: 7206
Reputation: 1
I am currently working on the LINQ query provider library to generate NEST method calls. If someone is interested - here is the link to the GitHub repository - https://github.com/VladislavRybnikov/NEST.Linq
Upvotes: 0
Reputation: 6665
The exact query you write there today works just great in ElasticLINQ.
The project is still alive - just sometimes there is no reason for a new release. There was a point release today to fix a corner case in generating Queries (not filters) using OR's nested within an AND.
Upvotes: 4
Reputation: 125528
In short, no.
The longer answer is, ElasticLINQ is the closest to a LINQ provider that I'm aware of but does not expose all of the capabilities of the Elasticsearch API.
Whilst there is some overlap between LINQ
, IQueryable<T>
et. al, and the search capabilities exposed by the Elasticsearch query DSL and REST API, there are many queries that cannot be easily expressed with LINQ e.g. what would a completion suggester query look like, or a function score query or a moving average aggregation using Holt-Winters?
You would need to extend the methods available in LINQ and write a non-trivial query provider, all for the desire to fit a well defined query DSL into the LINQ paradigm.
Personally, I would be inclined to embrace the query DSL and REST API and look to transform your Expression into something that you can send with NEST, Elasticsearch.Net or HttpClient
. The caller still doesn't need to know how the request is made.
If you do end up writing a LINQ query provider, I'd be very interested :)
Upvotes: 4