Solr Date Format issue in the Query

2019-06-09 03:59发布

I am trying to implement the solr query using .NET but i am getting bad request when i try to connect to the solr for search since my date format is wrong.Can any one tell me the exact syntax to create a date format in .net

Created_Dt :[12/12/2008 3:45 PM TO *]

标签: solr solrnet
3条回答
祖国的老花朵
2楼-- · 2019-06-09 04:09

SolrNet already does the conversion to Solr time format for you, you only need to work with the standard DateTime type:

new SolrQueryByRange<DateTime?>("Created_Dt", new DateTime(2008, 12, 12, 15, 45, 0), null);
查看更多
【Aperson】
3楼-- · 2019-06-09 04:09

I could get the solr date format using the code below,

DateTimeFieldSerializer date = new DateTimeFieldSerializer();

string fromDt = date.SerializeDate(searchCriteria.From);

string toDt = date.SerializeDate(searchCriteria.To);

This works fine and I can search using the date range now..

查看更多
趁早两清
4楼-- · 2019-06-09 04:25

You need to search based on a UTC timestmap. Here is some example .NET code to generate it:

DateTime dt = DateTime.Now.ToUniversalTime();
System.Diagnostics.Debug.WriteLine(dt.ToString("yyyy-MM-ddTHH:mm:ssZ"));

And a query using your example field that would use that format:

Created_Dt:[2011-06-07T13:35:47Z TO NOW]

Also, make sure you convert your dates to UTC format before you store them.

查看更多
登录 后发表回答