elasticsearch date_range查询nest api [英] elasticsearch date_range query witn nest api
问题描述
我想用NEST在C#中进行这个查询,我期望与此表达式的插件相同,但返回0 ..
函数调用:
EsCodes myes = new EsCodes();
myes.CreateConnection(localhost,dota2);
var result = myes.getDatasBetweenDates(01/01/2010 00:00:00,01/01/2015 00:00:00);
连接:
code> 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);
}
和功能:
public List< IndexModel> getDatasBetweenDates(string startdate,string enddate)
{
ElasticClient myes = this.getConnection();
列表< IndexModel> indices = new List< IndexModel>();
if(myes!= null)
{
var result = myes.Search< dynamic>(q => q.Query(p => p.Range(v = 。v.OnField( dateofplay)GreaterOrEquals(开始日期).LowerOrEquals(结束日期)))尺寸(10))的文档。
}
...
返回索引;
}
有什么问题?
编辑:我认识到由NEST创建的URL../dota2/object/_search ..
我不明白为什么它包含那种参数..我的问题点。为什么它会在url中生成对象?
请注意,您在两个查询中都没有使用相同的日期。
在Marvel中,您使用22/06/2010 00:00:00
和16/09/2015 00:00: 00
在您的代码中,您使用22/06/2012 00:00:00
和16/09/2014 00:00:00
所以也许这是唯一的你的代码没有得到任何结果的原因。
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 ?
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.
这篇关于elasticsearch date_range查询nest api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!