-
Notifications
You must be signed in to change notification settings - Fork 1.2k
DateMath -- Null string throws exception #1766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I had some time this morning to look at this, and I think the problem is there is no 'null' handling on some of the methods. For example in the
because otherwise the regex check on line 43 if you pass it a null seems to throw an excpetion. Also in the 'TermsQuery` I believe that line 68 should read:
I would have made a PR but I have two problems.
Can someone maybe check to see if they also get the exceptions? @russcam? |
Thanks for digging into this @RobinRieger - intending to look at this today 👍 |
[JsonConverter(typeof(DateMath.Json))]
public abstract class DateMath : IDateMath
{
// ... rest of class
public static implicit operator DateMath(DateTime dateTime) => DateMath.Anchored(dateTime);
public static implicit operator DateMath(string dateMath) => DateMath.FromString(dateMath);
} Now in the case of string tempField = null;
client.Search<dynamic>(s => s
.Query(q => q
.DateRange(ra => ra
.Field(fi => fi.ADate)
.LessThanOrEquals(!string.IsNullOrEmpty(tempField)
? DateTime.UtcNow.ToString()
: (string) null)
)
)
)
); an implicit conversion from In the case of string tempField = null;
client.Search<dynamic>(s => s
.Query(q => q
.DateRange(ra => ra
.Field(fi => fi.ADate)
.LessThanOrEquals(!string.IsNullOrEmpty(tempField)
? DateTime.UtcNow
: (DateTime?) null)
)
)
)
); there is no implicit conversion from a This is where Conditionless queries come into play.
Thanks for opening these issues and trying out NEST 2.x alpha - we'd like to send you some swag as a thank you; Would you be able to send me an email at russ.cam (the domain name is the same as the organisation domain website - damn the spam bots!) with your details? |
I am having some problems with the
DateRange
filter.The following does not work
but this does
I have a feeling that the DateMath does not like null values that are 'strings'.
Keeps saying
{"Value cannot be null.\r\nParameter name: input"}
From my understanding it should be able to handle this correct? I.e. if it is null then don't send the
DateRange
stuff to ES.Edit
I actually get an error with other searchs as well, e.g.
but if I pass a
new int[]{}
it works.....The text was updated successfully, but these errors were encountered: