Skip to content

Conversation

niemyjski
Copy link
Member

Related FoundatioFx/Foundatio.Repositories#150

Adds support for nested queries and aggregations. This change allows the parser to automatically wrap nested fields in nested queries and aggregations, simplifying the query and aggregation building process.

Adds multiple tests to ensure that the nested queries and aggregations are built correctly.

Adds support for nested queries and aggregations. This change allows the parser to automatically wrap nested fields in nested queries and aggregations, simplifying the query and aggregation building process.

Adds multiple tests to ensure that the nested queries and aggregations are built correctly.
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces nested query and aggregation support to the Foundatio.Parsers.ElasticQueries library, allowing automatic wrapping of nested fields in appropriate Elasticsearch nested queries and aggregations to simplify the query building process.

  • Adds comprehensive test coverage for nested field handling in queries, aggregations, and mixed operations
  • Includes tests for various scenarios including single fields, multiple fields, range queries, and filtering operations
  • Validates that the parser correctly wraps nested field operations in proper Elasticsearch nested contexts

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticQueryParserTests.cs Adds 9 comprehensive test methods covering nested query and aggregation functionality
src/Foundatio.Parsers.ElasticQueries/Visitors/CombineAggregationsVisitor.cs Adds a TODO comment for future investigation

var termNode = child as TermNode;
if (termNode != null && termsAggregation != null)
{
// Look into this...
Copy link
Preview

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment 'Look into this...' is vague and doesn't provide clear guidance about what needs investigation. Consider replacing it with a more specific description of what needs to be looked into or remove it if it's not necessary.

Suggested change
// Look into this...

Copilot uses AI. Check for mistakes.

var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings<MyNestedType>(Client).UseNested());

// Act
var result = await processor.BuildAggregationsAsync("terms:(nested.field1~@include:apple,banana,cherry nested.field4~@include:1,2,3)");
Copy link
Member Author

@niemyjski niemyjski Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this syntax is wrong: "terms:(field1 @include:myinclude )

var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings<MyNestedType>(Client).UseNested());

// Act
var result = await processor.BuildAggregationsAsync("terms:(nested.field1 @exclude:myexclude @include:myinclude @include:otherinclude @missing:mymissing @exclude:otherexclude @min:1)");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be simplified

Updates query parser to correctly handle include/exclude lists for nested fields.

- Corrects an issue where nested field includes were not properly parsed.
- Modifies the expected type for include/exclude values to string for consistency.
- Converts relevant tests to async and updates assertion logic to match expected behavior.
Moves the MyNestedType class definition from ElasticQueryParserTests to ElasticNestedQueryParserTests.

This change centralizes the type definition where it is primarily used and avoids code duplication, improving code organization and maintainability.
Updates the tests and nested query parsing logic to correctly reference the `MyNestedType` class, resolving type resolution issues.

Additionally, renames one of the nested query parser tests for clarity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant