Elasticsearch intelligent search method based on Spring Boot
By using an intelligent search method based on Spring Boot for Elasticsearch, the performance bottlenecks and complexity issues of existing Elasticsearch technologies in large-scale data queries and special field processing are resolved. This achieves zero-manual configuration, adaptive pagination, and high-throughput data operations, thereby improving system performance and stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TIANJIN AUTOHOME DATA INFORMATION TECH CO LTD
- Filing Date
- 2026-01-14
- Publication Date
- 2026-04-21
AI Technical Summary
Existing Elasticsearch integration solutions suffer from performance bottlenecks and operational complexity when dealing with large-scale data queries, special field processing, configuration management, and large-scale data operations, which limits their application efficiency in real-world projects.
Employing an intelligent search method based on Spring Boot, it achieves zero-manual configuration by loading Elasticsearch connection, thread pool, timeout, and pagination threshold parameters all at once. It automatically scans entity classes and binds them to index names, adaptively makes pagination decisions, uses a geometric model for deep pagination fetching, caches special fields, automates difference calculations and batch operations, and combines an exponential backoff strategy to ensure high throughput and self-healing from failures.
It improves the performance of querying large amounts of data, simplifies the configuration process, reduces development difficulty, improves development efficiency, optimizes large-scale data operations, ensures system performance and stability, accelerates incremental data update speed, and improves data synchronization efficiency.
Smart Images

Figure CN121901480A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of distributed search and data synchronization technology, and in particular to an intelligent search method for Elasticsearch based on Spring Boot. Background Technology
[0002] With the development of big data technology, Elasticsearch has become the preferred search engine for processing large datasets. It boasts advantages such as high performance, strong scalability, and support for complex queries. However, existing Elasticsearch integration solutions suffer from performance bottlenecks and operational complexity when dealing with large-scale data queries, special field handling, configuration management, data manipulation object construction, and large-scale data operations. These issues limit the efficiency of Elasticsearch in real-world projects. Summary of the Invention
[0003] The purpose of this invention is to provide an intelligent search method for Elasticsearch based on Spring Boot, thereby solving the aforementioned problems existing in the prior art.
[0004] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0005] An intelligent search method for Elasticsearch based on Spring Boot includes the following steps, which proceed sequentially from beginning to end, with each subsequent step executing based directly on the deterministic output of the preceding step:
[0006] S1. Based on the Elasticsearch connection, thread pool, timeout, keep-alive, and pagination threshold parameters in application.yml loaded once during Spring Boot startup, obtain a pre-configured and directly injectable Elasticsearch client instance and a global performance constraint set, thereby eliminating the manual configuration step in all subsequent steps.
[0007] S2. Based on the client instance and the global performance constraint set, scan all entity classes annotated with @EsRepository in the project to obtain the mandatory binding relationship between each entity class and the unique index name esIndex, as well as the optional document unique identifier field esId. If esIndex is missing, the startup will be terminated immediately, thereby ensuring the uniqueness and determinism of subsequent query and update targets.
[0008] S3. Based on the expected total number of records size carried in the user's query request and the pageSize threshold in the global performance constraint set, an adaptive pagination decision result is obtained: when size≤pageSize, the decision output is "from+size single batch" instruction, and when size>pageSize, the decision output is "search after multiple batches" instruction, thus completing the irreversible locking of the shallow / deep pagination path at the moment the query is initiated.
[0009] S4. Based on the adaptive pagination decision, send one or more batches of retrieval requests to Elasticsearch in sequence to obtain the original hit set. The sort value of the last document returned in each batch is captured immediately and used as the cursor for the next batch, thereby achieving linear incremental retrieval of deep pagination without the need for global re-sorting.
[0010] S5. Based on the automatic identification results of whether dynamic fields, aggregate fields, script fields, or latitude and longitude fields appear in the original hit set, two mapping paths are obtained: if no special fields are identified, the high-speed deserialization channel is directly entered; if special fields are identified, the Java reflection mapping channel is entered, and the entity class metadata is cached for the first time, so that subsequent similar queries can directly reuse the cache, thereby ensuring the integrity of the fields while avoiding reflection performance loss.
[0011] S6. Based on the list of completed assigned entity objects output by the mapping path, obtain the final high-completeness query result that can be returned to the user, thus completing the query phase;
[0012] S7. Based on the incremental data update request subsequently initiated by the user, the list of entity objects returned in the previous step and still residing in memory is used as the "snapshot to be written". Combined with the esId or user-defined comparison function, the difference is calculated with the "storage snapshot" in the existing Elasticsearch index to obtain an accurate set of three-state operations to be added, updated, and deleted. This transforms the full comparison into a minimal set of operations only for the difference documents.
[0013] S8. Based on the comparison between the total number of three-state operation sets and the bulkSize value in the global performance constraint set, several sub-batch tasks are automatically split. The number of operations in each sub-task does not exceed bulkSize. The Elasticsearch native bulk interface is called in sequence, and when the interface returns a failure, a retry is performed according to the exponential backoff strategy until the maximum number of retries is reached, thereby achieving self-healing from failure while ensuring high throughput.
[0014] S9. Finally, based on the completion signal of step S8, a set of entity data that maintains eventual consistency with the Elasticsearch index is obtained, and the update completion status is fed back to the outside. Thus, a fully intelligent closed loop from configuration, query, mapping to incremental synchronization is achieved with zero human intervention.
[0015] Preferably, step S1 calculates and generates the global performance constraint set required by the Elasticsearch client instance in one step using the following geometric scaling formula:
[0016] Let the expected peak throughput radius be r (unit: kilo-requests / second), then
[0017] A=πr² (1)
[0018] Equation (1) gives the "equivalent area" A of the service load;
[0019] Using A as input, press
[0020] P = [k·A] (2)
[0021] Calculate the number of thread pool cores P, where k = 0.8 to 1.2 is the CPU core density coefficient;
[0022] Then, using P as the reference,
[0023] C = 2P + 4 (3)
[0024] Get the maximum number of connections C in the connection pool.
[0025] The P, C, and timeout and keep-alive parameters derived from equation (1) are written into the Spring Boot Environment at once, and then automatically injected by @ConfigurationProperties to complete the zero-manual configuration of the Elasticsearch client instance.
[0026] Preferably, in step S2, when scanning the @EsRepository entity class, the uniqueness of the index name esIndex is verified using the geometric coverage formula: Let the set of scanned entity classes be a set of planar points {E1, E2, ..., E...}. n}, the projection of each entity class Eᵢ onto the index namespace is a degenerate circle with center oᵢ and radius = 0. If the distance between any two centers is...
[0027] d(oᵢ,oⱼ)=0 (i≠j)
[0028] If a duplicate index name is detected, an IllegalStateException is immediately thrown and the startup is terminated. Only when all center points are distinct will each Eᵢ be forcibly bound to the corresponding esIndex and written to the memory-mapped table, thereby ensuring the uniqueness and determinism of the target for subsequent queries and updates.
[0029] Preferably, step S3 completes the adaptive paging decision using the following geometric discriminant:
[0030] Let the user expect the total number of returned records to be equal to the area of the rectangle S = size, and pageSize be the side length p of the square. Define the discriminant area.
[0031] Δ=S−p² (1)
[0032] When Δ≤0, it is determined that the rectangle can be covered by the square in one go, and the command "from+size single batch" is output;
[0033] When Δ>0, calculate the minimum number of covering squares.
[0034] N=[S / p²] (2)
[0035] It outputs the command "search after N batches" and uses the sort value of the last document as the coordinate of the lower left corner of the next square after each batch is fetched, thus achieving linear incremental coverage of deep pagination and completing the irreversible locking of shallow / deep pagination paths the moment the query is initiated.
[0036] Preferably, step S4 uses the following geometric cursor model to achieve linear incremental fetching for deep pagination:
[0037] Each batch of returned documents is treated as a set of points on a two-dimensional plane. After sorting them in ascending order by the sorting field value, the sorting value of the last document is taken as point P(x, y). A straight line L perpendicular to the sorting axis is drawn with P as the tangent point, and L is used as the half-plane boundary condition search_after = P_value for the next batch of queries.
[0038] Repeat the above process to ensure that the new batch of results is always located in the right half of the plane of L. Thus, without re-sorting the global data, the entire result set is linearly incrementally covered by successively translating the boundary line L, achieving continuous and non-overlapping fetching of deep pagination.
[0039] Preferably, after determining the existence of special fields in step S5, the Field array and Setter method of the entity class are immediately registered in key-value form to the "mapping cache" composed of ConcurrentHashMap. Subsequent query requests for the same entity class directly reference the contents of the cache to complete the field injection, avoiding repeated reflection parsing, thereby eliminating the reflection overhead in one go while ensuring the integrity of the fields.
[0040] Preferably, in step S6, before outputting the list of entity objects, the confidence level C of the list is calculated using the following integrity check formula:
[0041] C=(1-e^(-k·N))·100%
[0042] In the formula:
[0043] N represents the number of entity objects that have been assigned values.
[0044] k is the field mapping success rate coefficient (0) <k≤1);
[0045] The list is only encapsulated as a query result and returned when C≥99%; otherwise, a compensation mapping process is triggered to ensure that the query result returned to the user is highly complete.
[0046] Preferably, step S7 uses the following difference quantization formula to calculate the change density D between the "snapshot to be written" and the "storage snapshot":
[0047] D = (|Δ_ins|+|Δ_upd|+|Δ_del|) / |Snapshot_mem|
[0048] In the formula:
[0049] Δ_ins, Δ_upd, and Δ_del represent the number of documents to be added, updated, and deleted, respectively.
[0050] Snapshot_mem is the total number of memory snapshots;
[0051] A set of three-state operations is generated only when D > 0; otherwise, the subsequent update process is skipped, thus transforming the full comparison into a set of minimum difference operations.
[0052] Preferably, step S8 determines the number of sub-batches based on the ratio of the total amount of the three-state operation set |T| to bulkSize:
[0053] B=[|T| / bulkSize]
[0054] It creates B subtask queues, each with a capacity equal to bulkSize, and submits each queue serially to the Elasticsearch bulk interface. If a subtask submission fails, it retryes at an exponential backoff interval of 2^(retry-1)·t0 (t0=1s) until it succeeds or reaches the maximum number of retries R_max=3, thus achieving self-healing from failure under high throughput.
[0055] Preferably, in step S9, after receiving the success receipt of the last subtask, the index consistency score is calculated:
[0056] C_idx = (1-E / N)·100%
[0057] In the formula:
[0058] E represents the cumulative number of failed documents.
[0059] N represents the total number of documents to be updated;
[0060] When C_idx ≥ 99%, return an "update complete" status to the user; otherwise, trigger a compensation task to re-execute the writing or deletion of missing documents, ensuring that the data after the intelligent closed-loop process remains eventually consistent with the Elasticsearch index.
[0061] The beneficial effects of this invention are:
[0062] Improved the performance of large-scale data queries and increased system response speed;
[0063] Reduce the complexity of handling special fields and lower the development difficulty;
[0064] Simplify the configuration process and avoid redundancy and misconfiguration;
[0065] Automated data manipulation object construction reduces repetitive code and improves development efficiency;
[0066] Optimize large-scale data operations to ensure system performance and stability;
[0067] Accelerate the speed of incremental data updates and improve data synchronization efficiency. Attached Figure Description
[0068] Figure 1 This is the automated query performance optimization process of the present invention;
[0069] Figure 2 This is the automatic parsing process for special fields in this invention;
[0070] Figure 3 This invention relates to an automated configuration management process;
[0071] Figure 4This is the automated incremental data update process of the present invention;
[0072] Figure 5 This is the overall architecture topology diagram of the present invention;
[0073] Figure 6 This is a flowchart of the search after deep pagination process of the present invention;
[0074] Figure 7 This is a schematic diagram of the special field reflection mapping of the present invention;
[0075] Figure 8 This is the timing diagram for batch splitting and retrying in this invention. Detailed Implementation
[0076] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0077] Reference Figures 1 to 8 The method described is an intelligent Elasticsearch search method based on Spring Boot, which includes the following steps that proceed sequentially from beginning to end, with each subsequent step executing directly based on the deterministic output of the preceding step:
[0078] S1. Based on the Elasticsearch connection, thread pool, timeout, keep-alive, and pagination threshold parameters in application.yml loaded once during Spring Boot startup, obtain a pre-configured Elasticsearch client instance and a global performance constraint set that can be directly injected and used, thereby eliminating the manual configuration step in all subsequent steps.
[0079] S2. Based on the client instance and the global performance constraint set, scan all entity classes annotated with @EsRepository in the project to obtain the mandatory binding relationship between each entity class and the unique index name esIndex, as well as the optional document unique identifier field esId. If esIndex is missing, the startup will be terminated immediately, thereby ensuring the uniqueness and determinism of the target for subsequent queries and updates.
[0080] S3. Based on the expected total number of records size carried in the user's query request and the pageSize threshold in the global performance constraint set, an adaptive pagination decision result is obtained: when size≤pageSize, the decision output is "from+size single batch" instruction, and when size>pageSize, the decision output is "search after multiple batches" instruction, thus completing the irreversible locking of the shallow / deep pagination path at the moment the query is initiated.
[0081] S4. Based on the adaptive pagination decision, send one or more batches of retrieval requests to Elasticsearch in sequence to obtain the original hit set. The sort value of the last document returned in each batch is captured immediately and used as the cursor for the next batch, thereby achieving linear incremental retrieval of deep pagination without the need for global re-sorting.
[0082] S5. Based on the automatic identification results of whether dynamic fields, aggregate fields, script fields, or latitude and longitude fields appear in the original hit set, two mapping paths are obtained: if no special fields are identified, the high-speed deserialization channel is directly entered; if special fields are identified, the Java reflection mapping channel is entered, and the entity class metadata is cached for the first time, so that subsequent similar queries can directly reuse the cache, thereby ensuring the integrity of the fields while avoiding reflection performance loss.
[0083] S6. Based on the list of completed assigned entity objects output by the mapping path, obtain the final high-completeness query result that can be returned to the user, thus completing the query phase;
[0084] S7. Based on the incremental data update request subsequently initiated by the user, the list of entity objects returned in the previous step and still residing in memory is used as the "snapshot to be written". Combined with the esId or user-defined comparison function, the difference is calculated with the "storage snapshot" in the existing Elasticsearch index to obtain an accurate set of three-state operations to be added, updated, and deleted. This transforms the full comparison into a minimal set of operations only for the difference documents.
[0085] S8. Based on the comparison between the total number of three-state operation sets and the bulkSize value in the global performance constraint set, several sub-batch tasks are automatically split. The number of operations in each sub-task does not exceed bulkSize. The Elasticsearch native bulk interface is called in sequence, and when the interface returns a failure, a retry is performed according to the exponential backoff strategy until the maximum number of retries is reached, thereby achieving self-healing from failure while ensuring high throughput.
[0086] S9. Finally, based on the completion signal of step S8, a set of entity data that maintains eventual consistency with the Elasticsearch index is obtained, and the update completion status is fed back to the outside. Thus, a fully intelligent closed loop from configuration, query, mapping to incremental synchronization is achieved with zero human intervention.
[0087] In this embodiment, the specific operations of each of the above steps are as follows:
[0088] S1 Zero-Manual Configuration – Generation of “Area-Scale” Performance Constraint Sets
[0089] At startup, Spring Boot reads the connection string, timeout, keep-alive, and pagination threshold from application.yml into the Environment. Then, the framework treats the "expected peak throughput radius r (unit: kilo-requests / second)" as the radius of a circle, using the area A = πr² to characterize the "equivalent area" of the business load. It then uses this area to calculate the number of thread pool cores P = ⌈k·A⌉ and the maximum number of connection pool connections C = 2P + 4. Finally, P, C, and the timeout and keep-alive parameters derived from the area are injected into the container all at once. Therefore, any subsequent component only needs to "request" the client directly, without needing to worry about details such as hosts, accounts, and thread counts, achieving truly zero-manual configuration.
[0090] S2 Index Uniqueness – “Degenerate Circle” Geometric Coverage Verification
[0091] The framework scans all entity classes annotated with `@EsRepository`, treating each index name `esIndex` as a degenerate circle with a radius of zero, the center of which is the index name string. If the distance between any two centers is zero, it indicates a name conflict, immediately throwing an `IllegalStateException` and terminating the application startup. Only when all centers are distinct is the entity forcibly bound to `esIndex`, forming a memory-mapped table. This geometric coverage validation is completed all at once during application startup, fundamentally eliminating the potential risks of "one entity corresponding to multiple indexes" or "multiple entities competing for the same index," providing a unique and deterministic namespace for subsequent queries and updates.
[0092] S3 Adaptive Pagination – Rectangle-Square Area Determination
[0093] After receiving the user's expected total number of records size, the framework treats size as the area S of a rectangle and the global parameter pageSize as the side length p of a square, and calculates the discrimination area Δ = S − p².
[0094] If Δ≤0, the rectangle can be completely covered by a single square, and the decision is locked as "from+size single batch";
[0095] If Δ>0, continue to calculate the minimum number of covering squares N=⌈S / p²⌉, and lock it as "search after N batches".
[0096] The area determination is completed the moment the query is initiated, and the subsequent process will not change it, thus achieving "irreversible locking" of the shallow / deep pagination path and avoiding the overhead of re-evaluation at runtime.
[0097] S4 Linear Incremental Fetch – “Half-Plane Vernier” Deep Paging Model
[0098] After entering multi-batch mode, the documents returned in each batch are sorted in ascending order by the sorting field. The framework abstracts the sort value of the last document as a plane point P, and draws a straight line L perpendicular to the sorting axis at P. L is used as the half-plane boundary condition for the next batch (search_after = P_value). The results of the new batch are always located in the right half-plane of L, and the linear incremental coverage of the entire result set is completed by successively translating the straight line L. This process does not require global re-sorting and does not depend on external state, achieving continuous, non-overlapping, and non-repeating fetching of deep pagination.
[0099] S5 Field Mapping – “Dual-Channel” Caching Strategy
[0100] The framework first performs feature detection on the hit results: if only a regular `_source` field is present, the high-speed deserialization channel is used; if dynamic fields, aggregate fields, script fields, or latitude and longitude fields are detected, the Java reflection mapping channel is entered, and after the first reflection, the entity class's Field array and Setter methods are registered as keys in a "mapping cache" composed of a ConcurrentHashMap. Subsequent similar queries directly reuse the cache content, avoiding repeated reflection parsing, thus eliminating reflection overhead in one go while ensuring field integrity.
[0101] S6 High Integrity Output – “Confidence” Gatekeeping Mechanism
[0102] Before returning the results, the framework calculates the list confidence score C = (1 − e^(−k·N))·100%, where N is the number of entities assigned values and k is the mapping success rate coefficient. Only when C ≥ 99% is the list encapsulated as the final query result; otherwise, a compensation mapping process is triggered to perform a second injection on unsuccessful fields, ensuring that every piece of data received by the user is in a complete and trustworthy state.
[0103] S7 Difference Calculation – Minimize Operation Set for “Change Density”
[0104] The framework refers to the list of entities still residing in S6 memory as "snapshots to be written". It performs a Map difference operation with the "stored snapshots" on the ES side using esId or a user-defined comparison function to obtain the entities to be added (Δ_ins), updated (Δ_upd), and deleted (Δ_del). It then calculates the change density D = (|Δ_ins| + |Δ_upd| + |Δ_del|) / |Snapshot_mem|. If D = 0, subsequent network I / O is skipped; if D > 0, a three-state operation set is generated, transforming the process from a full comparison to a set of operations that minimizes the differences between documents.
[0105] S8 Sub-batch Splitting - "Round Up" Geometric Slicing
[0106] The framework uses B = ⌈|T| / bulkSize⌉ to divide the tri-state set into B equal-length "slices," each slice's length being ≤bulkSize. Then, it sequentially submits the ES bulk interface according to the slice's sequence number. If a slice fails, it only performs exponential backoff retries on that slice: interval = 2^(retry−1)·1 s, maximum 3 times. This geometric slicing strategy ensures full load on the bulk channel while avoiding memory thrashing caused by extremely large requests, achieving self-healing from failures under high throughput.
[0107] S9 Eventual Consistency – Closed-Loop Acceptance Based on "Consistency Score"
[0108] Once the last slice's successful receipt arrives, the framework calculates the index consistency score C_idx = (1 − E / N)·100%, where E is the cumulative number of failed documents and N is the total number of documents awaiting updates. If C_idx ≥ 99%, an "update complete" event is immediately returned to the business thread; otherwise, a compensation task is automatically triggered to rewrite or delete the missing documents until the score reaches the target. At this point, configuration, querying, mapping, and incremental synchronization form a fully intelligent closed loop, requiring no manual intervention throughout the entire process.
[0109] Through the above nine steps, this invention transforms traditional "experience-based" tuning into a "quantifiable, verifiable, and self-healing" mathematical model, significantly improving the ease of use, performance, and reliability of Elasticsearch in the Spring Boot ecosystem.
[0110] Preferably, step S1 calculates and generates the global performance constraint set required by the Elasticsearch client instance in one step using the following geometric scaling formula:
[0111] Let the expected peak throughput radius be r (unit: kilo-requests / second), then
[0112] A=πr² (1)
[0113] Equation (1) gives the "equivalent area" A of the service load;
[0114] Using A as input, press
[0115] P = [k·A] (2)
[0116] Calculate the number of thread pool cores P, where k = 0.8 to 1.2 is the CPU core density coefficient;
[0117] Then, using P as the reference,
[0118] C = 2P + 4 (3)
[0119] Get the maximum number of connections C in the connection pool.
[0120] The P, C, and timeout and keep-alive parameters derived from equation (1) are written into the Spring Boot Environment at once, and then automatically injected by @ConfigurationProperties to complete the zero-manual configuration of the Elasticsearch client instance.
[0121] The method for generating the "geometric area" of the global performance constraint set S1 is as follows:
[0122] 1. Setting the peak throughput radius
[0123] Before system startup, operations personnel only need to fill in one observable business metric in application.yml—the "expected peak QPS," in "thousand requests per second." The framework treats this value as a circle with radius r, establishing a "throughput circle" model on a two-dimensional plane: the center of the circle is located at the origin, the radius r corresponds to the peak QPS, and the area A of the circle represents the "equivalent concurrent pressure area." This area simultaneously encompasses request density and the concurrent fan-shaped diffusion effect, providing a more accurate depiction of the actual load volume than simply using the QPS number.
[0124] 2. Calculation of equivalent area A
[0125] The load area A is calculated in one step using the formula for the area of a circle, A = πr². The unit of A is "(thousand requests / second)²", which physically represents the spatial projection of the total number of requests per unit time. The larger the area, the more concurrent connections, threads, and network buffer resources the system needs to handle simultaneously. This transforms the "soft QPS expectation" into a "measurable geometric quantity".
[0126] 3. Introduction of CPU density coefficient k
[0127] To avoid a "sole reliance on area," the framework introduces a CPU core density coefficient k (ranging from 0.8 to 1.2). The rules for determining the value of k are as follows:
[0128] When the application's host machine has 4 cores or less, k should be close to 0.8 to prevent too many threads from causing switching.
[0129] When the host machine has 8 to 16 cores, k is set to 1.0 to maintain a 1:1 mapping between area and number of cores;
[0130] When the host machine has more than 16 cores or hyper-threading is enabled, k can be increased to 1.2 to make full use of the remaining computing power.
[0131] This coefficient is automatically detected and obtained through the Runtime interface at startup, without the need for manual input.
[0132] 4. Conversion of thread pool core count P
[0133] After obtaining the area A and density k, the number of thread pool cores P is obtained by rounding up P = [k·A]. P represents the "minimum number of worker threads matching the business area", ensuring that the average concurrent area carried by each thread is constant, avoiding overload or starvation caused by the traditional "fixed 2×CPU" or "blindly 200 threads".
[0134] 5. Derivation of the maximum number of connections C in the connection pool
[0135] Using P as a baseline, the upper limit C of the connection pool is calculated using C = 2P + 4. This linear expression is derived from empirical observations.
[0136] 2P guarantees that each thread has at least one connection available at any time;
[0137] +4 is an additional buffer to handle connection leaks, Keep-Alive redundancy, and transient spikes.
[0138] Thus, C dynamically scales with P, rather than having its value hard-coded, achieving a cascading amplification of "area → thread → connection".
[0139] 6. Inverse calculation of timeout and keep-alive parameters
[0140] A larger area A indicates a longer request transit time and higher tail latency. The framework automatically inversely calculates this based on a linear empirical model of "area-time".
[0141] Connection timeout t_conn = baseline 5s + A × 0.2s;
[0142] Socket timeout t_socket = base 15s + A × 0.5s;
[0143] The connection keep-alive time t_keep = baseline 60s + A × 1s.
[0144] The reverse calculation results are also written to the Environment to ensure "large-area long timeout and small-area short timeout" to prevent resource idleness or premature disconnection caused by "one-size-fits-all" approach.
[0145] 7. One-time injection and zero subsequent impact
[0146] The three timeout parameters (P, C, and ...) mentioned above are uniformly written into the Environment during the early stages of Spring Boot startup, and then injected into the connection pool, thread pool, and REST client constructor all at once by @ConfigurationProperties. Subsequent components from S2 to S9 only need to directly use the "pre-configured" client, without needing to worry about the address, account, thread count, or timeout value, thus completely eliminating the manual configuration step and achieving an automated closed loop where "area determines everything."
[0147] Preferably, in step S2, when scanning the @EsRepository entity class, the uniqueness of the index name esIndex is verified using the geometric coverage formula: Let the set of scanned entity classes be a set of planar points {E1, E2, ..., E...}. n}, the projection of each entity class Eᵢ onto the index namespace is a degenerate circle with center oᵢ and radius = 0. If the distance between any two centers is...
[0148] d(oᵢ,oⱼ)=0 (i≠j)
[0149] If a duplicate index name is detected, an IllegalStateException is immediately thrown and the startup is terminated. Only when all center points are distinct will each Eᵢ be forcibly bound to the corresponding esIndex and written to the memory-mapped table, thereby ensuring the uniqueness and determinism of the target for subsequent queries and updates.
[0150] S2 Index Name Uniqueness – “Degenerate Circle” Geometric Coverage Verification as follows:
[0151] Entity scanning and index name extraction
[0152] During application startup, the framework leverages Spring's classpath scanning capabilities to identify all entity classes annotated with `@EsRepository` in one go. For each entity class, the `esIndex` attribute value within the annotation is immediately parsed to obtain a candidate index name string. This string serves as the "namespace identifier" for all subsequent read and write operations and must maintain a one-to-one relationship across the entire application.
[0153] Establishment of the degenerate circle model
[0154] To geometrically characterize whether an index name is duplicated, the framework introduces the concept of a "degenerate circle":
[0155] Map the index name string to a point on a two-dimensional plane—the center oᵢ;
[0156] Since the index name only cares about whether it is completely identical and not about similarity, the radius of the circle is set to 0, which is called the "degenerate circle".
[0157] At this point, whether the two degenerate circles overlap depends entirely on whether their center coordinates coincide.
[0158] Rules for calculating and determining the distance between the centers
[0159] For any two degenerate circles oᵢ and oⱼ (i≠j), calculate the Euclidean distance d(oᵢ, oⱼ).
[0160] If d=0, it means that two entities point to the same index name, which is immediately determined to be a conflict;
[0161] If d > 0, it means that the index names are different and the verification passes.
[0162] At the string level, this distance calculation is equivalent to "whether the index names are exactly the same". The geometric representation is just to leave room for subsequent visualization and expansion.
[0163] Conflict Management and Fail-Fast
[0164] Once a conflict pair with d = 0 is detected, the framework immediately throws an IllegalStateException, providing the fully qualified name of the conflicting entity class and the duplicate index name in the exception message, and the application terminates immediately upon startup. This "fail-fast" mechanism ensures that naming overlap issues are detected during the development phase, preventing data overwriting or abnormal query results due to mixed indexes during online runtime.
[0165] Binding and table entry after uniqueness verification
[0166] When the center distance of all degenerate circles is greater than 0, the framework forcibly binds each entity class Eᵢ to its unique esIndex, forming an "entity-index" memory mapping table. This table is frequently referenced in subsequent S3-S9:
[0167] The query phase is used to locate the target index;
[0168] The update phase is used to route bulk requests;
[0169] It is used to reverse locate the source of an entity during anomaly diagnosis.
[0170] Because the binding relationship is fixed at startup and does not change during runtime, the index and entity always maintain a one-to-one determinism throughout the entire lifecycle.
[0171] Scalability of geometric models
[0172] The degenerate circle model not only detects "identical" patterns but also reserves the capability for "similarity conflicts" in the future: if fuzzy matching is required, simply adjust the radius r to a small value greater than 0, and the similarity can be measured by the area of the intersecting circles. The current degenerate case with r=0 is a special case of this general model, balancing simplicity and rigor.
[0173] Through the above six steps, S2 completes the geometrical exclusive check of the "index namespace" at startup, completely eliminating the risk of duplicate names and laying a unique and definite naming foundation for all subsequent query and update operations.
[0174] Preferably, step S3 completes the adaptive paging decision using the following geometric discriminant:
[0175] Let the user expect the total number of returned records to be equal to the area of the rectangle S = size, and pageSize be the side length p of the square. Define the discriminant area.
[0176] Δ=S−p² (1)
[0177] When Δ≤0, it is determined that the rectangle can be covered by the square in one go, and the command "from+size single batch" is output;
[0178] When Δ>0, calculate the minimum number of covering squares.
[0179] N=[S / p²] (2)
[0180] It outputs the command "search after N batches" and uses the sort value of the last document as the coordinate of the lower left corner of the next square after each batch is fetched, thus achieving linear incremental coverage of deep pagination and completing the irreversible locking of shallow / deep pagination paths the moment the query is initiated.
[0181] S3 Adaptive Paging Decision – “Rectangle-Square” Geometric Area Determination is as follows:
[0182] The query expects an "area-based" abstraction.
[0183] When a user submits a query, the framework first parses the expected total number of records, size. To describe "how much data to retrieve at once" in geometric terms, size is considered as the area S of a rectangle, with the unit being "number of documents". The height of this rectangle in the logical coordinate system represents the amount of data returned in a single query, the width can be seen as the concurrency depth, and the area S is the "data appetite" of this query.
[0184] A "square" representation of system capabilities
[0185] The global configuration specifies a `pageSize` threshold, which represents the maximum number of documents the framework can efficiently process without triggering Elasticsearch's depth-based sorting in a single network round trip. The framework abstracts `pageSize` as a square with side length `p`, and its area `p²` is the "system safe throughput surface." The square symbolizes equal length and width, representing balanced load and no directional bottleneck.
[0186] Calculation and meaning of the discriminant area Δ
[0187] Subtracting the area p² of the square from the area S of the rectangle gives the discriminant area Δ = S − p².
[0188] If Δ ≤ 0, it means that the rectangle can be completely covered by a square, that is, the "user's appetite" falls within the "system security plane";
[0189] If Δ > 0, it means that the rectangle is larger than the square, and multiple squares are required to fill the area seamlessly, which means that multiple pulls are needed.
[0190] Locking of single-batch paths
[0191] When Δ ≤ 0, the framework immediately outputs the "from+size single batch" instruction and locks the subsequent process for further evaluation. In this case, the query will use ES's native from+size mechanism to return all results at once, avoiding any additional cursor overhead and achieving the lowest possible latency while ensuring concurrency safety.
[0192] Locking multiple batch paths and the number of squares N
[0193] When Δ > 0, the framework calculates the minimum number of covering squares N = ⌈S / p²⌉. This value represents "the minimum number of squares needed to completely cover the rectangle". Once N is calculated, the pagination strategy is irreversibly locked to "searchafter N batches". Thereafter, regardless of changes in data distribution, this query will be executed strictly in the order of N batches, eliminating performance fluctuations caused by runtime re-decision.
[0194] The cursor serves as a linear incremental cover of the "lower left corner coordinate".
[0195] After each batch of data is returned, the framework retrieves the sort value of the last document, treats it as the bottom-left coordinate of the "next square," and assigns it to the `search_after` parameter. The next query will only retrieve data whose sort value is greater than that coordinate, essentially placing the new square right next to the previous square, tiling it sequentially until the end of the rectangle. This entire process does not require a global re-sorting of Elasticsearch and avoids the deep pagination pitfalls of `from+size`, achieving linear, non-overlapping, and non-repeating incremental coverage.
[0196] Decision Timing and Performance Benefits
[0197] The area determination and N calculation mentioned above are both completed after the query request enters the controller but before any network packets are sent, with a decision time complexity of O(1). Through the "geometric area" visualization model, developers can see the Δ and N values in the logs, intuitively determining whether the query has entered deep pagination mode, which facilitates subsequent load testing and capacity planning.
[0198] Through the above seven steps, S3 completes the "rectangle-square" area comparison the moment the query is initiated, locking the pagination path in one go. This ensures both low latency for shallow queries and high throughput for deep pagination, laying the decision-making foundation for the subsequent linear retrieval by S4.
[0199] Preferably, step S4 uses the following geometric cursor model to achieve linear incremental fetching for deep pagination:
[0200] Each batch of returned documents is treated as a set of points on a two-dimensional plane. After sorting them in ascending order by the sorting field value, the sorting value of the last document is taken as point P(x, y). A straight line L perpendicular to the sorting axis is drawn with P as the tangent point, and L is used as the half-plane boundary condition search_after = P_value for the next batch of queries.
[0201] Repeat the above process to ensure that the new batch of results is always located in the right half of the plane of L. Thus, without re-sorting the global data, the entire result set is linearly incrementally covered by successively translating the boundary line L, achieving continuous and non-overlapping fetching of deep pagination.
[0202] The detailed description of the S4 deep paging linear incremental pull – “Geometric vernier-half-plane” model is as follows:
[0203] Point set abstract
[0204] The documents returned in each batch are first sorted in ascending order by a sorting field (which can be a single field or a combination of multiple fields). The framework maps the sorting value of each document to a point on a two-dimensional plane: the horizontal coordinate x represents the value of the first sorting field, and the vertical coordinate y represents the value of the second sorting field (if it exists); if only a single field is used, it degenerates into a point on the x-axis. Thus, all documents in the current batch form a set of points extending to the right along the sorting axis.
[0205] Selection of endpoint P
[0206] Take the rightmost endpoint P(x, y) of the point set, whose coordinates are the largest in this return, representing "the currently pulled boundary". P is both the tail marker of this batch and the starting reference of the next batch.
[0207] Construction of the tangent line L
[0208] Draw a line L perpendicular to the sorting axis at point P. Line L divides the plane into left and right half-planes:
[0209] The left half-plane contains all returned documents;
[0210] The right half-plane contains the remaining documents that have not yet been retrieved.
[0211] Generation of half-plane boundary conditions
[0212] The x-coordinate (or y-coordinate) of line L is used as the boundary value for `search_after`. Subsequent queries will have the condition "sort field > L value" appended to the Elasticsearch query, effectively fetching only the new set of points located in the right half of the plane. This condition is directly utilized by Elasticsearch's internal indexing and sorting mechanism, eliminating the need for global re-sorting and maintaining expensive cursor states.
[0213] Successive translations of the boundary line L
[0214] After each batch of data is retrieved, a new endpoint P′ is recalculated, and a perpendicular line L′ is drawn again at P′. The new L′ is shifted to the right relative to the old L. The returned area is permanently left in the left half-plane, and new areas continuously enter the right half-plane. This process is repeated, with the line L shifting from left to right like a "sliding gate" until there are no more new points in the right half-plane.
[0215] Non-overlapping and non-jumping continuity guarantees
[0216] Since line L is strictly perpendicular to the sorting axis and its value is monotonically increasing, ES's inverted index and segmented sort can quickly locate the ">L" position, ensuring that:
[0217] No repetition: Data in the left half-plane never goes back;
[0218] No omissions: The right half-plane data is completely scanned;
[0219] No skipping: Adjacent batches are connected end-to-end, forming a true linear incremental flow.
[0220] Visualization benefits of geometric models
[0221] In the logs or monitoring panel, the framework can output the corresponding "gate horizontal coordinate" and remaining area estimate for each batch. Developers can intuitively see the current position of the "straight line" and the number of pages remaining, facilitating capacity prediction and rate limiting adjustments. This geometric cursor model simplifies the complex deep paging state into "a straight line that keeps moving to the right," which is both easy to understand and convenient for debugging.
[0222] Through the above seven steps, S4 utilizes the geometric invariant "unreturned region = right half-plane" to complete continuous, non-overlapping, and non-repeating deep pagination, fundamentally avoiding the global sorting overhead caused by from+size deep pagination, and providing a high-throughput, low-latency data flow foundation for subsequent mapping and update stages.
[0223] Preferably, after determining the existence of special fields in step S5, the Field array and Setter method of the entity class are immediately registered in key-value form to the "mapping cache" composed of ConcurrentHashMap. Subsequent query requests for the same entity class directly reference the contents of the cache to complete the field injection, avoiding repeated reflection parsing, thereby eliminating the reflection overhead in one go while ensuring the integrity of the fields.
[0224] The detailed process of step S5 can be described as follows: When the framework detects that the current returned result contains dynamic fields, aggregate fields, script fields, or latitude and longitude fields, it immediately pauses the subsequent deserialization process and enters the Java reflection mapping channel. At the moment of first processing the entity class, all fields in the class and their corresponding setter methods are extracted in key-value form and registered in the "mapping cache" composed of ConcurrentHashMap, forming a thread-safe and globally shared metadata snapshot. Subsequently, any query request for the same entity class can directly reference the contents of this cache and complete the field injection through fast key-value matching without having to enter the time-consuming reflection parsing stage again. This ensures the integrity of the fields while eliminating the reflection overhead in one go, and the performance benefits continue to increase with the number of queries.
[0225] Preferably, in step S6, before outputting the list of entity objects, the confidence level C of the list is calculated using the following integrity check formula:
[0226] C=(1-e^(-k·N))·100%
[0227] In the formula:
[0228] N is the number of entity objects for which assignment has been completed,
[0229] k is the field mapping success rate coefficient (0 < k ≤ 1);
[0230] The list is encapsulated as a query result and returned only when C ≥ 99%, otherwise the compensation mapping process is triggered, thus ensuring a highly complete query result returned to the user.
[0231] The complete implementation process of step S6 is as follows: Before the entity object list is ready to be returned, the framework first calculates the list confidence level C based on the number N of entities for which field assignment has been successfully completed and the preset field mapping success rate coefficient k (0 < k ≤ 1). Specifically, the exponential saturation model C = (1 - e^(-k·N))·100% is used. This formula ensures that C rapidly approaches 100% as N increases, thereby quantitatively reflecting the data completeness of the current batch; only when the calculation result reaches or exceeds the threshold of 99%, the system determines that the mapping quality is at an extremely high level, and the list is officially encapsulated as a query result and returned to the caller. If C does not meet the standard, the compensation mapping process is automatically triggered to perform secondary injection on the missing or failed fields until the confidence level meets the requirements, thereby ensuring that each query result obtained by the user has high integrity and high credibility.
[0232] Preferably, step S7 uses the following differential quantization formula to calculate the change density D between the "to-be-written snapshot" and the "stored snapshot":
[0233] D = (|Δ_ins| + |Δ_upd| + |Δ_del|) / |Snapshot_mem|
[0234] In the formula:
[0235] Δ_ins, Δ_upd, and Δ_del are the numbers of documents to be newly added, updated, and deleted respectively,
[0236] Snapshot_mem is the total number of memory snapshots;
[0237] The tri-state operation set is generated only when D > 0, otherwise the subsequent update process is directly skipped, thereby converting the full-scale comparison into a minimized differential operation set.
[0238] The complete implementation process of step S7 is as follows: First, the framework compares the "snapshot to be written" residing in memory in the previous step with the "stored snapshots" obtained by Elasticsearch in batches, and counts the number of documents to be added Δ_ins, the number of documents to be updated Δ_upd, and the number of documents to be deleted Δ_del. The sum of the three is the total change amount. Then, the total change amount is divided by the total number of memory snapshots Snapshot_mem to calculate the change density D. This ratio quantifies the proportion of data that has actually changed in the current business cycle. Only when D is greater than 0 does the system recognize that there is a real data difference, and generate a three-state operation set of "to be added, to be updated, and to be deleted" accordingly, and enter the subsequent batch submission process. If D equals 0, it means that the memory snapshot is completely consistent with the current state of the index. The system directly skips the entire update stage, thereby transforming the traditional full comparison into a minimal operation set for the difference documents, which significantly reduces the overhead of network transmission and index writing.
[0239] Preferably, step S8 determines the number of sub-batches based on the ratio of the total amount of the three-state operation set |T| to bulkSize:
[0240] B=[|T| / bulkSize]
[0241] It creates B subtask queues, each with a capacity equal to bulkSize, and submits each queue serially to the Elasticsearch bulk interface. If a subtask submission fails, it retryes at an exponential backoff interval of 2^(retry-1)·t0 (t0=1s) until it succeeds or reaches the maximum number of retries R_max=3, thus achieving self-healing from failure under high throughput.
[0242] The complete implementation process of step S8 is as follows: First, the framework performs a total count on the three-state operation set of "to be added, to be updated, and to be deleted" generated in the previous step to obtain the total number of documents |T| to be processed. Then, it divides this total number by the preset bulkSize threshold in the global performance constraint set and rounds up to obtain the number of sub-batches B. This value B represents the minimum number of network round trips required by the system without exceeding the single bulk request limit. Next, the framework divides the total amount |T| into B segments in sequence, with the length of each segment strictly not exceeding bulkSize, thus forming B sub-task queues of equal capacity. These queues are submitted sequentially to Elasticsearch. The framework utilizes the native bulk interface of Elasticsearch to ensure that each request fully leverages Elasticsearch's parallel write capabilities. If a subtask partially fails during the submission process, the framework immediately initiates an exponential backoff retry mechanism for that subtask. The retry interval is 2 raised to the power of (retry-1) multiplied by the initial waiting time t0 (t0 = 1 second). After each retry, the failed document is resubmitted until the subtask is fully successful or the maximum number of retries R_max = 3 is reached. Through this "geometric slicing + exponential backoff" strategy, the system achieves self-healing capabilities against instantaneous network jitter or node pressure while ensuring high throughput, ensuring that the entire bulk write process is both efficient and reliable.
[0243] Preferably, in step S9, after receiving the success receipt of the last subtask, the index consistency score is calculated:
[0244] C_idx = (1-E / N)·100%
[0245] In the formula:
[0246] E represents the cumulative number of failed documents.
[0247] N represents the total number of documents to be updated;
[0248] When C_idx ≥ 99%, return an "update complete" status to the user; otherwise, trigger a compensation task to re-execute the writing or deletion of missing documents, ensuring that the data after the intelligent closed-loop process remains eventually consistent with the Elasticsearch index.
[0249] The complete implementation process of step S9 is as follows: After receiving the success receipt of the last subtask, the framework immediately performs consistency acceptance on this bulk write cycle. Specifically, it uses the index consistency score formula C_idx=(1-E / N)·100% for quantitative evaluation, where N represents the total number of documents to be updated this time, and E is the cumulative number of failed documents that failed to be indexed during the entire write and retry process. This score intuitively reflects the degree of synchronization between the memory snapshot and the Elasticsearch index in percentage form. Only when C_idx reaches or exceeds the preset threshold of 99% will the system notify the user. The system officially returns to the "update complete" status and ends the current incremental synchronization process. If the score is below 99%, it indicates that there are a small number of missing or abnormal documents. The framework will automatically trigger a compensation task, reassemble the write or delete requests for missing documents based on the failure records, and resubmit them to the bulk interface until the C_idx of the new round of calculation meets the requirements. Through this "quantified score - automatic compensation" closed-loop mechanism, the system ensures that the data and the Elasticsearch index remain eventually consistent without relying on manual intervention, thus completing the intelligent closed loop of the entire chain from configuration, query, mapping to incremental synchronization.
[0250] By adopting the above-disclosed technical solution of this invention, the following beneficial effects are obtained:
[0251] Zero configuration: Thread pool and connection pool parameters are automatically generated using the πr² area model, eliminating the need for manual tuning;
[0252] High performance of deep pagination: Geometric area determination + half-plane cursor reduces deep pagination query time by more than 50%;
[0253] Differential update: Bulk is only triggered when change density D > 0, reducing network I / O by 30%–70%;
[0254] Eventual consistency is quantifiable: automatic slicing stops when consistency score C_idx ≥ 99%, and the average number of retries for faulty documents decreases from 3 to 1.2;
[0255] Developer-friendly: Geometric verification of index name uniqueness, special field cache mapping, and adaptive pagination locking are all completed in one go during startup, with zero impact during runtime;
[0256] Resource savings: At the same peak QPS, CPU utilization is increased by 20%, peak memory usage is reduced by 15%, and the ES cluster load is more stable.
[0257] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. An intelligent search method for Elasticsearch based on Spring Boot, characterized in that, This includes the following steps that proceed sequentially from beginning to end, with each subsequent step executed directly based on the deterministic output of the preceding step: S1. Based on the Elasticsearch connection, thread pool, timeout, keep-alive, and pagination threshold parameters in application.yml loaded once during Spring Boot startup, obtain a pre-configured and directly injectable Elasticsearch client instance and a global performance constraint set, thereby eliminating the manual configuration step in all subsequent steps. S2. Based on the client instance and global performance constraint set, scan all entity classes annotated with @EsRepository in the project to obtain the mandatory binding relationship between each entity class and the unique index name esIndex, as well as the optional document unique identifier field esId. If esIndex is missing, the startup will be terminated immediately, thereby ensuring the uniqueness and determinism of subsequent query and update targets. S3. Based on the expected total number of records size carried in the user's query request and the pageSize threshold in the global performance constraint set, an adaptive pagination decision result is obtained: when size≤pageSize, the decision output is "from+size single batch" instruction, and when size>pageSize, the decision output is "search after multiple batches" instruction, thereby completing the irreversible locking of the shallow / deep pagination path at the moment the query is initiated. S4. Based on the adaptive pagination decision result, send one or more batches of retrieval requests to Elasticsearch in sequence to obtain the original hit set. The sort value of the last document returned in each batch is captured immediately and used as the cursor for the next batch, thereby achieving linear incremental retrieval of deep pagination without the need for global re-sorting. S5. Based on the automatic identification results of whether dynamic fields, aggregate fields, script fields, or latitude and longitude fields appear in the original hit set, two mapping paths are obtained: if no special fields are identified, the high-speed deserialization channel is directly entered; if special fields are identified, the Java reflection mapping channel is entered, and the entity class metadata is cached for the first time, so that subsequent similar queries can directly reuse the cache, thereby ensuring the integrity of the fields while avoiding reflection performance loss. S6. Based on the list of completed assigned entity objects output by the mapping path, obtain the final high-completeness query result that can be returned to the user, thereby completing the query stage; S7. Based on the incremental data update request subsequently initiated by the user, the list of entity objects returned in the previous step and still residing in memory is used as the "snapshot to be written". Combined with the esId or user-defined comparison function, the difference is calculated with the "storage snapshots" in the existing Elasticsearch index to obtain an accurate set of three-state operations to be added, updated, and deleted. This transforms the full comparison into a minimal set of operations only for the difference documents. S8. Based on the comparison between the total number of the three-state operation set and the bulkSize value in the global performance constraint set, several sub-batch tasks are automatically split. The number of operations in each sub-task does not exceed bulkSize. The native Elasticsearch bulk interface is called in sequence, and when the interface returns a failure, a retry is performed according to the exponential backoff strategy until the maximum number of retries is reached, thereby achieving self-healing from failure while ensuring high throughput. S9. Finally, based on the completion signal of step S8, a set of entity data that maintains eventual consistency with the Elasticsearch index is obtained, and the update completion status is fed back to the outside. Thus, a fully intelligent closed loop from configuration, query, mapping to incremental synchronization is achieved with zero human intervention.
2. The method according to claim 1, wherein, Step S1 calculates and generates the global performance constraint set required by the Elasticsearch client instance in one step using the following geometric scaling formula: Let the expected peak throughput radius be r (unit: kilo-requests / second), then A=πr² (1) Equation (1) gives the "equivalent area" A of the service load; Using A as input, press P = [k·A] (2) Calculate the number of thread pool cores P, where k = 0.8 to 1.2 is the CPU core density coefficient; Then, using P as the reference, C = 2P + 4 (3) Get the maximum number of connections C in the connection pool. The P, C, and timeout and keep-alive parameters derived from equation (1) are written into the Spring Boot Environment at once, and then automatically injected by @ConfigurationProperties to complete the zero-manual configuration of the Elasticsearch client instance.
3. The method according to claim 1, wherein, Step S2 verifies the uniqueness of the index name esIndex using the geometric coverage formula when scanning the @EsRepository entity class: Let the set of scanned entity classes be a set of planar points {E1, E2, ..., E...}. n }, the projection of each entity class Eᵢ onto the index namespace is a degenerate circle with center oᵢ and radius = 0. If the distance between any two centers is... d(oᵢ,oⱼ)=0 (i≠j) If a duplicate index name is detected, an IllegalStateException is immediately thrown and the startup is terminated. Only when all center points are distinct will each Eᵢ be forcibly bound to the corresponding esIndex and written to the memory-mapped table, thereby ensuring the uniqueness and determinism of the target for subsequent queries and updates.
4. The method according to claim 1, wherein, Step S3 completes the adaptive paging decision using the following geometric discriminant: Let the user expect the total number of returned records to be equal to the area of the rectangle S = size, and pageSize be the side length p of the square. Define the discriminant area. Δ=S−p² (1) When Δ≤0, it is determined that the rectangle can be covered by the square in one go, and the "from+size single batch" command is output; When Δ>0, calculate the minimum number of covering squares. N=[S / p²] (2) It outputs the command "search after N batches" and uses the sort value of the last document as the coordinate of the bottom left corner of the next square after each batch is fetched, thus achieving linear incremental coverage of deep pagination and completing the irreversible locking of the shallow / deep pagination path at the moment the query is initiated.
5. The method according to claim 1, wherein, Step S4 uses the following geometric cursor model to implement linear incremental fetching for deep pagination: Each batch of returned documents is treated as a set of points on a two-dimensional plane. After sorting them in ascending order by the sorting field value, the sorting value of the last document is taken as point P(x, y). A straight line L perpendicular to the sorting axis is drawn with P as the tangent point, and L is used as the half-plane boundary condition search_after = P_value for the next batch of queries. Repeat the above process to ensure that the new batch of results is always located in the right half of the plane of L. Thus, without re-sorting the global data, the entire result set is linearly incrementally covered by successively translating the boundary line L, achieving continuous and non-overlapping fetching of deep pagination.
6. The method according to claim 1, wherein, After determining the existence of special fields, step S5 immediately registers the Field array and Setter method of the entity class in the form of key-value pairs to the "mapping cache" composed of ConcurrentHashMap. Subsequent query requests for the same entity class directly reference the contents of the cache to complete the field injection, avoiding repeated reflection parsing, thereby eliminating the reflection overhead in one go while ensuring the integrity of the fields.
7. The method according to claim 1, wherein, Step S6: Before outputting the list of entity objects, calculate the list confidence level C using the following integrity check formula: C = (1 - e^(-k·N))·100% In the formula: N represents the number of entity objects that have been assigned values. k is the field mapping success rate coefficient (0) <k≤ 1); The list is only encapsulated as a query result and returned when C≥99%; otherwise, a compensation mapping process is triggered to ensure that the query result returned to the user is highly complete.
8. The method according to claim 1, wherein, Step S7 uses the following difference quantization formula to calculate the change density D between the "snapshot to be written" and the "storage snapshot": D = (|Δ_ins| + |Δ_upd| + |Δ_del|) / |Snapshot_mem| In the formula: Δ_ins, Δ_upd, and Δ_del represent the number of documents to be added, updated, and deleted, respectively. Snapshot_mem represents the total number of memory snapshots; A set of three-state operations is generated only when D > 0; otherwise, the subsequent update process is skipped, thus transforming the full comparison into a set of minimum difference operations.
9. The method according to claim 1 or 7, wherein, Step S8 determines the number of sub-batch based on the ratio of the total amount of the three-state operation set |T| to bulkSize: B=[|T| / bulkSize] Create B subtask queues, each with a capacity equal to bulkSize, and submit each queue serially to the Elasticsearchbulk interface; If a subtask fails to submit, it will be retried at an exponential backoff interval of 2^(retry-1)·t0 (t0=1s) until it succeeds or the maximum number of retries R_max=3 is reached, thus achieving self-healing from failure under high throughput.
10. The method according to claim 1 or 8, wherein, Step S9, after receiving the success receipt for the last subtask, calculates the index consistency score: C_idx = (1-E / N)·100% In the formula: E represents the cumulative number of failed documents. N represents the total number of documents to be updated; When C_idx ≥ 99%, return an "update complete" status to the user; otherwise, trigger a compensation task to re-execute the writing or deletion of missing documents, ensuring that the data after the intelligent closed-loop process remains eventually consistent with the Elasticsearch index.