Skip to content

Commit 43bf3fe

Browse files
committed
Fix Query DSL usage tests (#3804)
This commit removes the lenient assertion within QueryDslUsagesTestsBase that allowed parsing exceptions in Elasticsearch to pass. This was a temporary solution whilst upgrading the client to work with Elasticsearch 7.x. Add an IGeoShape property to Project called LocationShape, and always seeds it with a PointGeoShape. Rename Location to LocationPoint Update the GeoShapeFormatter to skip over the value of a field within JSON when it is not the type field. String allocations for property names are reduced by comparing fields to static byte fields. Fix the serialized ordering of lat lon values in the geo_shape query using an envelope, since server side validation only allows valid envelopes. Skip multi_point and circle geo_shape queries for now as both result in 400 error responses. Do not set id when MoreLikeThis query input is a document GeoPolygon query requires a minimum of 3 coordinates
1 parent 01202a0 commit 43bf3fe

File tree

29 files changed

+236
-277
lines changed

29 files changed

+236
-277
lines changed

src/CodeGeneration/DocGenerator/StringExtensions.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static class StringExtensions
6262
{ "Script.Map", "\"if (doc['state'].value == \\\"Stable\\\") { params._agg.commits.add(doc['numberOfCommits'].value) }\"" },
6363
{ "Script.Combine", "\"def sum = 0.0; for (c in params._agg.commits) { sum += c } return sum\"" },
6464
{ "Script.Reduce", "\"def sum = 0.0; for (a in params._aggs) { sum += a } return sum\"" },
65-
{ "EnvelopeCoordinates", @"new [] { new [] { 45.0, -45.0 }, new [] { -45.0, 45.0 }}" },
65+
{ "EnvelopeCoordinates", @"new [] { new [] { -45.0, 45.0 }, new [] { 45.0, -45.0 }}" },
6666
{ "CircleCoordinates", @"new [] { 45.0, -45.0 }" },
6767
{ "MultiPointCoordinates", @"new [] { new [] {38.897676, -77.03653}, new [] {38.889939, -77.009051} }" },
6868
{
@@ -117,12 +117,6 @@ public static class StringExtensions
117117
},
118118
{ "LineStringCoordinates", @"new [] { new [] {38.897676, -77.03653}, new [] {38.889939, -77.009051} }" },
119119
{ "PointCoordinates", "new[] { 38.897676, -77.03653 }" },
120-
{
121-
"_polygonCoordinates", @"new[]{
122-
new []{ new [] {10.0, -17.0}, new [] {15.0, 16.0}, new [] {0.0, 12.0}, new [] {-15.0, 16.0}, new [] {-10.0, -17.0},new [] {10.0, -17.0}},
123-
new []{ new [] {8.2, 18.2}, new [] {8.2, -18.8}, new [] {-8.8, -10.8}, new [] {8.8, 18.2}}
124-
}"
125-
},
126120
{ "ProjectFilterExpectedJson", "new {term = new {type = new {value = \"project\"}}}" }
127121
};
128122

src/Nest/Mapping/Visitor/PropertyWalker.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ private static IProperty InferProperty(PropertyInfo propertyInfo)
162162
if (type == typeof(QueryContainer))
163163
return new PercolatorProperty();
164164

165+
if (type == typeof(IGeoShape))
166+
return new GeoShapeProperty();
167+
165168
return new ObjectProperty();
166169
}
167170

