-
Notifications
You must be signed in to change notification settings - Fork 6
[NAE-2161] Optimize ElasticCaseService queries to eliminate maxClauseCount error #335
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
Conversation
…Count error - optimize queries for elastic and mongo for cases and tasks
WalkthroughThe changes update the Maven parent and project versions from Changes
Sequence Diagram(s)sequenceDiagram
participant Service as Service Method (e.g., buildPetriNetQuery)
participant QueryBuilder as QueryBuilders / TermsQueryField
participant ES as Elasticsearch
Service->>QueryBuilder: Collect identifiers/IDs into TermsQueryField
Service->>QueryBuilder: Build terms query with QueryBuilders.terms
QueryBuilder-->>Service: Return terms query
Service->>ES: Add terms query to BoolQuery and execute
ES-->>Service: Return query result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes Suggested labels
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
♻️ Duplicate comments (4)
nae-user-ce/pom.xml (1)
6-10
: Same concern as innae-user-common/pom.xml
– parent version bump requires the artifact to be published.application-engine/pom.xml (1)
6-10
: Same concern as innae-user-common/pom.xml
– parent version bump requires the artifact to be published.nae-object-library/pom.xml (1)
7-11
: Same concern as innae-user-common/pom.xml
– parent version bump requires the artifact to be published.nae-spring-core-adapter/pom.xml (1)
7-11
: Same concern as innae-user-common/pom.xml
– parent version bump requires the artifact to be published.
🧹 Nitpick comments (1)
application-engine/src/main/java/com/netgrif/application/engine/workflow/service/CaseSearchService.java (1)
347-348
: Remove unnecessary cast to List.The explicit cast is redundant since
collect(Collectors.toList())
already returns aList
.- List<Predicate> expressions = (List<Predicate>) ((ArrayList) query).stream().filter(q -> q instanceof String).map(q -> caseIdString((String) q)).collect(Collectors.toList()); + List<Predicate> expressions = ((ArrayList) query).stream().filter(q -> q instanceof String).map(q -> caseIdString((String) q)).collect(Collectors.toList());
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
application-engine/pom.xml
(1 hunks)application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseService.java
(8 hunks)application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticTaskService.java
(3 hunks)application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticViewPermissionService.java
(3 hunks)application-engine/src/main/java/com/netgrif/application/engine/workflow/service/CaseSearchService.java
(3 hunks)nae-object-library/pom.xml
(1 hunks)nae-spring-core-adapter/pom.xml
(1 hunks)nae-user-ce/pom.xml
(1 hunks)nae-user-common/pom.xml
(1 hunks)pom.xml
(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: in the netgrif application engine, the domain realm class (com.netgrif.application.engine.objects.au...
Learnt from: renczesstefan
PR: netgrif/application-engine#329
File: nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/RealmServiceImpl.java:39-39
Timestamp: 2025-07-31T08:05:21.587Z
Learning: In the Netgrif Application Engine, the domain Realm class (com.netgrif.application.engine.objects.auth.domain.Realm) is abstract and cannot be instantiated. The concrete implementation is in the adapter package (com.netgrif.application.engine.adapter.spring.auth.domain.Realm) which extends the abstract domain class. Services must instantiate the concrete adapter class and cast it when saving to repositories that accept the abstract domain type.
Applied to files:
nae-spring-core-adapter/pom.xml
📚 Learning: in elasticpetrinetservice class, petrinetservice is properly initialized using @lazy setter injectio...
Learnt from: tuplle
PR: netgrif/application-engine#331
File: application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticPetriNetService.java:45-46
Timestamp: 2025-07-29T17:19:18.300Z
Learning: In ElasticPetriNetService class, petriNetService is properly initialized using Lazy setter injection rather than constructor injection. This pattern with Lazy Autowired setter methods is commonly used in Spring to resolve circular dependencies and is a valid alternative to constructor injection.
Applied to files:
application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseService.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build
🔇 Additional comments (9)
nae-user-common/pom.xml (1)
6-10
: Confirm Parent POM7.0.0-RC5
AvailabilityWe attempted to resolve the parent POM with
mvn dependency:get
, but Maven isn’t installed in this environment. Please ensure that com.netgrif:application-engine-parent:7.0.0-RC5 is published to your Nexus or Maven Central before running CI, as all downstream modules will fail at the validate phase otherwise.Location:
- nae-user-common/pom.xml lines 6–10
You can manually verify its availability by running:
mvn -q dependency:get \ -Dartifact=com.netgrif:application-engine-parent:7.0.0-RC5:pom \ -Dtransitive=false(The command should exit with status 0 and no “Could not find artifact” message.)
pom.xml (1)
9-9
: Version update to release candidate looks good.The version change from
7.0.0-SNAPSHOT
to7.0.0-RC5
appropriately moves the project towards a release candidate phase.application-engine/src/main/java/com/netgrif/application/engine/workflow/service/CaseSearchService.java (1)
145-146
: constructPredicateTree is properly defined and inherited
TheconstructPredicateTree
method is implemented inMongoSearchService
(application-engine/src/main/java/com/netgrif/application/engine/workflow/service/MongoSearchService.java) and is accessible toCaseSearchService
via inheritance. No further changes are needed.application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticTaskService.java (2)
359-366
: Good optimization using terms query.The refactoring from multiple term queries to a single terms query helps prevent maxClauseCount errors and improves query performance.
455-462
: Consistent refactoring with proper empty check.Good use of
isEmpty()
instead ofsize() == 0
and consistent application of the terms query pattern.application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseService.java (2)
225-250
: Excellent refactoring with duplicate prevention.Good use of
HashSet
to eliminate duplicates before creating the terms queries. The empty checks ensure no unnecessary queries are added.
460-460
: Good simplification of query structure.Removing the unnecessary
BoolQuery
wrapper makes the code cleaner and more direct.application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticViewPermissionService.java (2)
55-59
: Consistent optimization pattern applied.Good application of the
TermsQueryField
pattern to consolidate multiple role queries into a single terms query, helping prevent maxClauseCount errors.
100-104
: Good explicit configuration of union behavior.Setting
minimumShouldMatch("1")
explicitly clarifies that at least one of the should clauses must match, which is the correct semantics for a union operation.
670dd19
Description
Implements NAE-2161
Dependencies
none
Third party dependencies
No new dependencies were introduced
Blocking Pull requests
There are no dependencies on other PR
How Has Been This Tested?
manually
Test Configuration
Checklist:
Summary by CodeRabbit
Chores
Refactor