Query construction method for Elasticsearch object relation mapping based on PHP

By establishing an index model and index structure, the automatic generation of Elasticsearch query commands is realized, which solves the problem of repeatedly writing index configurations, improves query processing efficiency and code reusability, reduces development difficulty, and is suitable for query construction in database systems.

CN122019685APending Publication Date: 2026-05-12SHANGHAI MEDIA TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANGHAI MEDIA TECH
Filing Date
2025-12-22
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

When using Elasticsearch, existing technologies require repeatedly writing index configuration and query building code across multiple projects. The lack of a unified abstraction layer makes project maintenance difficult and code reusability low.

Method used

By establishing an index model and introducing an index structure, the system enables the automatic generation of query commands into PHP query statements. This includes configuring the index model, building the index structure, and managing the document index. Utilizing an object-oriented API design and modular architecture, it provides index operation modules, document operation modules, and query building modules, supporting aggregation configuration and highlighted field processing.

Benefits of technology

It improves query processing efficiency, reduces development difficulty and learning cost, enhances code readability and maintainability, increases development efficiency and code reusability, ensures performance advantages, and is suitable for big data scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122019685A_ABST
    Figure CN122019685A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of databases, in particular to a PHP-based Elasticsearch object relation mapping query construction method, which comprises the following steps of: establishing a corresponding index model for a storage object, and connecting an Elasticsearch client; establishing an index structure corresponding to the storage object for the index model; extracting an object attribute from the storage object, and creating a document index of the Elasticsearch client based on the object attribute and the index structure; and when an external query instruction is received, establishing a query statement according to the document index. Aiming at the problem that a query index needs to be repeatedly established in the construction process of a query system in the prior art, in the scheme, the automatic generation process from the query instruction to the PHP query statement is realized by introducing the index model and establishing the index structure, a new query index does not need to be independently generated for each query process, and the processing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database technology, and specifically to a query construction method for Elasticsearch object relational mapping based on PHP. Background Technology

[0002] Database querying refers to the process by which developers design specific query statements using programming languages ​​such as PHP and C, based on a specific format, to extract data from a database that meets specific conditions. Elasticsearch is a distributed search and analytics engine based on Lucene, widely used in scenarios such as full-text search, log analysis, and real-time data analysis.

[0003] For example, patent application CN202510219400.X discloses a method, device, and medium for storing and querying pure JSON files based on PHP. This includes receiving the data to be stored and the file name; determining whether to split the file for storage based on user needs, distinguishing them by date and time suffixes to ensure the storage and querying of large amounts of data; constructing a data storage structure based on JSON format; writing data to the end of the storage file and saving it using PHP file operation methods; receiving user query requests; traversing the storage file to obtain the result set based on the user's complex query conditions; processing the result set and returning it to the user. This provides a simple and easy-to-use data storage mechanism, storing data through pure JSON files, reducing development and maintenance costs, and is especially suitable for small applications and rapid development scenarios. It supports data partitioning to improve data storage and retrieval efficiency, adapting to the needs of large-scale data storage while maintaining the simplicity of the data storage method.

[0004] For example, patent application CN201410355624.5 discloses a method for quickly searching PHP variable keywords and pushing content of interest. This invention connects to a database, performs a fuzzy search on the database information fields, and returns information fields including keywords from the keyword array to a PHP array variable for storage. The search process only interacts with the database once; other operations only require interaction with the PHP array variable. When the user's input keyword is empty, the method pushes content of interest based on the PHP array variable search. This invention reduces user search time and risk; it pushes the latest updates of content of interest, allowing users to stay informed and improving the timeliness of information.

[0005] However, in actual implementation, the inventors found that in this type of technical solution, when Elasticsearch is applied, the index configuration and query building code need to be repeatedly written in multiple projects during the query building process. The lack of a unified abstraction layer makes project maintenance difficult and code reuse rate low. Summary of the Invention

