Search code examples
elasticsearchnest

Option for ElasticSearch Nest if you are still on .net Framework 4


I would like to use ElasticSearch Nest but my application is using .net Framework 4. What other options do I have? I have tried PlainElastic.net but it has not been updated lately. If there is no other option, what I am thinking to try is generate the query.

Kind Regards


Solution

  • Made a simple class to build the query. It works for my scenario, hope it can help someone else:

    public class SearchQuery
    {
        public int size { get; set; }
        public int from { get; set; }
        public Query query { get; set; }
    
        public SearchQuery()
        {
            size = 50;
            from = 0;
            query = new Query();
        }
    
    
    }
    
    public class Query
    {
        public boolquery @bool { get; set; }
    
        public Query()
        {
            @bool = new boolquery();
        }
    
    
    }
    
    public class boolquery
    {
        public JArray must { get; set; }
        public JArray should { get; set; }
        public boolquery()
        {
            must = new JArray();
            should = new JArray();
        }
    }
    
    public static class QueryCommands
    {
        public static dynamic AddMatch(string field, dynamic value)
        {
            dynamic m = new JObject();
            m.match = new JObject(new JProperty(field, value));
            return m;
        }
    
        public static dynamic AddTerm(string field, dynamic value)
        {
            dynamic m = new JObject();
            m.term = new JObject(new JProperty(field, value));
            return m;
        }
        public static dynamic AddMatchPhrase(string field, dynamic value)
        {
            dynamic m = new JObject();
            m.match_phrase = new JObject(new JProperty(field, value));
            return m;
        }
    }