src/Tests/Tests.Core/ManagedElasticsearch/NodeSeeders/DefaultSeeder.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ public static PropertiesDescriptor<TProject> ProjectProperties<TProject>(Propert
328328
.Properties(DeveloperProperties)
329329
)
330330
.GeoPoint(g => g
331-
.Name(p => p.Location)
331+
.Name(p => p.LocationPoint)
332+
)
333+
.GeoShape(g => g
334+
.Name(p => p.LocationShape)
332335
)
333336
.Completion(cm => cm
334337
.Name(p => p.Suggest)

src/Tests/Tests.Domain/Project.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public class Project
2323
public JoinField Join => JoinField.Root<Project>();
2424
public DateTime LastActivity { get; set; }
2525
public Developer LeadDeveloper { get; set; }
26-
public SimpleGeoPoint Location { get; set; }
26+
public SimpleGeoPoint LocationPoint { get; set; }
27+
public IGeoShape LocationShape { get; set; }
2728
public Dictionary<string, Metadata> Metadata { get; set; }
2829
public string Name { get; set; }
2930
public int? NumberOfCommits { get; set; }
@@ -57,7 +58,8 @@ [StringEnum] [JsonConverter(typeof(StringEnumConverter))]
5758
.RuleFor(p => p.LeadDeveloper, p => Developer.Developers[Gimme.Random.Number(0, Developer.Developers.Count - 1)])
5859
.RuleFor(p => p.Tags, f => Tag.Generator.Generate(Gimme.Random.Number(2, 50)))
5960
.RuleFor(p => p.CuratedTags, f => Tag.Generator.Generate(Gimme.Random.Number(1, 5)))
60-
.RuleFor(p => p.Location, f => SimpleGeoPoint.Generator.Generate())
61+
.RuleFor(p => p.LocationPoint, f => SimpleGeoPoint.Generator.Generate())
62+
.RuleFor(p => p.LocationShape, f => new PointGeoShape(new GeoCoordinate(f.Address.Latitude(), f.Address.Latitude())))
6163
.RuleFor(p => p.NumberOfCommits, f => Gimme.Random.Number(1, 1000))
6264
.RuleFor(p => p.NumberOfContributors, f => Gimme.Random.Number(1, 200))
6365
.RuleFor(p => p.Ranges, f => Ranges.Generator.Generate())
@@ -84,7 +86,7 @@ [StringEnum] [JsonConverter(typeof(StringEnumConverter))]
8486
LeadDeveloper = new Developer() { FirstName = "Martijn", LastName = "Laarman" },
8587
StartedOn = new DateTime(2015, 1, 1),
8688
DateString = new DateTime(2015, 1, 1).ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz"),
87-
Location = new SimpleGeoPoint { Lat = 42.1523, Lon = -80.321 },
89+
LocationPoint = new SimpleGeoPoint { Lat = 42.1523, Lon = -80.321 },
8890
SourceOnly = TestConfiguration.Instance.Random.SourceSerializer ? new SourceOnlyObject() : null
8991
};
9092

@@ -102,7 +104,7 @@ [StringEnum] [JsonConverter(typeof(StringEnumConverter))]
102104
numberOfContributors = 0,
103105
dateString = new DateTime(2015, 1, 1).ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz"),
104106
leadDeveloper = new { gender = "Male", id = 0, firstName = "Martijn", lastName = "Laarman" },
105-
location = new { lat = Instance.Location.Lat, lon = Instance.Location.Lon }
107+
locationPoint = new { lat = Instance.LocationPoint.Lat, lon = Instance.LocationPoint.Lon }
106108
};
107109

108110
private static readonly object InstanceAnonymousSourceSerializer = new
@@ -117,7 +119,7 @@ [StringEnum] [JsonConverter(typeof(StringEnumConverter))]
117119
numberOfContributors = 0,
118120
dateString = new DateTime(2015, 1, 1).ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz"),
119121
leadDeveloper = new { gender = "Male", id = 0, firstName = "Martijn", lastName = "Laarman" },
120-
location = new { lat = Instance.Location.Lat, lon = Instance.Location.Lon },
122+
locationPoint = new { lat = Instance.LocationPoint.Lat, lon = Instance.LocationPoint.Lon },
121123
sourceOnly = new { notWrittenByDefaultSerializer = "written" }
122124
};
123125

