Commit 50891f7
authored
Adds nested field support with query, aggregation tests and serialization fixes (#150)
* Adds nested field support in tests
Introduces nested field support and related tests.
This commit addresses the need for testing nested fields.
It includes a new test file, updates configurations,
and adds utilities for generating test data with nested properties.
A nested field is also added to the default search fields.
* formatting updates
* Adds nested aggregations filtering tests
Adds tests to verify filtering of nested aggregations using include and exclude.
This ensures that aggregations can be filtered based on specific values within nested fields, providing more granular control over the aggregation results.
Also improves readability in existing tests.
* Fixes nested aggregation serialization
Addresses issues with deserializing nested aggregations in Elasticsearch queries.
This change ensures that nested aggregations, particularly those involving terms aggregations on nested fields, are correctly serialized and deserialized. It corrects the format of aggregations expressions in tests and handles the deserialization of SingleBucketAggregates correctly.
* Adds comprehensive nested field query tests
Updates Foundatio.Parsers.ElasticQueries dependency to support enhanced nested field parsing.
Introduces new test cases for various nested query scenarios in FindAsync:
- Queries on individual nested fields without group syntax.
- Nested range queries.
- Nested AND conditions without group syntax.
- Queries mixing nested and non-nested fields.
- Negated nested group queries.
Refactors existing test code for clarity and minor performance improvements.
* Add comprehensive serialization round-trip tests and upgrade parsers
- Add round-trip tests for all aggregate types (ValueAggregate, StatsAggregate, ExtendedStatsAggregate, PercentilesAggregate, ObjectValueAggregate, DateValueAggregate, BucketAggregate, SingleBucketAggregate)
- Add round-trip tests for all bucket types (KeyedBucket<string>, KeyedBucket<double>, DateHistogramBucket, RangeBucket) with inner aggregation preservation
- Add deep nesting round-trip test (sbucket -> bucket -> keyed bucket -> value)
- Upgrade Foundatio.Parsers.ElasticQueries to 7.18.0-beta4
- Simplify SetDefaultFields to use plain strings consistently
Made-with: Cursor
* Fix serializer converters to properly handle non-public setters
Both Newtonsoft and System.Text.Json converters now explicitly extract Items for PercentilesAggregate, matching the existing pattern used by BucketsNewtonsoftJsonConverter for inner aggregations. This fixes a latent bug where serializer.Populate and element.Deserialize could not set properties with internal/protected setters through the custom converters. Reverts PercentilesAggregate.Items back to internal set to preserve the original API contract.
Made-with: Cursor
* Add isolated serializer tests and deep nesting coverage
Re-adds isolated Newtonsoft and System.Text.Json tests for SingleBucketAggregate to catch serializer-specific regressions. Adds 3-level deep sbucket nesting test and mixed sub-aggregation test (stats + percentiles + bucket-with-sub-agg inside a single bucket).
Made-with: Cursor
* Refactor converters to use pattern matching and readonly types
Replaces if/switch chains with switch expressions in both Newtonsoft and STJ aggregate converters. Extracts dedicated methods for percentiles and sbucket deserialization. Deserializes to IReadOnlyList to skip constructor allocations. Removes serializer-specific tests in favor of the existing all-serializers loop test.
Made-with: Cursor
* Clean up GetProperty and document tophits limitation
Makes GetProperty and GetTokenType static directly, removing the unnecessary GetPropertyStatic/GetProperty indirection. Adds comments to both converters explaining why TopHitsAggregate cannot be round-tripped.
Made-with: Cursor
* Remove JsonConstructor attributes, handle all types explicitly in converters
SingleBucketAggregate and MultiBucketAggregate no longer need JsonConstructor attributes. The STJ converter now explicitly extracts Aggregations for sbucket (matching the Newtonsoft converter pattern), so both serializers handle non-public setters consistently through converter-level extraction rather than relying on STJ fallback behavior.
Made-with: Cursor
* updated deps
* Ensures culture-invariant string casing
Updates `ToLower()` calls to `ToLowerInvariant()` for JSON property name lookups and Elasticsearch default field configurations. This promotes consistent string comparison and conversion, mitigating potential issues with culture-specific casing rules across different environments.
Adds documentation to `AggregationQueryTests` explaining the limitations of JSON round-tripping for `TopHitsAggregate` due to its internal use of `ILazyDocument` references.
Refactors test setup in `NestedFieldTests` by renaming `utcToday` to `baseDate` for improved clarity, better reflecting its role as a fixed reference point in the tests.
* Docs: Add comprehensive nested query/aggregation guide
Adds detailed documentation explaining how the framework automatically handles Elasticsearch nested types.
Explains how filter and aggregation expressions on nested fields are automatically wrapped in appropriate nested queries and aggregations. Covers:
- Basic and advanced nested query patterns
- Nested field aggregations and result access
- Sorting, _exists_/_missing_, and default fields with nested paths
- The Top Hits aggregation and its serialization limitations1 parent c63eefa commit 50891f7
19 files changed
Lines changed: 1399 additions & 150 deletions
File tree
- docs/guide
- samples/Foundatio.SampleApp
- Client
- Server
- src
- Foundatio.Repositories.Elasticsearch
- Foundatio.Repositories
- Models/Aggregations
- Utility
- tests
- Foundatio.Repositories.Elasticsearch.Tests
- Repositories
- Configuration/Indexes
- Models
- Foundatio.Repositories.Tests
- Serialization/Models
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
| 383 | + | |
| 384 | + | |
383 | 385 | | |
384 | 386 | | |
385 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
299 | 499 | | |
300 | 500 | | |
301 | 501 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
Lines changed: 31 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | | - | |
21 | | - | |
| 22 | + | |
22 | 23 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
56 | 35 | | |
57 | | - | |
58 | | - | |
| 36 | + | |
59 | 37 | | |
60 | 38 | | |
61 | 39 | | |
62 | 40 | | |
63 | 41 | | |
64 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
65 | 58 | | |
66 | 59 | | |
67 | 60 | | |
| |||
0 commit comments