elasticsearch date_range query witn nest api

主宰稳场 提交于 2020-01-05 04:03:22

问题


I run a query in marvel plugin and it works fine(return 4 document) as you see below

And I want to make this query in C# with NEST, I expected same result with the plugin for this expression but it returns 0..

function call:

EsCodes myes = new EsCodes();
                myes.CreateConnection("localhost", "dota2");
                var result = myes.getDatasBetweenDates("01/01/2010 00:00:00", "01/01/2015 00:00:00");

connection:

private static ElasticClient es = new ElasticClient();
      public void CreateConnection(string hostname, string defaultIndex)
        {
            var node = new Uri(string.Format("http://{0}:9200", hostname));
            var settings = new ConnectionSettings(node).SetDefaultIndex(defaultIndex).UsePrettyResponses();
            es = new ElasticClient(settings);
        }

and function:

public List<IndexModel> getDatasBetweenDates(string startdate, string enddate)
        {
            ElasticClient myes = this.getConnection();
            List<IndexModel> indices = new List<IndexModel>();
            if (myes != null)
            {
                var result = myes.Search<dynamic>(q => q.Query(p => p.Range(v => v.OnField("dateofplay").GreaterOrEquals(startdate).LowerOrEquals(enddate))).Size(10)).Documents;
            }
                ...
                return indices;
            }

What is wrong with that ?

EDIT: I recognized the url created by NEST contaims "../dota2/object/_search.." I don't understand why it included that kind of parameter.. its the point of my issue. why it generates object in the url ?


回答1:


Note that you're not using the same dates in both queries.

In Marvel you use "22/06/2010 00:00:00" and "16/09/2015 00:00:00"

In your code you use "22/06/2012 00:00:00" and "16/09/2014 00:00:00"

So maybe that's the only reason why you don't get any results from your code.



来源:https://stackoverflow.com/questions/32466163/elasticsearch-date-range-query-witn-nest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!