CN-122019685-A - PHP-based query construction method for elastic search object relationship mapping
Abstract
The invention relates to the technical field of databases, in particular to a query construction method of PHP-based elastic search object relation mapping, which comprises the steps of establishing a corresponding index model aiming at a storage object and connecting an elastic search client; the method comprises the steps of establishing an index structure corresponding to a storage object for the index model, extracting object attributes for the storage object, establishing a document index of the elastic search client based on the object attributes and the index structure, and establishing a query statement according to the document index when an external query instruction is received. Aiming at the problem that the query system in the prior art needs to repeatedly establish the query index in the construction process, in the scheme, the index model is introduced and the index structure is established, so that the automatic generation process from the query instruction to the PHP query statement is realized, a new query index is not required to be independently generated for each query process, and the processing efficiency is improved.
Inventors
- SONG JIANSHENG
Assignees
- 上海东方传媒技术有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20251222
Claims (10)
- 1. The PHP-based query construction method of the elastic search object relation mapping is characterized by comprising the following steps: Step S1, establishing a corresponding index model aiming at a storage object and connecting an elastic search client; s2, establishing an index structure corresponding to the storage object for the index model; S3, extracting object attributes from the storage objects, and creating a document index of the elastic search client based on the object attributes and the index structure; and S4, when an external query instruction is received, establishing a query statement according to the document index.
- 2. The query construction method according to claim 1, wherein the step S1 includes: step S11, establishing the index model aiming at the storage object; step S12, abstracting the storage object to define configuration information of the index model relative to the elastic search client; step S13, carrying out interface check on the configuration information so that the index model has an index interface which accords with a specification; And step S14, controlling the index model to be connected with the elastic search client based on the index interface.
- 3. The query building method according to claim 2, wherein in the step S12, the configuration information includes connection configuration, index name definition, field mapping structure, and sharded copy setting.
- 4. The query construction method according to claim 2, wherein the step S2 includes: S21, acquiring configuration information of the index model, and determining an index structure body according to the configuration information; step S22, adding field mapping information to the index structure body to form a first intermediate structure body; Step S23, performing alias extension on the field mapping information in the first intermediate structure to obtain a second intermediate structure; And step S24, performing routing field assignment on the second intermediate structure body to obtain the index structure.
- 5. The query construction method according to claim 1, wherein the step S3 includes: s31, extracting the object attribute from the storage object and filtering to obtain a document field; step S32, adding the document fields to the document index, and then extracting field updating content based on the index structure; and step S33, updating the document index according to the field updating content.
- 6. The query construction method according to claim 1, wherein the step S4 includes: step S41, adding query conditions according to the query instruction, and storing a value query array in a triplet form; step S42, traversing the query array and converting the query array into a standard query format; and S43, generating a query statement according to the standard query format.
- 7. The query construction method according to claim 1, wherein the step S4 further comprises: And step A41, directly setting a native elastomer search query statement as the query statement to output according to the query instruction.
- 8. The query building method of claim 1, further comprising: s5, defining an aggregation configuration for a plurality of query sentences and establishing an aggregation query sentence; the aggregation configuration includes an aggregation name, a child aggregation, and an aggregation parameter.
- 9. The query building method of claim 6, further comprising: and S44, extracting a highlight field from the query instruction, and adding a label to the query statement according to the highlight field.
- 10. A storage medium comprising computer instructions which, when executed by a computer, perform the query building method of any of claims 1-9.
Description
PHP-based query construction method for elastic search object relationship mapping Technical Field The invention relates to the technical field of databases, in particular to a PHP-based query construction method for mapping an elastiscearch object relationship. Background The query of the database refers to a process that a developer designs a specific query sentence based on a specific format by using a development language like PHP, C, etc. to extract data meeting a specific condition from the database. The elastiscearch is a distributed search and analysis engine based on Lucene, and is widely applied to scenes such as full-text search, log analysis, real-time data analysis and the like. For example, patent document with application number of CN202510219400.X discloses a PHP-based pure JSON file data storage query method, device and medium, which comprises the steps of receiving data to be stored and a storage file name, determining whether to split file storage according to user needs, distinguishing date and time as a suffix to ensure storage and query of large data amount data, constructing a JSON format-based data storage structure, writing the tail of the storage file and storing the storage file by a PHP language file operation method, receiving a user query request, traversing an acquisition result set in the storage file according to a user complex query condition, and returning to the user after processing. The data storage mechanism is simple and easy to use, data is stored through the pure JSON file, development and maintenance cost is reduced, and the data storage mechanism is particularly suitable for small-sized application and quick development scenes. The data sub-table function is supported, so that the data storage and retrieval efficiency is improved, the requirement of large-scale data storage is met, and meanwhile, the simplicity of a data storage mode is kept. For another example, the patent document with the application number of CN201410355624.5 discloses a method for quickly searching PHP variable keywords and pushing interested contents, after the method is connected with a database, fuzzy inquiry is carried out on information fields of the database, the information fields including the keywords in the keyword array are returned to the PHP array variable for storage, the search process is only interacted with the database once, and other operations only need to be interacted with the PHP array variable; when the keyword to be queried input by the user is empty, the step of pushing the interested content is carried out according to PHP array variable search, the method and the device reduce the search time of the user, reduce risks, and timely learn about the latest content by pushing the latest update of the data information of the interested content, thereby improving the effectiveness of the information. However, in the practical implementation process, the inventor finds that in the technical scheme, after the elastic search is applied, index configuration and query construction codes are required to be repeatedly written in a plurality of items in the process of constructing the query, and the lack of a uniform abstract layer causes difficult maintenance of the items and low code multiplexing rate. Disclosure of Invention Aiming at the problems in the prior art, a query construction method of PHP-based elastic search object relation mapping is provided. The specific technical scheme is as follows: A query construction method of PHP-based elastic search object relation mapping comprises the following steps: Step S1, establishing a corresponding index model aiming at a storage object and connecting an elastic search client; s2, establishing an index structure corresponding to the storage object for the index model; S3, extracting object attributes from the storage objects, and creating a document index of the elastic search client based on the object attributes and the index structure; step S4, when an external query instruction is received, a query statement is established according to the document index; On the other hand, the step S1 includes: step S11, establishing the index model aiming at the storage object; step S12, abstracting the storage object to define configuration information of the index model relative to the elastic search client; step S13, carrying out interface check on the configuration information so that the index model has an index interface which accords with a specification; And step S14, controlling the index model to be connected with the elastic search client based on the index interface. On the other hand, in the step S12, the configuration information includes a connection configuration, an index name definition, a field mapping structure, and a sharded copy setting. On the other hand, the step S2 includes: S21, acquiring configuration information of the index model, and determining an index structure body according to the configuration informatio