-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Long range query support #3299
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
Merged
Merged
Long range query support #3299
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6dca245
added LongRangeQuery
annashlyak 51d7589
moved LongRangeQuery in LongRangeQuery.cs and added tests
annashlyak 2166072
added VisitQuery
annashlyak 1020933
test fix
annashlyak a3e493b
RangeQueryJsonConverter fix: added support for long deserealization
annashlyak 6686482
returned method TermsSet
annashlyak 24b1793
review fixes
annashlyak 78d918b
simplified GetRangeQuery
annashlyak 958118c
fq initialization fix
annashlyak b4fbbb3
fix
annashlyak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Nest | ||
{ | ||
public interface ILongRangeQuery : IRangeQuery | ||
{ | ||
[JsonProperty("gte")] | ||
long? GreaterThanOrEqualTo { get; set; } | ||
|
||
[JsonProperty("lte")] | ||
long? LessThanOrEqualTo { get; set; } | ||
|
||
[JsonProperty("gt")] | ||
long? GreaterThan { get; set; } | ||
|
||
[JsonProperty("lt")] | ||
long? LessThan { get; set; } | ||
|
||
[JsonProperty("relation")] | ||
RangeRelation? Relation { get; set; } | ||
} | ||
|
||
public class LongRangeQuery : FieldNameQueryBase, ILongRangeQuery | ||
{ | ||
protected override bool Conditionless => IsConditionless(this); | ||
public long? GreaterThanOrEqualTo { get; set; } | ||
public long? LessThanOrEqualTo { get; set; } | ||
public long? GreaterThan { get; set; } | ||
public long? LessThan { get; set; } | ||
|
||
public RangeRelation? Relation { get; set; } | ||
|
||
internal override void InternalWrapInContainer(IQueryContainer c) => c.Range = this; | ||
|
||
internal static bool IsConditionless(ILongRangeQuery q) | ||
{ | ||
return q.Field.IsConditionless() | ||
|| (q.GreaterThanOrEqualTo == null | ||
&& q.LessThanOrEqualTo == null | ||
&& q.GreaterThan == null | ||
&& q.LessThan == null); | ||
} | ||
} | ||
|
||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | ||
public class LongRangeQueryDescriptor<T> | ||
: FieldNameQueryDescriptorBase<LongRangeQueryDescriptor<T>, ILongRangeQuery, T> | ||
, ILongRangeQuery where T : class | ||
{ | ||
protected override bool Conditionless => LongRangeQuery.IsConditionless(this); | ||
long? ILongRangeQuery.GreaterThanOrEqualTo { get; set; } | ||
long? ILongRangeQuery.LessThanOrEqualTo { get; set; } | ||
long? ILongRangeQuery.GreaterThan { get; set; } | ||
long? ILongRangeQuery.LessThan { get; set; } | ||
RangeRelation? ILongRangeQuery.Relation { get; set; } | ||
|
||
public LongRangeQueryDescriptor<T> Relation(RangeRelation? relation) => Assign(a => a.Relation = relation); | ||
|
||
public LongRangeQueryDescriptor<T> GreaterThan(long? from) => Assign(a => a.GreaterThan = from); | ||
|
||
public LongRangeQueryDescriptor<T> GreaterThanOrEquals(long? from) => Assign(a => a.GreaterThanOrEqualTo = from); | ||
|
||
public LongRangeQueryDescriptor<T> LessThan(long? to) => Assign(a => a.LessThan = to); | ||
|
||
public LongRangeQueryDescriptor<T> LessThanOrEquals(long? to) => Assign(a => a.LessThanOrEqualTo = to); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/Tests/QueryDsl/TermLevel/Range/LongRangeQueryUsageTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Nest; | ||
using Tests.Framework.Integration; | ||
using Tests.Framework.ManagedElasticsearch.Clusters; | ||
using Tests.Framework.MockData; | ||
|
||
namespace Tests.QueryDsl.TermLevel.Range | ||
{ | ||
public class LongRangeQueryUsageTests : QueryDslUsageTestsBase | ||
{ | ||
public LongRangeQueryUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) {} | ||
|
||
protected override object QueryJson => new | ||
{ | ||
range = new | ||
{ | ||
description = new | ||
{ | ||
_name = "named_query", | ||
boost = 1.1, | ||
gt = 636634079999999999, | ||
gte = 636634080000000000, | ||
lt = 636634080000000000, | ||
lte = 636634079999999999, | ||
relation = "within" | ||
} | ||
} | ||
}; | ||
|
||
protected override QueryContainer QueryInitializer => new LongRangeQuery | ||
{ | ||
Name = "named_query", | ||
Boost = 1.1, | ||
Field = "description", | ||
GreaterThan = 636634079999999999, | ||
GreaterThanOrEqualTo = 636634080000000000, | ||
LessThan = 636634080000000000, | ||
LessThanOrEqualTo = 636634079999999999, | ||
Relation = RangeRelation.Within | ||
}; | ||
|
||
protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project> q) => q | ||
.LongRange(c => c | ||
.Name("named_query") | ||
.Boost(1.1) | ||
.Field(p => p.Description) | ||
.GreaterThan(636634079999999999) | ||
.GreaterThanOrEquals(636634080000000000) | ||
.LessThan(636634080000000000) | ||
.LessThanOrEquals(636634079999999999) | ||
.Relation(RangeRelation.Within) | ||
); | ||
|
||
protected override ConditionlessWhen ConditionlessWhen => new ConditionlessWhen<ILongRangeQuery>(q => q.Range as ILongRangeQuery) | ||
{ | ||
q=> q.Field = null, | ||
q=> | ||
{ | ||
q.GreaterThan = null; | ||
q.GreaterThanOrEqualTo = null; | ||
q.LessThan = null; | ||
q.LessThanOrEqualTo = null; | ||
} | ||
}; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be simplified further.
For
isNumeric
and DateRangeQuery cases,CheckType
will end up being called twice. It looks like it should be possible to enumerate/iterate overjo.Properties()
once and determine from the existence of "format", "time_zone" or token type, whichIRangeQuery
it is. I was thinking something likewhat do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thank you. LGTM. "format" and "time_zone" checks must be done for all properties in jo. When we check for a type, we can not immediately return the result, because LongRange is used, if there was no property of type float, but there was a property of type int. However, we can iterate once and I think that the code will looks better.