src/Tests/Tests/Aggregations/Bucket/GeoDistance/GeoDistanceAggregationUsageTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public GeoDistanceAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage)
2121
{
2222
geo_distance = new
2323
{
24-
field = "location",
24+
field = "locationPoint",
2525
origin = new
2626
{
2727
lat = 52.376,
@@ -39,7 +39,7 @@ public GeoDistanceAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage)
3939

4040
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
4141
.GeoDistance("rings_around_amsterdam", g => g
42-
.Field(p => p.Location)
42+
.Field(p => p.LocationPoint)
4343
.Origin(52.376, 4.894)
4444
.Ranges(
4545
r => r.To(100),
@@ -51,7 +51,7 @@ public GeoDistanceAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage)
5151
protected override AggregationDictionary InitializerAggs =>
5252
new GeoDistanceAggregation("rings_around_amsterdam")
5353
{
54-
Field = Field((Project p) => p.Location),
54+
Field = Field((Project p) => p.LocationPoint),
5555
Origin = "52.376, 4.894",
5656
Ranges = new List<AggregationRange>
5757
{

src/Tests/Tests/Aggregations/Bucket/GeoHashGrid/GeoHashGridAggregationUsageTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public GeoHashGridAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage)
1919
{
2020
geohash_grid = new
2121
{
22-
field = "location",
22+
field = "locationPoint",
2323
precision = 3,
2424
size = 1000,
2525
shard_size = 100
@@ -29,7 +29,7 @@ public GeoHashGridAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage)
2929

3030
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
3131
.GeoHash("my_geohash_grid", g => g
32-
.Field(p => p.Location)
32+
.Field(p => p.LocationPoint)
3333
.GeoHashPrecision(GeoHashPrecision.Precision3)
3434
.Size(1000)
3535
.ShardSize(100)
@@ -38,7 +38,7 @@ public GeoHashGridAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage)
3838
protected override AggregationDictionary InitializerAggs =>
3939
new GeoHashGridAggregation("my_geohash_grid")
4040
{
41-
Field = Field<Project>(p => p.Location),
41+
Field = Field<Project>(p => p.LocationPoint),
4242
Precision = GeoHashPrecision.Precision3,
4343
Size = 1000,
4444
ShardSize = 100

src/Tests/Tests/Aggregations/Metric/GeoBounds/GeoBoundsAggregationUsageTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ public GeoBoundsAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) :
1919
{
2020
geo_bounds = new
2121
{
22-
field = "location",
22+
field = "locationPoint",
2323
wrap_longitude = true
2424
}
2525
}
2626
};
2727

2828
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
2929
.GeoBounds("viewport", gb => gb
30-
.Field(p => p.Location)
30+
.Field(p => p.LocationPoint)
3131
.WrapLongitude(true)
3232
);
3333

3434
protected override AggregationDictionary InitializerAggs =>
35-
new GeoBoundsAggregation("viewport", Field<Project>(p => p.Location))
35+
new GeoBoundsAggregation("viewport", Field<Project>(p => p.LocationPoint))
3636
{
3737
WrapLongitude = true
3838
};

src/Tests/Tests/Aggregations/Metric/GeoCentroid/GeoCentroidAggregationUsageTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ public GeoCentroidAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage)
2525
{
2626
geo_centroid = new
2727
{
28-
field = "location"
28+
field = "locationPoint"
2929
}
3030
}
3131
};
3232

3333
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
3434
.GeoCentroid("centroid", gb => gb
35-
.Field(p => p.Location)
35+
.Field(p => p.LocationPoint)
3636
);
3737

3838
protected override AggregationDictionary InitializerAggs =>
39-
new GeoCentroidAggregation("centroid", Infer.Field<Project>(p => p.Location));
39+
new GeoCentroidAggregation("centroid", Infer.Field<Project>(p => p.LocationPoint));
4040

4141
protected override void ExpectResponse(ISearchResponse<Project> response)
4242
{
@@ -76,7 +76,7 @@ public NestedGeoCentroidAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
7676
{
7777
geo_centroid = new
7878
{
79-
field = "location"
79+
field = "locationPoint"
8080
}
8181
}
8282
}
@@ -88,7 +88,7 @@ public NestedGeoCentroidAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
8888
.Field(p => p.Name)
8989
.Aggregations(sa => sa
9090
.GeoCentroid("centroid", gb => gb
91-
.Field(p => p.Location)
91+
.Field(p => p.LocationPoint)
9292
)
9393
)
9494
);
@@ -97,7 +97,7 @@ public NestedGeoCentroidAggregationUsageTests(ReadOnlyCluster i, EndpointUsage u
9797
new TermsAggregation("projects")
9898
{
9999
Field = Infer.Field<Project>(p => p.Name),
100-
Aggregations = new GeoCentroidAggregation("centroid", Infer.Field<Project>(p => p.Location))
100+
Aggregations = new GeoCentroidAggregation("centroid", Infer.Field<Project>(p => p.LocationPoint))
101101
};
102102

103103
protected override void ExpectResponse(ISearchResponse<Project> response)
@@ -128,17 +128,17 @@ public GeoCentroidNoResultsAggregationUsageTests(ReadOnlyCluster i, EndpointUsag
128128
{
129129
centroid = new
130130
{
131-
geo_centroid = new { field = "location" }
131+
geo_centroid = new { field = "locationPoint" }
132132
}
133133
};
134134

135135
protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
136136
.GeoCentroid("centroid", gb => gb
137-
.Field(p => p.Location)
137+
.Field(p => p.LocationPoint)
138138
);
139139

140140
protected override AggregationDictionary InitializerAggs =>
141-
new GeoCentroidAggregation("centroid", Infer.Field<Project>(p => p.Location));
141+
new GeoCentroidAggregation("centroid", Infer.Field<Project>(p => p.LocationPoint));
142142

143143
protected override QueryContainer QueryScope => new TermQuery { Field = Infer.Field<Project>(p => p.Name), Value = "noresult" };
144144
protected override object QueryScopeJson { get; } = new { term = new { name = new { value = "noresult" } } };

src/Tests/Tests/ClientConcepts/HighLevel/Inference/Equality/FieldsEqualityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ [U] public void TypedNotEq()
6161
t1.Should().NotBeEquivalentTo(t2);
6262

6363
t1 = Infer.Field<Project>(p => p.Name, 1.0);
64-
t2 = Infer.Field<Project>(p => p.Location, 1.0);
64+
t2 = Infer.Field<Project>(p => p.LocationPoint, 1.0);
6565
(t1 != t2).ShouldBeTrue(t2);
6666
t1.Should().NotBeEquivalentTo(t2);
6767
}

src/Tests/Tests/Indices/MappingManagement/PutMapping/PutMappingApiTest.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public PutMappingApiTests(WritableCluster cluster, EndpointUsage usage) : base(c
6969
},
7070
type = "object"
7171
},
72-
location = new
72+
locationPoint = new
7373
{
7474
properties = new
7575
{
@@ -78,6 +78,10 @@ public PutMappingApiTests(WritableCluster cluster, EndpointUsage usage) : base(c
7878
},
7979
type = "object"
8080
},
81+
locationShape = new
82+
{
83+
type = "geo_shape"
84+
},
8185
metadata = new { type = "object" },
8286
name = new
8387
{
@@ -236,7 +240,7 @@ public PutMappingApiTests(WritableCluster cluster, EndpointUsage usage) : base(c
236240
}
237241
},
238242
{
239-
p => p.Location, new ObjectProperty
243+
p => p.LocationPoint, new ObjectProperty
240244
{
241245
Properties = new Properties<SimpleGeoPoint>
242246
{
@@ -245,6 +249,7 @@ public PutMappingApiTests(WritableCluster cluster, EndpointUsage usage) : base(c
245249
}
246250
}
247251
},
252+
{ p => p.LocationShape, new GeoShapeProperty() },
248253
{ p => p.Metadata, new ObjectProperty() },
249254
{ p => p.Name, new TextProperty { Index = false } },
250255
{ p => p.NumberOfCommits, new NumberProperty(NumberType.Integer) },

0 commit comments

Comments
 (0)