[0006] To address the aforementioned problems in existing technologies, a query construction method based on PHP for Elasticsearch object relational mapping is provided.

[0007] The specific technical solution is as follows: A PHP-based method for constructing Elasticsearch object-relational mapping queries, including: Step S1: Create a corresponding index model for the stored object and connect to the Elasticsearch client; Step S2: Establish an index structure corresponding to the stored object for the index model; Step S3: Extract object attributes from the stored object, and create a document index for the Elasticsearch client based on the object attributes and the index structure; Step S4: When an external query instruction is received, a query statement is created based on the document index; On the other hand, step S1 includes: Step S11: Establish the index model for the stored object; Step S12: Abstract the storage object and define the configuration information of the index model relative to the Elasticsearch client; Step S13: Perform an interface check on the configuration information to ensure that the index model has a compliant index interface; Step S14: Control the index model to connect to the Elasticsearch client based on the index interface.

[0008] On the other hand, in step S12, the configuration information includes connection configuration, index name definition, field mapping structure, and shard replica settings.

[0009] On the other hand, step S2 includes: Step S21: Obtain the configuration information of the index model, and determine the index structure according to the configuration information; Step S22: Add field mapping information to the index structure to form a first intermediate structure; Step S23: Perform alias expansion on the field mapping information in the first intermediate structure to obtain the second intermediate structure; Step S24: Specify the routing field in the second intermediate structure to obtain the index structure.

[0010] On the other hand, step S3 includes: Step S31: Extract the object attributes from the stored object and filter them to obtain document fields; Step S32: Add the document field to the document index, and then extract the field update content based on the index structure; Step S33: Update the document index according to the updated content of the field.

[0011] On the other hand, step S4 includes: Step S41: Add query conditions according to the query instruction, and store the value query array in the form of triples; Step S42 involves traversing the query array and converting it into a standard query format; Step S43: Generate a query statement according to the standard query format.

[0012] On the other hand, step S4 also includes: Step A41: Directly set the native Elasticsearch query statement as the output of the query statement according to the query instruction.

[0013] On the other hand, it also includes: Step S5: Define aggregation configurations for multiple query statements and create aggregate query statements; The aggregation configuration includes the aggregation name, sub-aggregates, and aggregation parameters.

[0014] On the other hand, it also includes: Step S44: Extract the highlighted fields from the query instruction and add tags to the query statement based on the highlighted fields.

[0015] A storage medium includes computer instructions that, when executed by a computer, perform the query construction method described above.

[0016] The above technical solution has the following advantages or beneficial effects: To address the issue that existing query systems require repeated creation of query indexes during the construction process, this solution introduces an index model and establishes an index structure, thereby enabling the automatic generation of PHP query statements from query commands. This eliminates the need to generate new query indexes for each query, thus improving processing efficiency. Attached Figure Description

[0017] Embodiments of the invention will be described more fully with reference to the accompanying drawings. However, the drawings are for illustration and explanation only and do not constitute a limitation on the scope of the invention.

[0018] Figure 1 This is an overall schematic diagram of an embodiment of the present invention; Figure 2 This is a schematic diagram of step S1 in an embodiment of the present invention; Figure 3 This is a schematic diagram of step S2 in an embodiment of the present invention; Figure 4 This is a schematic diagram of step S3 in an embodiment of the present invention; Figure 5 This is a schematic diagram of step S4 in an embodiment of the present invention; Figure 6 This is a schematic diagram of step S5 in an embodiment of the present invention; Figure 7 This is a schematic diagram of step S44 in an embodiment of the present invention. Detailed Implementation

[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0020] It should be noted that, unless otherwise specified, the embodiments and features described in the present invention can be combined with each other.

[0021] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, but this is not intended to limit the scope of the invention.

[0022] This invention includes: A PHP-based method for constructing Elasticsearch object-relational mapping queries, such as... Figure 1 As shown, it includes: Step S1: Create a corresponding index model for the stored object and connect to the Elasticsearch client; Step S2: Establish an index structure corresponding to the stored object for the index model; Step S3: Extract object attributes from the stored object and create a document index for the Elasticsearch client based on the object attributes and the index structure; Step S4: When an external query instruction is received, a query statement is created based on the document index; Specifically, addressing the issue that existing query systems require repeated creation of query indexes during the construction process, this solution introduces an index model and establishes an index structure, thereby enabling the automatic generation of PHP query statements from query commands. This eliminates the need to generate new query indexes for each query process, thus improving processing efficiency.

[0023] Specifically, the above query method is primarily configured as a software implementation in computer systems, particularly database systems, to build an index model for stored objects and connect to the Elasticsearch client on the development side. Users input specific query commands into the system through the Elasticsearch client, which then uses a pre-recorded document index to find the corresponding index structure, thus automating the query statement generation process.

[0024] This involves creating a corresponding index model for the stored object and connecting it to the Elasticsearch client.

[0025] The index model implements abstract methods such as config(), indexName(), properties(), and settings() by inheriting the BaseConstruct abstract class.

[0026] The `config` method configures Elasticsearch connection parameters, including host address, port number, protocol type, and number of retries. The `indexName` method defines the index name and verifies its validity using the `checkIndexName` method of `ClientTrait`. The properties method defines the index field mapping structure, including field type, whether to create an index, and analyzer settings; The settings method configures the number of index shards and replicas.

[0027] The above process creates an index model. The basic structure of the index model is defined by the abstract class `BaseConstruct`, and subclasses are forced to implement abstract methods such as `config()`, `indexName()`, `properties()`, and `settings()` to ensure that the index model contains core information such as connection configuration, index names, field mappings, and sharding settings. The `IndexBaseInterface` interface standardizes the standard method signatures for index operations. The `ClientTrait` attribute validates the validity of the index name using regular expressions and provides singleton connection management for the Elasticsearch client, subsequently establishing an association with the Elasticsearch client.

[0028] For the newly added index model, the Index class is used to manage the entire lifecycle of the index. The Index class incorporates features from QueryTrait and QueryBuildTrait. The createIndex method automatically builds an index structure that includes sharding settings and field mappings based on the index model's configuration information. The updateIndexMapping method dynamically expands the field mappings. The createAlias ​​and deleteAlias ​​methods automate the management of index aliases. The batchInsert method constructs a bulk API request body to achieve high-performance batch document operations.

[0029] Specifically, the `init` static method of the `BaseConstruct` abstract class is called to create an `Index` instance. This method internally instantiates a user-defined index model class. The `createIndex` method of the `Index` class is then executed to create the index. This method automatically constructs the index structure, including sharding settings and field mappings, based on the configuration information returned by the index model's `settings()` and `properties()` methods. When the index structure needs modification, the `updateIndexMapping` method is called to update the field mappings. This method uses the `buildProperties()` method to obtain field mapping information and dynamically expands the fields. The `createAlias` method is used to create aliases for the index. This method uses the index model's `getAlias()` method to obtain the alias configuration, enabling automated management of index aliases. Finally, the `delIndex` method is used to delete the index when necessary; this operation permanently deletes the index and all its data.

[0030] The above process is used to establish an index structure corresponding to the stored object.

[0031] For the newly generated storage structure, by maintaining the document index, the Elasticsearch client can find the corresponding information in the index structure according to the query command, thereby converting the query command into a query statement that actually matches the database.

[0032] Document manipulation is achieved through the following technical solutions: An Index instance is created using the `init` method of the index model. The `__set()` magic method of the Document class sets the document field values ​​and stores the attributes in the `__magicParams` private property. The system automatically verifies whether the fields are defined in the index mapping. The `insert` method of the Index class inserts the document into Elasticsearch. If the index model defines a primary key field, the specified ID is used; otherwise, a new ID is automatically generated. The `updateDoc` method of the Document class iterates through the list of fields defined in the index model to construct a request body containing the document's update content, thus performing a partial document update. The `delDoc` method of the Document class constructs a deletion request body to perform the document deletion operation.

[0033] For the batch-generated index structures, the following methods can also be used for processing: Create an Index instance and prepare an array of document data, with each element containing a complete document field. Call the `batchInsert` method of the Index class to perform a batch insert. This method achieves high-performance batch operations by iterating through the document array to construct the bulk API request body, and supports specifying routing fields to optimize data distribution.

[0034] Finally, when a query command is received from the user, the query triple is constructed based on the document index to perform the query, including: Create an Index instance as the starting point for the query. Use the `must` method of the `QueryBuildTrait` attribute to add mandatory matching conditions, supporting query types such as `match`, `term`, and `range`. Optionally, use the `page` method of the `QueryTrait` attribute to set pagination parameters, including page number and number of items per page. Call the `search` method of the Index class to execute the query. This method constructs the query request body using the `buildQueryBody` method and returns an array of Document objects or the original data.

[0035] In one embodiment, such as Figure 2 As shown, step S1 includes: Step S11: Establish an index model for the stored object; Step S12: Abstract the storage object and define the index model's configuration information relative to the Elasticsearch client; Step S13: Perform an interface check on the configuration information to ensure that the index model has a compliant index interface; Step S14: Control the index model to connect to the Elasticsearch client based on the index interface.

[0036] Specifically, in order to build the index model, in this embodiment, an index model is first generated for the storage object that needs to be indexed, and then the storage object is abstracted to define the configuration information of the index model relative to the Elasticsearch client.

[0037] Configuration information includes connection configuration, index name definition, field mapping structure, and shard replica settings.

[0038] The specific configuration process includes: The BaseConstruct abstract class defines the config(), indexName(), properties(), and settings() abstract methods to force the index model class to implement Elasticsearch connection configuration, index name definition, field mapping structure, and shard replica settings. It also implements singleton connection management for the Elasticsearch client through the getClient() method.

[0039] The above method is used to input configuration information.

[0040] Subsequently, to enable connections to clients, the IndexBaseInterface interface specifies the method signatures for basic index operations. Based on this interface definition, interface checks are performed on configuration information to ensure that different index model classes have consistent interface specifications.

[0041] Finally, the ClientTrait feature validates the index name's validity using the `preg_match_all` regular expression, checking if the name is all lowercase, contains special characters, and contains spaces. Once all checks pass, a connection is established between the index model and the client.

[0042] In one embodiment, such as Figure 3 As shown, step S2 includes: Step S21: Obtain the configuration information of the index model and determine the index structure according to the configuration information; Step S22: Add field mapping information to the index structure to form the first intermediate structure; Step S23: Perform aliasing expansion on the field mapping information in the first intermediate structure to obtain the second intermediate structure; Step S24: Specify the routing field in the second intermediate structure to obtain the index structure.

[0043] Specifically, to build the index structure based on the index model, this embodiment uses the Index class to implement index operations by incorporating the QueryTrait and QueryBuildTrait features: The createIndex method automatically constructs an index structure that includes sharding settings and field mappings based on the configuration information returned by the index model's settings() and properties() methods. The `updateIndexMapping` method obtains field mapping information through the `buildProperties()` method, enabling dynamic expansion of index fields. The createAlias ​​and deleteAlias ​​methods retrieve alias configurations through the getAlias() method of the index model, enabling automated management of index aliases; The batchInsert method constructs a bulk API request body by iterating through an array of documents and supports specifying routing fields to optimize data distribution.

[0044] In practical applications, the `init` static method of the `BaseConstruct` abstract class is called to create an `Index` instance. This method internally instantiates a user-defined index model class. The `createIndex` method of the `Index` class is then executed to create the index. This method automatically constructs the index structure, including sharding settings and field mappings, based on the configuration information returned by the `settings()` and `properties()` methods of the index model. When the index structure needs to be modified, the `updateIndexMapping` method is called to update the field mappings. This method uses the `buildProperties()` method to obtain field mapping information and dynamically expands the fields. The `createAlias` method is used to create aliases for the index. This method uses the `getAlias()` method of the index model to obtain the alias configuration, enabling automated management of index aliases. When necessary, the `delIndex` method is used to delete the index, which permanently deletes the index and all its data.

[0045] In one embodiment, such as Figure 4 As shown, step S3 includes: Step S31: Extract object attributes from the stored object and filter them to obtain document fields; Step S32: Add a document field to the document index, and then extract the updated content of the field based on the index structure; Step S33: Update the document index based on the updated field content.

[0046] Specifically, indexed documents are represented by the Document class as individual document objects, and the PHP magic methods __get() and __set() are used to dynamically access document fields. The __set() method stores fields whose attribute names do not begin with an underscore into the private __magicParams property, thus filtering specific document fields to retrieve the relevant document fields.

[0047] The __get() method retrieves the field values ​​from the __magicParams private property, and then combines them with the updateDoc() method to construct the document update request body by traversing the list of fields defined in the index model. This obtains the document field update content, and the document index is updated based on the field update content to obtain the complete document index.

[0048] In one embodiment, such as Figure 5 As shown, step S4 includes: Step S41: Add query conditions according to the query instruction, and store the query array in the form of triples; Step S42: Traverse the query array and convert it into a standard query format; Step S43: Generate a query statement according to the standard query format.

[0049] Specifically, in this solution, the received query command is transformed by constructing triples. First, the query conditions are stored using a triple [operator, field, value] data structure. These conditions are then grouped by query type (must, should, must_not, filter) and stored in the private property `$__queryWhere`. Query conditions are added using a chained call method via the `must()`, `should()`, `mustNot()`, and `filter()` methods.

[0050] Subsequently, for the query array, the query conditions in $__queryWhere are traversed using the array_map function, and the triples are converted into the standard Elasticsearch query format. Based on the query pattern returned by the getQueryPattern() method, the corresponding query type is wrapped around the query statement, supporting query patterns such as bool, nested, has_child, and has_parent. The queryRaw() method supports direct injection of native Elasticsearch query statements.

[0051] As an optional implementation, for complex Boolean queries, the `must` method of the `QueryBuildTrait` attribute can be used to add mandatory conditions that affect relevance scores; the `should` method can be used to add optional matching conditions that improve scores when met; the `filter` method can be used to add filtering conditions that do not affect scores but improve query performance; and the `mustNot` method can be used to add exclusion conditions that documents cannot match these conditions. The `search` method of the `Index` class is then executed to retrieve query results that satisfy all conditions.

[0052] When a query command contains nested queries, the corresponding query mode and parameters can be set through the nested(), has_child(), and has_parent() methods, additional parameters for specific query types can be added through the queryExtra() method, and specific query conditions can be added through the query() method to construct complex nested queries.

[0053] Specifically, this involves: creating a separate Query object to construct subquery conditions; adding query conditions for nested fields within the subquery; converting the subquery into a query statement structure by calling the `buildQuery` method of the `QueryBuildTrait` attribute; setting the query mode to 'nested' using the `nested` method in the main query; specifying the nested field path by adding the `path` parameter through the `queryExtra` method; and adding query conditions for nested fields through the `query` method. Finally, executing the `search` method of the `Index` class to retrieve documents matching the nested conditions.

[0054] In one embodiment, step S4 further includes: Step A41: Directly set the native Elasticsearch query statement as the query output according to the query command.

[0055] Specifically, in some embodiments, the queryRaw() method can be used to directly set the native Elasticsearch query statement according to the query instruction, skipping the triple conversion process and directly returning the native query statement as the query body.

[0056] In one embodiment, such as Figure 6 As shown, it also includes: Step S5: Define aggregation configurations for multiple query statements and create aggregate query statements; Aggregate configuration includes aggregate name, sub-aggregates, and aggregate parameters.

[0057] Specifically, for aggregate query needs, select the corresponding aggregate class based on the required aggregate type, such as TermsAggregation for grouped statistics. Create an aggregate instance using the `init` static method of the BaseAggregation abstract class, specifying the aggregate name and applicable fields. Set aggregate parameters, such as the limit on the number of returned buckets, using the `setParams` method. For nested aggregates, create child aggregate instances and add them to the parent aggregate using the `addAggregation` method. Call the `buildAgg` method of BaseAggregation to construct the aggregate query structure. Add the aggregate to the main query using the `addAggregation` method of the Index class. Execute the `getAggregations` method of the Index class to retrieve the aggregate results, returning statistical data organized by aggregate name.

[0058] In one embodiment, such as Figure 7 As shown, it also includes: Step S44: Extract the highlighted fields from the query command and add tags to the query statement based on the highlighted fields.

[0059] Specifically, for content that requires highlighting query fields after being returned to the front end, a highlight configuration instance is created using the `init` method of the `Highlight` class after receiving the query command. The fields to be highlighted are specified using the `field` method, and multiple fields can be added via multiple calls. The `preTags` method sets the prefix tags for the highlighted content, typically HTML tags. The `postTags` method sets the suffix tags for the highlighted content, used in conjunction with the prefix tags. The `buildHighlight` method of the `Highlight` class is called to generate the highlight configuration structure. The highlight configuration is applied using the `highlight` method of the `Index` class in the main query. The `asArray` mode is set to retrieve the raw results containing the highlighted information. The `search` method of the `Index` class is executed, and the returned results include the `highlight` field displaying the highlighted content.

[0060] As an optional implementation method, cursor queries can be implemented using the following technical solutions for queries involving large amounts of data: The basic query conditions are established to set the range of data to be processed. The `asArray` method of the `QueryTrait` attribute is used to set the return format as an array for easier data processing. The `limit` method is used to set the amount of data to be processed in each batch, balancing memory usage and network transmission. The `scroll` method of the `Index` class is called to start the cursor and specify the cursor's validity period. The system returns a generator object supporting foreach iteration. During iteration, a batch of data is retrieved and processed in each iteration. Internally, the cursor state is automatically managed, including the passing and updating of `scroll_id`. When there is no more data, the cursor automatically closes and the iteration ends.

[0061] As an optional implementation method, index reconstruction is achieved through the following technical solutions: Create an Index instance to ensure the new index configuration is updated, specifying the name of the old index to be rebuilt. Call the `reIndex` method of the Index class to start the rebuild task, setting it to asynchronous mode to handle large amounts of data. The system first creates a new index based on the current model configuration. Start a data migration task to copy data from the old index to the new index. Obtain the task ID for subsequent status monitoring. Use a polling mechanism to periodically check the task execution status. Query task details, including completion status and processing progress, using the `tasks` method of the Index class. After the task is completed, rebind the index alias using the `rebuildAlias` method of the Index class. Delete the alias binding of the old index and point the alias to the new index for a smooth switch.

[0062] A storage medium includes computer instructions that, when executed by a computer, perform the query construction method described above.

[0063] As can be seen from the above embodiments, the technical solution of the present invention solves the problems existing in the background art through the following technical effects: 1. Technical benefits of reduced learning costs: Through object-oriented API design and modular architecture, developers can build complex queries without needing in-depth knowledge of the Elasticsearch Query DSL. The abstract base class module enforces the implementation of core configuration methods, the index operation module provides full lifecycle management, the document operation module implements dynamic attribute access, the query building module uses a triple data structure and chained calls, and the feature extension module supports advanced functions. The clear responsibilities of each module lower the technical learning threshold.

[0064] 2. Technical benefits in improving development efficiency: The chained query style makes query construction more natural and intuitive; the array_map function automatically converts triples into the Elasticsearch standard query format, significantly reducing boilerplate code; the trait mechanism enables code reuse; modular design facilitates feature expansion; and unified error handling and exception management improve code quality.

[0065] 3. Enhanced type safety: Define Elasticsearch query operators, field types, and analyzer configuration items through constant classes such as QueryConstants, TypeConstants, and AnalyzerConstants. Use constant references instead of string literals to avoid spelling errors and provide IDE intelligent suggestions.

[0066] 4. Technical benefits of improved code readability: Object-oriented design hides the complexity of Elasticsearch, and modular architecture makes the code structure clear, with clear responsibilities for each module, making it easy to understand and maintain, and facilitating collaborative development within a team.

[0067] 5. Technical advantages to ensure performance: Supports batch operations and cursor queries, suitable for big data scenarios, and provides connection pools and retry mechanisms to ensure service stability.

[0068] This invention, through reasonable architecture design and ingenious implementation, successfully encapsulates complex Elasticsearch operations into a simple and easy-to-use PHP API, providing PHP developers with a powerful and easy-to-use Elasticsearch ORM solution.

[0069] The above are merely preferred embodiments of the present invention and are not intended to limit the implementation methods and protection scope of the present invention. Those skilled in the art should recognize that any equivalent substitutions and obvious changes made based on the description and illustrations of the present invention should be included within the protection scope of the present invention.

Claims

1. A query construction method based on PHP using Elasticsearch object-relational mapping, characterized in that, include: Step S1: Create a corresponding index model for the stored object and connect to the Elasticsearch client; Step S2: Establish an index structure corresponding to the stored object for the index model; Step S3: Extract object attributes from the stored object, and create a document index for the Elasticsearch client based on the object attributes and the index structure; Step S4: When an external query instruction is received, a query statement is created based on the document index.

2. The query construction method according to claim 1, characterized in that, Step S1 includes: Step S11: Establish the index model for the stored object; Step S12: Abstract the storage object and define the configuration information of the index model relative to the Elasticsearch client; Step S13: Perform an interface check on the configuration information to ensure that the index model has a compliant index interface; Step S14: Control the index model to connect to the Elasticsearch client based on the index interface.

3. The query construction method according to claim 2, characterized in that, In step S12, the configuration information includes connection configuration, index name definition, field mapping structure, and shard replica settings.

4. The query construction method according to claim 2, characterized in that, Step S2 includes: Step S21: Obtain the configuration information of the index model, and determine the index structure according to the configuration information; Step S22: Add field mapping information to the index structure to form a first intermediate structure; Step S23: Perform alias expansion on the field mapping information in the first intermediate structure to obtain the second intermediate structure; Step S24: Specify the routing field in the second intermediate structure to obtain the index structure.

5. The query construction method according to claim 1, characterized in that, Step S3 includes: Step S31: Extract the object attributes from the stored object and filter them to obtain document fields; Step S32: Add the document field to the document index, and then extract the field update content based on the index structure; Step S33: Update the document index according to the updated content of the field.

6. The query construction method according to claim 1, characterized in that, Step S4 includes: Step S41: Add query conditions according to the query instruction, and store the value query array in the form of triples; Step S42 involves traversing the query array and converting it into a standard query format; Step S43: Generate a query statement according to the standard query format.

7. The query construction method according to claim 1, characterized in that, Step S4 also includes: Step A41: Directly set the native Elasticsearch query statement as the output of the query statement according to the query instruction.

8. The query construction method according to claim 1, characterized in that, Also includes: Step S5: Define aggregation configurations for multiple query statements and create aggregate query statements; The aggregation configuration includes the aggregation name, sub-aggregates, and aggregation parameters.

9. The query construction method according to claim 6, characterized in that, Also includes: Step S44: Extract the highlighted fields from the query instruction and add tags to the query statement based on the highlighted fields.

10. A storage medium comprising computer instructions, characterized in that, When the computer executes the computer instructions, it performs the query construction method as described in any one of claims 1-9.