Skip to content

Commit 62cb72e

Browse files
committed
WIP - Elastic 9.0 Client Preview
elastic/elasticsearch-net#8496
1 parent 90bae5f commit 62cb72e

File tree

4 files changed

+26
-41
lines changed

4 files changed

+26
-41
lines changed

src/Foundatio.Parsers.ElasticQueries/Extensions/DefaultQueryNodeExtensions.cs

+9-26
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ public static Query GetDefaultQuery(this TermNode node, IQueryVisitorContext con
4444

4545
if (!node.IsQuotedTerm && node.UnescapedTerm.EndsWith("*"))
4646
{
47-
query = new QueryStringQuery
47+
query = new QueryStringQuery(node.UnescapedTerm)
4848
{
4949
Fields = fields,
5050
AllowLeadingWildcard = false,
51-
AnalyzeWildcard = true,
52-
Query = node.UnescapedTerm
51+
AnalyzeWildcard = true
5352
};
5453
}
5554
else
@@ -58,25 +57,18 @@ public static Query GetDefaultQuery(this TermNode node, IQueryVisitorContext con
5857
{
5958
if (node.IsQuotedTerm)
6059
{
61-
query = new MatchPhraseQuery(fields[0])
62-
{
63-
Query = node.UnescapedTerm
64-
};
60+
query = new MatchPhraseQuery(fields[0], node.UnescapedTerm);
6561
}
6662
else
6763
{
68-
query = new MatchQuery(fields[0])
69-
{
70-
Query = node.UnescapedTerm
71-
};
64+
query = new MatchQuery(fields[0], node.UnescapedTerm);
7265
}
7366
}
7467
else
7568
{
76-
query = new MultiMatchQuery
69+
query = new MultiMatchQuery(node.UnescapedTerm)
7770
{
7871
Fields = fields,
79-
Query = node.UnescapedTerm,
8072
Type = node.IsQuotedTerm ? TextQueryType.Phrase : null
8173
};
8274
}
@@ -86,17 +78,11 @@ public static Query GetDefaultQuery(this TermNode node, IQueryVisitorContext con
8678
{
8779
if (!node.IsQuotedTerm && node.UnescapedTerm.EndsWith("*"))
8880
{
89-
query = new PrefixQuery(field)
90-
{
91-
Value = node.UnescapedTerm.TrimEnd('*')
92-
};
81+
query = new PrefixQuery(field, node.UnescapedTerm.TrimEnd('*'));
9382
}
9483
else
9584
{
96-
query = new TermQuery(field)
97-
{
98-
Value = node.UnescapedTerm
99-
};
85+
query = new TermQuery(field, node.UnescapedTerm);
10086
}
10187
}
10288

@@ -155,7 +141,7 @@ public static async Task<Query> GetDefaultQueryAsync(this TermRangeNode node, IQ
155141

156142
public static Query GetDefaultQuery(this ExistsNode node, IQueryVisitorContext context)
157143
{
158-
return new ExistsQuery { Field = node.UnescapedField };
144+
return new ExistsQuery(node.UnescapedField);
159145
}
160146

161147
public static Query GetDefaultQuery(this MissingNode node, IQueryVisitorContext context)
@@ -164,10 +150,7 @@ public static Query GetDefaultQuery(this MissingNode node, IQueryVisitorContext
164150
{
165151
MustNot =
166152
[
167-
new ExistsQuery
168-
{
169-
Field = node.UnescapedField
170-
}
153+
new ExistsQuery(node.UnescapedField)
171154
]
172155
};
173156
}

src/Foundatio.Parsers.ElasticQueries/Visitors/GeoVisitor.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override async Task VisitAsync(TermNode node, IQueryVisitorContext contex
2424
return;
2525

2626
string location = _resolveGeoLocation != null ? await _resolveGeoLocation(node.Term).ConfigureAwait(false) ?? node.Term : node.Term;
27-
var query = new GeoDistanceQuery { Field = node.Field, Location = location, Distance = node.Proximity ?? "10mi" };
27+
var query = new GeoDistanceQuery(node.Proximity ?? "10mi", node.Field, location);
2828
node.SetQuery(query);
2929
}
3030

@@ -33,8 +33,9 @@ public override void Visit(TermRangeNode node, IQueryVisitorContext context)
3333
if (context is not IElasticQueryVisitorContext elasticContext || !elasticContext.MappingResolver.IsGeoPropertyType(node.Field))
3434
return;
3535

36-
var box = GeoBounds.TopLeftBottomRight(new TopLeftBottomRightGeoBounds { TopLeft = node.Min, BottomRight = node.Max });
37-
var query = new GeoBoundingBoxQuery { BoundingBox = box, Field = node.Field };
36+
// NOTE: Feedback here: https://github.com/elastic/elasticsearch-net/issues/8496
37+
var box = GeoBounds.TopLeftBottomRight(new TopLeftBottomRightGeoBounds(node.Max, node.Min));
38+
var query = new GeoBoundingBoxQuery(box, node.Field);
3839
node.SetQuery(query);
3940
}
4041
}

src/Foundatio.Parsers.ElasticQueries/Visitors/NestedVisitor.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public override Task VisitAsync(GroupNode node, IQueryVisitorContext context)
1919
if (nestedProperty == null)
2020
return base.VisitAsync(node, context);
2121

22-
node.SetQuery(new NestedQuery { Path = nestedProperty });
22+
// NOTE: This nested query will be updated in the CombineQueriesVisitor.
23+
node.SetQuery(new NestedQuery(nestedProperty, new Query()));
2324

2425
return base.VisitAsync(node, context);
2526
}

tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticQueryParserTests.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -847,10 +847,10 @@ public async Task NestedFilterProcessor()
847847
.Text(e => e.Field2, o => o.Index())
848848
.Text(e => e.Field3, o => o.Index())
849849
.IntegerNumber(e => e.Field4)
850-
.Nested<MyType>(r => r.Name(n => n.Nested.First()).Properties(p1 => p1
851-
.Text(e => e.Field1, o => o.Index())
852-
.Text(e => e.Field2, o => o.Index())
853-
.Text(e => e.Field3, o => o.Index())
850+
.Nested(e => e.Nested, o => o.Properties(p1 => p1
851+
.Text(e1 => e1.Field1, o1 => o1.Index())
852+
.Text(e1 => e1.Field2, o1 => o1.Index())
853+
.Text(e1 => e1.Field3, o1 => o1.Index())
854854
.IntegerNumber(e => e.Field4)
855855
))
856856
));
@@ -919,10 +919,10 @@ public async Task NestedFilterProcessor2()
919919
.Text(e => e.Field2, o => o.Index())
920920
.Text(e => e.Field3, o => o.Index())
921921
.IntegerNumber(e => e.Field4)
922-
.Nested<MyType>(r => r.Name(n => n.Nested.First()).Properties(p1 => p1
923-
.Text(e => e.Field1, o => o.Index())
924-
.Text(e => e.Field2, o => o.Index())
925-
.Text(e => e.Field3, o => o.Index())
922+
.Nested(e => e.Nested, o => o.Properties(p1 => p1
923+
.Text(e1 => e1.Field1, o1 => o1.Index())
924+
.Text(e1 => e1.Field2, o1 => o1.Index())
925+
.Text(e1 => e1.Field3, o1 => o1.Index())
926926
.IntegerNumber(e => e.Field4)
927927
))
928928
));
@@ -985,9 +985,9 @@ public async Task CanGenerateMatchQuery()
985985
public async Task CanBuildAliasQueryProcessor()
986986
{
987987
string index = await CreateRandomIndexAsync<MyType>(m => m.Properties(p => p
988-
.Object<Dictionary<string, object>>(f => f.Name(e => e.Data).Properties(p2 => p2
989-
.Text(e => e.Name("@browser_version"))
990-
.FieldAlias(a => a.Name("browser.version").Path("data.@browser_version"))))));
988+
.Object(f => f.Data, o => o.Properties(p2 => p2
989+
.Text("@browser_version")
990+
.FieldAlias("browser.version", o1 => o1.Path("data.@browser_version"))))));
991991

992992
var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log));
993993
var result = await processor.BuildQueryAsync("browser.version:1", new ElasticQueryVisitorContext().UseScoring());

0 commit comments

Comments
 (0)