问题
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