CN114676133A - Index creating method, device, equipment and storage medium - Google Patents
Index creating method, device, equipment and storage medium Download PDFInfo
- Publication number
- CN114676133A CN114676133A CN202210259724.2A CN202210259724A CN114676133A CN 114676133 A CN114676133 A CN 114676133A CN 202210259724 A CN202210259724 A CN 202210259724A CN 114676133 A CN114676133 A CN 114676133A
- Authority
- CN
- China
- Prior art keywords
- index
- annotation
- target entity
- data
- entity class
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 48
- 238000005096 rolling process Methods 0.000 claims description 61
- 238000013075 data extraction Methods 0.000 claims description 4
- 238000013507 mapping Methods 0.000 description 13
- 230000008569 process Effects 0.000 description 6
- 238000004891 communication Methods 0.000 description 5
- 238000010586 diagram Methods 0.000 description 4
- 238000012545 processing Methods 0.000 description 4
- 238000006243 chemical reaction Methods 0.000 description 3
- 230000006870 function Effects 0.000 description 3
- 230000002159 abnormal effect Effects 0.000 description 2
- 239000008186 active pharmaceutical agent Substances 0.000 description 2
- 230000018109 developmental process Effects 0.000 description 2
- 230000000694 effects Effects 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000012423 maintenance Methods 0.000 description 2
- 230000004931 aggregating effect Effects 0.000 description 1
- 230000032683 aging Effects 0.000 description 1
- 230000008878 coupling Effects 0.000 description 1
- 238000010168 coupling process Methods 0.000 description 1
- 238000005859 coupling reaction Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000011835 investigation Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000011218 segmentation Effects 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2228—Indexing structures
- G06F16/2272—Management thereof
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention belongs to the technical field of computers, and discloses an index creating method, an index creating device, index creating equipment and a storage medium. The method comprises the steps of scanning entity classes marked with preset type annotations in target codes to obtain target entity classes; reading code annotation data from the target entity class; generating an index creation message according to the code annotation data; and calling a preset index creation interface through the index creation message to create a database index corresponding to the target entity class. The target code can be automatically scanned, the index creation message is automatically generated according to the code annotation data in all the entity classes marked with the annotations of the preset types, and then the corresponding database index is created through the index creation message calling the preset creation interface, so that developers do not need to pay attention to the calling of a complicated official interface, the index can be automatically generated only by configuring simple annotations, the workload of the developers is greatly reduced, and the database index is simpler and more convenient to maintain.
Description
Technical Field
The present invention relates to the field of computer technologies, and in particular, to an index creating method, apparatus, device, and storage medium.
Background
With the development of the internet, document-oriented databases are also widely used, for example: an elastic search (ES for short) is a json format document in a document-oriented database. An index (index) in a document-oriented database corresponds to a database in a relational database, a type (type) corresponds to a data table in the relational database, documents (documents) correspond to rows in a data table of the relational database, fields (fields) correspond to columns in a data table of the relational database, and an index structure (mapping) corresponds to a table structure of a data table in the relational database, and specifically describes the attributes of each field in the index.
Official authorities facing document type databases generally provide APIs (such as restful API or java API) to realize interaction between a server and a user, but the APIs provided by official authorities are very complex and cumbersome, the learning cost of developers is high, and the developers are very prone to make mistakes due to the complexity in the using process, so that the developers need to consume a lot of time and energy when maintaining indexes facing the document type databases, and the maintenance cost is very high.
The above is only for the purpose of assisting understanding of the technical solution of the present invention, and does not represent an admission that the above is the prior art.
Disclosure of Invention
The invention mainly aims to provide an index creating method, an index creating device, index creating equipment and a storage medium, and aims to solve the technical problem that in the prior art, the maintenance cost is high when an index facing a document type database is maintained.
In order to achieve the above object, the present invention provides an index creating method, including the steps of:
scanning an entity class marked with a preset type annotation in a target code to obtain a target entity class;
reading code annotation data from the target entity class;
generating an index creation message according to the code annotation data;
and calling a preset index creation interface through the index creation message to create a database index corresponding to the target entity class.
Optionally, the step of generating an index according to the code annotation data to create a packet includes:
determining an index configuration annotation and an index structure annotation solution set according to the code annotation data;
generating index configuration data according to the index configuration annotation, and generating field configuration data according to the index structure annotation set;
and combining the index configuration data and the field configuration data in a preset format to obtain an index creation message.
Optionally, the step of generating field configuration data according to the index structure solution set includes:
traversing the index structure annotation set, and taking the traversed index structure annotation as a current structure annotation;
extracting annotation configuration parameters from the current structure annotation, and acquiring an entity field corresponding to the current structure annotation to acquire a target entity field;
generating configuration data corresponding to the target entity type field according to the annotation configuration parameters;
and at the end of traversal, combining the obtained configuration data into field configuration data.
Optionally, the step of generating configuration data corresponding to the target entity class field according to the annotation configuration parameter includes:
determining whether the data type of the target entity type field is a nested object type or not according to the annotation configuration parameters;
if yes, acquiring an entity class corresponding to the target entity class field, and acquiring a nested entity class;
and generating configuration data corresponding to the target entity class field according to the field information in the nested entity class.
Optionally, the step of generating configuration data corresponding to the target entity class field according to the annotation configuration parameter includes:
Generating field type data corresponding to the target entity type field according to the annotation configuration parameters;
determining whether the target entity class field supports efficient search prompt according to the annotation configuration parameters;
if the target entity type field supports efficient search prompt, efficient search configuration data is generated according to the annotation configuration parameters;
and combining the field type data and the efficient search configuration data into configuration data corresponding to the target entity type field.
Optionally, after the step of reading the code annotation data from the target entity class, the method further includes:
determining whether alias setting is started for the target entity class according to the code annotation data;
if so, determining the alias to be written and the index name to be set according to the code annotation data;
detecting whether a database index corresponding to the index name to be set exists or not;
if the database index corresponding to the index name to be set exists, generating an alias creating message according to the alias to be written and the index name to be set;
and calling a preset alias creating interface through the alias creating message, and setting the alias of the database index corresponding to the index name to be set as the alias to be written.
Optionally, before the step of calling a preset index creation interface through the index creation packet to create the database index corresponding to the target entity class, the method further includes:
determining whether the target entity class starts rolling index setting or not according to the code annotation data;
if the rolling index setting is started, determining a rolling index generation rule according to the code annotation data;
extracting an index name to be created from the index creating message to obtain an alias to be set;
generating a rolling index name according to the rolling index generation rule;
updating the index creation message according to the alias to be set and the rolling index name to obtain a rolling index creation message;
correspondingly, the step of calling a preset index creation interface through the index creation packet to create the database index corresponding to the target entity class includes:
and calling a preset index creation interface through the rolling index creation message to create a database index corresponding to the target entity class.
In addition, to achieve the above object, the present invention further provides an index creating apparatus, including the following modules:
The code scanning module is used for scanning the entity class marked with the preset type annotation in the target code to obtain a target entity class;
the data extraction module is used for reading code annotation data from the target entity class;
the message generating module is used for generating an index creation message according to the code annotation data;
and the index creating module is used for calling a preset index creating interface through the index creating message so as to create the database index corresponding to the target entity class.
In addition, to achieve the above object, the present invention further provides an index creating apparatus, including: a processor, a memory and an index creation program stored on the memory and executable on the processor, the index creation program when executed by the processor implementing the steps of the index creation method as described above.
In addition, to achieve the above object, the present invention also provides a computer readable storage medium, on which an index creating program is stored, the index creating program implementing the steps of the index creating method as described above when executed.
The method comprises the steps of scanning entity classes marked with preset type annotations in target codes to obtain target entity classes; reading code annotation data from the target entity class; generating an index creation message according to the code annotation data; and calling a preset index creation interface through the index creation message to create a database index corresponding to the target entity class. The target code can be automatically scanned, the index creation message is automatically generated according to the code annotation data in all the entity classes marked with the annotations of the preset types, and then the corresponding database index is created through the index creation message calling the preset creation interface, so that developers do not need to pay attention to the calling of a complicated official interface, the index can be automatically generated only by configuring simple annotations, the workload of the developers is greatly reduced, and the database index is simpler and more convenient to maintain.
Drawings
Fig. 1 is a schematic structural diagram of an electronic device in a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a first embodiment of an index creating method according to the present invention;
FIG. 3 is a flowchart illustrating a second embodiment of an index creating method according to the present invention;
fig. 4 is a block diagram showing the structure of a first embodiment of the index creating apparatus according to the present invention.
The implementation, functional features and advantages of the present invention will be further described with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a schematic structural diagram of an index creating device of a hardware operating environment according to an embodiment of the present invention.
As shown in fig. 1, the electronic device may include: a processor 1001, such as a Central Processing Unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a Wireless interface (e.g., a Wireless-Fidelity (WI-FI) interface). The Memory 1005 may be a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as a disk Memory. The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the configuration shown in fig. 1 does not constitute a limitation of the electronic device, and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a storage medium, may include therein an operating system, a network communication module, a user interface module, and an index creation program.
In the electronic device shown in fig. 1, the network interface 1004 is mainly used for data communication with a network server; the user interface 1003 is mainly used for data interaction with a user; the processor 1001 and the memory 1005 in the electronic device of the present invention may be provided in an index creating device, and the electronic device calls the index creating program stored in the memory 1005 through the processor 1001 and executes the index creating method provided by the embodiment of the present invention.
An embodiment of the present invention provides an index creating method, and referring to fig. 2, fig. 2 is a flowchart illustrating a first embodiment of an index creating method according to the present invention.
In this embodiment, the index creating method includes the following steps:
step S10: and scanning the entity class marked with the preset type annotation in the target code to obtain the target entity class.
It should be noted that the execution subject of this embodiment may be the index creating device, and the index creating device may be an electronic device such as a personal computer, a server, and the like, or may also be other devices that can achieve the same or similar functions. Since the document-oriented database has many types, and the elastic search (ES for short) is a very typical document-oriented database, in this embodiment and the following embodiments, the index creation method of the present invention is described by taking the ES database as an example.
It should be noted that, since the ES database is taken as an example for description, the preset type annotation in this embodiment is preset for the ES database, for example: the annotation "@ ESMetaData" is annotated as a preset type. The object code may be a user-specified code, such as: when a user starts a certain software project, the code contained in the software project is used as the target code.
In actual use, when the entity class is marked with the preset type annotation, the annotation is generally set above the class name of the entity class, so that the entity class marked with the preset type annotation in the scanning target code can be the scanning target code, and the entity class marked with the preset type annotation in the class name in the target code is used as the target entity class.
In a specific implementation, when scanning the target code, the target code may be written by itself for annotation scanning, or the target code may be scanned by using an existing code framework, for example: assuming that the target code is JAVA code, scanning the JAVA entity class labeled with the @ ESMetaData annotation when the software project is started can be implemented by means of a docscan method of a classpathbean definitionsscanner in the existing Spring framework, after the scanning, the entity class labeled with the annotation is managed to a Spring container, and then the target entity class is obtained from the Spring container.
Step S20: code annotation data is read from the target entity class.
Note that the annotation may be marked on the class name of the entity class (for short, referred to as index configuration annotation, e.g.: @ ESMetaData), or may be marked on the field of the entity class (for short, referred to as index structure annotation, e.g.: @ ESMapping and @ ESID, where @ ESID is a special @ ESMapping annotation, which is an annotation for identifying that a field of an entity class is set as a unique primary key). The code annotation data may include all annotation data in the target entity class, such as: annotation data for configuration annotations is indexed and annotation data for structural annotations is indexed.
It should be noted that the target entity class may further include other annotations unrelated to the creation of the database index, and when reading the code annotation data from the target entity class, all the annotation data in the target entity class may be read first, and then the annotation data unrelated to the creation of the database index is removed, and then the remaining annotation data is used as the code annotation data.
In practical use, the annotation marked on the class name of the entity class is an annotation used for describing the attribute information of the index, wherein the configurable attribute is shown in the following table 1:
TABLE 1 configuration item List for entity class name Annotation
The annotations marked on the fields of the entity class are annotations used for describing attribute information corresponding to the fields in the index structure, wherein the configurable attributes are shown in the following table 2:
TABLE 2 entity class field Annotation configuration item List
Furthermore, an alias can be set for the index in the document-oriented database, that is, the alias is also used as a query condition in the query, for example: if the alias setting is opened for a certain entity class, it means that the corresponding index does not need to be created for the entity class, but an alias needs to be set, so after the step S20, the method may further include:
Determining whether alias setting is started for the target entity class according to the code annotation data;
if so, determining the alias to be written and the index name to be set according to the code annotation data;
detecting whether a database index corresponding to the index name to be set exists or not;
if the database index corresponding to the index name to be set exists, generating an alias creating message according to the alias to be written and the index name to be set;
and calling a preset alias creating interface through the alias creating message, and setting the alias of the database index corresponding to the index name to be set as the alias to be written.
It should be noted that, alias setting may be performed by setting annotation configuration in the index configuration annotation, determining whether to open alias setting for the target entity class according to the code annotation data may be to extract annotation data of the index configuration annotation from the code annotation data, read alias related settings therein, and determine whether to open alias setting according to the alias related settings, for example: the read alias correlation setting is 'alias true'; and if the alias index is { a }, and the writeIndex is B', the alias setting is started, the alias is set for the index with the index name a, and when the entity class object corresponding to the entity class is stored, the data is stored in the index with the index name B.
It should be noted that the alias to be written may be data corresponding to an "indexName" attribute in the index configuration annotation, and the index name to be set is data corresponding to an "aliasIndex" attribute in the index configuration annotation, for example: assuming that the index configuration annotation is "@ MetaData (indexinme ═ a, alias ═ true, alias ═ B })", at this time, an index name a is to be written, and an index name B is to be set.
It can be understood that a setting error may occur when a developer performs configuration, at this time, a database index corresponding to an index name to be set may not exist in a document-oriented database, and if alias setting is performed at this time, an exception may occur, so that it may be detected whether a database index corresponding to an index name to be set exists, and if a database index corresponding to an index name to be set exists, an alias creating packet is generated according to an alias to be written and the index name to be set, and then a preset alias creating interface is called according to the alias creating packet, so that an alias of the database index corresponding to the index name to be set is set as an alias to be written. The preset alias creating interface is an API (application programming interface) provided by an official facing document type database and used for setting aliases for the indexes.
Step S30: and generating an index creation message according to the code annotation data.
It should be noted that the code annotation data includes all annotation data in the entity class, including annotation data on the class name of the entity class and annotation data marked on each field in the entity class, so that the configuration about the index and the configuration about the index structure can be read from the code annotation data, and the read configuration is converted into a format specified by an API provided by an authority, that is, the index creation message can be obtained.
Step S40: and calling a preset index creation interface through the index creation message to create a database index corresponding to the target entity class.
It should be noted that the preset index creation interface may be an API interface which is provided by an official facing document type database and needs to be accessed when creating an index. The step of calling the preset index creation interface through the index creation message may be to use the index creation message as an interface calling parameter, and transfer the interface calling parameter into the preset index creation interface to call the preset index creation interface.
It can be understood that the format of the index creation packet is a format specified by the preset index creation interface, and therefore, the preset index creation interface can normally analyze the index creation packet and create a corresponding database index in the document-oriented database according to the index creation packet.
In a specific implementation, before the software project is started, a developer may manually create a corresponding index in the document-oriented database in advance, or the software project is not started for the first time, that is, before the software project is started, a code corresponding to the software project is scanned, and a corresponding index is created in the document-oriented database, and if a preset index creating interface is directly called according to the index creating message to create the index at this time, unnecessary performance loss may be caused, and even an execution error occurs, and in order to avoid this phenomenon, before the preset index creating interface is called through the index creating message, an index name of the index to be created may be extracted from the index creating message, and whether an index corresponding to the index name of the index to be created exists in the document-oriented database is detected, and if the index creating message does not exist, calling a preset index creating interface through the index creating message, and continuously creating the database index corresponding to the target entity class.
Further, the rolling index is a scheme for governing the index data in the document database, a new index may be dynamically generated according to a customized rule, a governing effect not only effectively controls an index volume, but also has an effect of data aging processing, and in order to meet a setting requirement of a user on the rolling index, before the step S40, the method may further include:
Determining whether the target entity class starts rolling index setting or not according to the code annotation data;
if the rolling index setting is started, determining a rolling index generation rule according to the code annotation data;
extracting an index name to be created from the index creating message to obtain an alias to be set;
generating a rolling index name according to the rolling index generation rule;
updating the index creation message according to the alias to be set and the rolling index name to obtain a rolling index creation message;
correspondingly, the step of calling a preset index creation interface through the index creation packet to create the database index corresponding to the target entity class includes:
and calling a preset index creation interface through the rolling index creation message to create a database index corresponding to the target entity class.
It should be noted that, by setting annotation configuration in the index configuration annotation, rolling index setup may be started, and determining whether to start the rolling index setup for the target entity class according to the code annotation data may be to extract annotation data of the index configuration annotation from the code annotation data, read rolling index related settings therein, and determine whether to start according to the rolling index related settings, for example: assume that the scroll index correlation setting is "scroll ═ true; and if the target entity class is started, the rolling index is started, and the rolling index name is automatically generated by starting.
It should be noted that, determining the rolling index generation rule according to the code annotation data may be to extract a rolling index related setting from the code annotation data, and generate the rolling index generation rule according to a condition in the rolling index related setting, for example: assume that the scroll index correlation setting is "scroll ═ true; when the default value is adopted, the rolling index generation rule is "formed by the index name configured with the annotation + the current date + the sequence serial number", and if the index name configured in the annotation configured with the index is a (i.e., indexName ═ a), the current date is "XX-XX", and the sequence serial number is 0001, the rolling index name generated at this time is "a-XX-0001".
In actual use, the index name to be created is extracted from the index creation message, and the obtained alias to be set can use the index name to be created read from the index creation message as the alias to be set. Updating the index creation message according to the alias to be set and the rolling index name, wherein the step of obtaining the rolling index creation message may be to modify the name of the index to be created in the index creation message into the name of the rolling index, and to modify the alias of the index in the index creation message into the alias to be set. And calling a preset index creation interface through the rolling index creation message, wherein an index name is consistent with a rolling index name and an alias is consistent with an index to be set when the database index is created at the moment.
For example: assuming that the name of the rolling index is 'A-XX-XX-0001', the index creation message is { 'good': { "aliases": { } } mappings ": {.. } "settings": { "index": {.. }, if the name of the index to be created in the index creation message is "good", and if the name of the index to be created is "good", the name of the other index to be set is "good", the obtained rolling index creation message at this time is { "a-XX-0001": { "aliases": { "good" } } "mappings": {.. } "settings": { "index": {.. }, the index corresponding to the database created at this time is the index named "A-XX-XX-0001", and the alias is "good".
In a specific implementation, a thread may be generated for the rolling index after the rolling index is created, the thread is used to detect the data amount in the rolling index or the existence duration of the rolling index, and when the data amount in the rolling index is greater than the upper limit of the data amount set by the user or the existence duration of the index is greater than the maximum duration of the single rolling index set by the user, the thread is generated to increment the sequence number used when the rolling index is generated by one, so as to generate a new rolling index.
In the embodiment, a target entity class is obtained by scanning the entity class marked with the preset type annotation in the target code; reading code annotation data from the target entity class; generating an index creation message according to the code annotation data; and calling a preset index creation interface through the index creation message to create a database index corresponding to the target entity class. The target code can be automatically scanned, the index creation message is automatically generated according to the code annotation data in all the entity classes marked with the annotations of the preset types, and then the corresponding database index is created through the index creation message calling the preset creation interface, so that developers do not need to pay attention to the calling of a complicated official interface, the index can be automatically generated only by configuring simple annotations, the workload of the developers is greatly reduced, and the database index is simpler and more convenient to maintain.
Referring to fig. 3, fig. 3 is a flowchart illustrating a second embodiment of an index creating method according to the present invention.
Based on the foregoing first embodiment, the step S30 of the index creating method according to this embodiment includes:
step S301: and determining an index configuration annotation and an index structure annotation set according to the code annotation data.
It should be noted that the entity class may include a plurality of fields, that is, a plurality of index structure annotations may exist in one entity class, and therefore, determining the index configuration annotation and the index structure annotation set according to the code annotation data may be based on the difference of the positions of the index annotations, dividing the code annotation data into the index configuration annotation and the index structure annotation, and then aggregating the index structure annotations to obtain the index structure annotation set.
Step S302: and generating index configuration data according to the index configuration annotation, and generating field configuration data according to the index structure annotation set.
It should be noted that, the generation of the index configuration data according to the index configuration annotation may be to read the annotation configuration in the index configuration annotation, and then convert the annotation configuration into a format according to the official specification of the document-oriented database, thereby obtaining the index configuration data. The mapping relation table can be set for the annotation configuration and the configuration item format specified by the official, and the format conversion is carried out according to the mapping relation in the mapping relation table during the conversion.
It should be noted that, the generation of the field configuration data according to the index structure annotation set may be to determine the configuration data of each field in the index structure according to the annotation configuration of each index structure annotation in the index structure annotation set, then aggregate the obtained configuration data, and convert the configuration data into a format according to the official regulation of the document-oriented database, thereby obtaining the field configuration data.
In a specific implementation, the integral processing is performed on the index structure annotation set, so that a phenomenon of repeatedly processing or omitting to process a certain index structure annotation is easily caused, and in order to avoid this phenomenon, the step S302 in this embodiment may include:
traversing the index structure annotation set, and taking the traversed index structure annotation as the current structure annotation;
extracting annotation configuration parameters from the current structure annotation, and acquiring an entity field corresponding to the current structure annotation to acquire a target entity field;
generating configuration data corresponding to the target entity type field according to the annotation configuration parameters;
and at the end of traversal, combining the obtained configuration data into field configuration data.
It should be noted that, traversing the index structure annotation set may be sequentially traversing the index structure annotation set, or may be reversely traversing the index structure annotation set, which is not limited in this embodiment.
It should be noted that the annotation configuration parameters may include an annotation configuration item and setting parameters corresponding to the annotation configuration item, an entity type field corresponding to the current structure annotation is obtained, and the obtaining of the target entity type field may be that the entity type field marked by the current structure annotation is used as the target entity type field. The generating of the configuration data corresponding to the target entity field according to the annotation configuration parameter may be converting the annotation configuration parameter into a configuration item format specified by an authority according to a preset configuration parameter mapping table, thereby obtaining the configuration data corresponding to the target entity field. The preset configuration parameter mapping table may be set in advance by an administrator of the index creation device, where the preset configuration parameter mapping table includes mapping relationships between various annotation configuration parameters and configuration item formats.
For example: assuming that the current structure annotation is "@ ESMapping (datatype ═ date)", and the corresponding target entity class field is "good _ date", the annotation configuration parameter therein is datatpe ═ date mapping configuration data format "type": "date", the configuration data corresponding to the field of the target entity class generated at this time is "good _ date": { "type": "date" }.
In actual use, when traversal is finished, configuration data corresponding to each entity field in a target entity class can be obtained, the configuration data corresponding to each entity field is filled into a preset template, and then field configuration data can be obtained, wherein the preset template can be preset according to a format specified by an official API facing a structure database. For example: assuming that there are two fields in the target entity class, including "good _ data" and "good _ type", the corresponding configuration data is "good _ data": { "type": "date" } and "good _ date": { "type": "keywords", presetting a template as { "mappings": { "properties": { XX,. } } }, where XX is a template placeholder, and the configuration data corresponding to each field is filled in a preset template, and the obtained field configuration data is: { "mappings": { "properties": { "good _ date": { "type": "date" }, "good _ date": { "type": "keyword" } }.
Further, because of the requirement of software development, object nesting may occur in some cases, that is, an entity class object of another entity class is stored in a certain entity class field in an entity class, and in order to still normally create a database index in such a case, the step of generating configuration data corresponding to the target entity class field according to the annotation configuration parameter in this embodiment may include:
determining whether the data type of the target entity type field is a nested object type or not according to the annotation configuration parameters;
if yes, acquiring an entity class corresponding to the target entity class field, and acquiring a nested entity class;
and generating configuration data corresponding to the target entity type field according to the field information in the nested entity type.
It should be noted that, determining whether the data type of the target entity class field is the nested object type according to the annotation configuration parameter may be to obtain whether a "nested _ class" configuration item exists in the annotation configuration parameter, and if the "nested _ class" configuration item exists and the parameter corresponding to the configuration item is not "null" or "null", it indicates that the data type of the target entity class field is the nested object type. At this time, the entity class can be searched according to the parameter corresponding to the "nested _ class" configuration item, so as to obtain the entity class corresponding to the target entity class field.
It can be understood that, if the data type of the target entity class field is a nested object type, it indicates that the target entity class field stores an entity class object of another entity class, and at this time, the configuration data corresponding to the entity class field cannot be generated in a normal manner, and therefore, it is necessary to acquire the entity class corresponding to the target entity class field, acquire the nested entity class, then read field information of all fields existing in the nested entity class, and convert the field information thereof into a configuration item format specified by an official authority, thereby acquiring the configuration data corresponding to the target entity class field. The field information may include field name, field type, and other information.
For example: assuming that the field of the target entity class is "good _ member", the corresponding entity class is "member", the entity class includes two fields of "name" and "age", and the corresponding field types are "text" and "int", respectively, then the configuration data corresponding to the field of the target entity class generated at this time is "good _ member": { "properties": { "name": { "type": "text" }, "age": { "type": "int" }).
Further, the document-oriented database generally supports functions such as efficient search prompt, and in order to enable the index creation of the present invention to be also suitable for the efficient search prompt function, the step of generating the configuration data corresponding to the target entity field according to the annotation configuration parameter in this embodiment may include:
Generating field type data corresponding to the target entity type field according to the annotation configuration parameters;
determining whether the target entity class field supports efficient search prompt or not according to the annotation configuration parameters;
if the target entity type field supports efficient search prompt, efficient search configuration data is generated according to the annotation configuration parameters;
and combining the field type data and the efficient search configuration data into configuration data corresponding to the target entity type field.
It should be noted that the efficient search hint is generally divided into two types, which are an efficient full-text search hint and an efficient prefix search hint, respectively, and if "ngram ═ true" and/or "negest ═ true" exists in the annotation configuration parameter, it indicates that the target entity class field is configured to support the efficient search hint. The field type data can be configuration data such as a data type corresponding to the target entity type field, and the efficient search configuration data can include configuration data such as efficient search rules and word segmentation.
In actual use, if the target entity type field is configured to support efficient search prompting, then when generating the configuration data corresponding to the target entity type field, not only the field type data needs to be acquired, but also efficient search configuration data needs to be set for the field type data, and then the field type data and the efficient search configuration data are combined into the configuration data corresponding to the target entity type field.
For example: assume that the target entity class field is "goods _ name" and its corresponding current structure annotation is
@ ESMapping (datatype. text _ type, analyzer ═ analyzer. ik _ max _ word, search _ analyzer ═ analyzer. ik _ max _ word, and gather ═ true), this time, it means that this field supports efficient prefix search hints, and the configuration data generated for this time is
Assuming that the target entity class field is "phone" and the corresponding current structure annotation is @ ESMapping (datatype, key _ type, and ngram ═ true), it indicates that the field supports efficient full-text search prompting, and the configuration data generated for the field at this time is "phone"
Step S303: and combining the index configuration data and the field configuration data in a preset format to obtain an index creation message.
It should be noted that, combining the index configuration data and the field configuration data in a preset format to obtain the index creation packet may be generating a packet template according to the preset format, and then filling the index configuration data and the field configuration data into the packet template to obtain the index creation packet.
In the embodiment, an index configuration annotation and an index structure annotation set are determined according to the code annotation data; generating index configuration data according to the index configuration annotation, and generating field configuration data according to the index structure annotation set; and combining the index configuration data and the field configuration data in a preset format to obtain an index creation message. The code annotation data are respectively processed according to different annotation types, the field configuration data are generated according to the index configuration annotations, the field configuration data are generated according to the index structure annotation set, then the index configuration data and the field configuration data are combined into the index creation message, and the data generation flows are separated, so that the program execution efficiency can be improved, the coupling of the program can be reduced, and the abnormal investigation of developers can be facilitated when the message conversion is abnormal.
Furthermore, an embodiment of the present invention further provides a storage medium, where an index creating program is stored, and the index creating program, when executed by a processor, implements the steps of the index creating method described above.
Referring to fig. 4, fig. 4 is a block diagram illustrating a first embodiment of an index creating apparatus according to the present invention.
As shown in fig. 4, an index creating apparatus provided in an embodiment of the present invention includes:
the code scanning module 10 is configured to scan an entity class marked with a preset type annotation in a target code to obtain a target entity class;
a data extraction module 20, configured to read code annotation data from the target entity class;
the message generating module 30 is configured to generate an index creation message according to the code annotation data;
and the index creating module 40 is configured to invoke a preset index creating interface through the index creating packet to create a database index corresponding to the target entity class.
In the embodiment, a target entity class is obtained by scanning the entity class marked with the preset type annotation in the target code; reading code annotation data from the target entity class; generating an index creation message according to the code annotation data; and calling a preset index creation interface through the index creation message to create a database index corresponding to the target entity class. The target code can be automatically scanned, the index creation message is automatically generated according to the code annotation data in all the entity classes marked with the annotations of the preset types, and then the corresponding database index is created through the index creation message calling the preset creation interface, so that developers do not need to pay attention to the calling of a complicated official interface, the index can be automatically generated only by configuring simple annotations, the workload of the developers is greatly reduced, and the database index is simpler and more convenient to maintain.
Further, the message generating module 30 is further configured to determine an index configuration annotation and an index structure annotation solution set according to the code annotation data; generating index configuration data according to the index configuration annotations, and generating field configuration data according to the index structure annotation set; and combining the index configuration data and the field configuration data in a preset format to obtain an index creation message.
Further, the message generating module 30 is further configured to traverse the index structure annotation set, and use the traversed index structure annotation as a current structure annotation; extracting annotation configuration parameters from the current structure annotation, acquiring an entity field corresponding to the current structure annotation, and acquiring a target entity field; generating configuration data corresponding to the target entity type field according to the annotation configuration parameters; and when the traversal is finished, combining the obtained configuration data into field configuration data.
Further, the message generating module 30 is further configured to determine whether the data type of the target entity class field is a nested object type according to the annotation configuration parameter; if yes, acquiring an entity class corresponding to the target entity class field, and acquiring a nested entity class; and generating configuration data corresponding to the target entity class field according to the field information in the nested entity class.
Further, the message generating module 30 is further configured to generate field type data corresponding to the target entity type field according to the annotation configuration parameter; determining whether the target entity class field supports efficient search prompt or not according to the annotation configuration parameters; if the target entity type field supports efficient search prompt, efficient search configuration data is generated according to the annotation configuration parameters; and combining the field type data and the efficient search configuration data into configuration data corresponding to the target entity type field.
Further, the data extraction module 20 is further configured to determine whether alias setting is started for the target entity class according to the code annotation data; if so, determining an alias to be written and an index name to be set according to the code annotation data; detecting whether a database index corresponding to the index name to be set exists or not; if the database index corresponding to the index name to be set exists, generating an alias creating message according to the alias to be written and the index name to be set; and calling a preset alias creating interface through the alias creating message, and setting the alias of the database index corresponding to the index name to be set as the alias to be written.
Further, the index creating module 40 is further configured to determine whether the target entity class starts a rolling index setting according to the code annotation data; if the rolling index setting is started, determining a rolling index generation rule according to the code annotation data; extracting an index name to be created from the index creating message to obtain an alias to be set; generating a rolling index name according to the rolling index generation rule; updating the index creation message according to the alias to be set and the rolling index name to obtain a rolling index creation message;
the index creating module 40 is further configured to invoke a preset index creating interface through the rolling index creating packet to create a database index corresponding to the target entity class.
It should be understood that the above is only an example, and the technical solution of the present invention is not limited in any way, and in a specific application, a person skilled in the art may set the technical solution as needed, and the present invention is not limited thereto.
It should be noted that the above-described work flows are only exemplary, and do not limit the scope of the present invention, and in practical applications, a person skilled in the art may select some or all of them to achieve the purpose of the solution of the embodiment according to actual needs, and the present invention is not limited herein.
In addition, the technical details that are not described in detail in this embodiment may refer to the index creation method provided in any embodiment of the present invention, and are not described herein again.
Further, it is to be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention or portions thereof that contribute to the prior art may be embodied in the form of a software product, where the computer software product is stored in a storage medium (e.g. Read Only Memory (ROM)/RAM, magnetic disk, optical disk), and includes several instructions for enabling a terminal device (e.g. a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention, and all equivalent structures or equivalent processes performed by the present invention or directly or indirectly applied to other related technical fields are also included in the scope of the present invention.
Claims (10)
1. An index creation method, characterized in that the index creation method comprises the steps of:
scanning entity classes marked with preset type annotations in the target codes to obtain target entity classes;
reading code annotation data from the target entity class;
generating an index creation message according to the code annotation data;
and calling a preset index creation interface through the index creation message to create a database index corresponding to the target entity class.
2. The index creation method of claim 1 wherein the step of generating an index creation packet from the code annotation data comprises:
determining an index configuration annotation and an index structure annotation set according to the code annotation data;
generating index configuration data according to the index configuration annotations, and generating field configuration data according to the index structure annotation set;
And combining the index configuration data and the field configuration data in a preset format to obtain an index creation message.
3. The index creation method of claim 2 wherein the step of generating field configuration data from the set of index structure annotations comprises:
traversing the index structure annotation set, and taking the traversed index structure annotation as a current structure annotation;
extracting annotation configuration parameters from the current structure annotation, and acquiring an entity field corresponding to the current structure annotation to acquire a target entity field;
generating configuration data corresponding to the target entity type field according to the annotation configuration parameters;
and at the end of traversal, combining the obtained configuration data into field configuration data.
4. The index creation method of claim 3, wherein the step of generating configuration data corresponding to the target entity class field according to the annotation configuration parameter comprises:
determining whether the data type of the target entity type field is a nested object type or not according to the annotation configuration parameters;
if yes, acquiring an entity class corresponding to the target entity class field, and acquiring a nested entity class;
And generating configuration data corresponding to the target entity type field according to the field information in the nested entity type.
5. The index creation method of claim 4, wherein the step of generating configuration data corresponding to the target entity class field according to the annotation configuration parameter comprises:
generating field type data corresponding to the target entity type field according to the annotation configuration parameters;
determining whether the target entity class field supports efficient search prompt or not according to the annotation configuration parameters;
if the target entity type field supports efficient search prompt, efficient search configuration data is generated according to the annotation configuration parameters;
and combining the field type data and the efficient search configuration data into configuration data corresponding to the target entity type field.
6. The index creation method of any of claims 1-5, wherein the step of reading code annotation data from the target entity class is followed by further comprising:
determining whether alias setting is started for the target entity class according to the code annotation data;
if so, determining the alias to be written and the index name to be set according to the code annotation data;
Detecting whether a database index corresponding to the index name to be set exists or not;
if the database index corresponding to the index name to be set exists, generating an alias creating message according to the alias to be written and the index name to be set;
and calling a preset alias creating interface through the alias creating message, and setting the alias of the database index corresponding to the index name to be set as the alias to be written.
7. The index creation method according to any one of claims 1 to 5, wherein before the step of calling a preset index creation interface through the index creation packet to create the database index corresponding to the target entity class, the index creation method further comprises:
determining whether the target entity class starts rolling index setting or not according to the code annotation data;
if the rolling index setting is started, determining a rolling index generation rule according to the code annotation data;
extracting an index name to be created from the index creating message to obtain an alias to be set;
generating a rolling index name according to the rolling index generation rule;
updating the index creation message according to the alias to be set and the rolling index name to obtain a rolling index creation message;
Correspondingly, the step of calling a preset index creation interface through the index creation packet to create the database index corresponding to the target entity class includes:
and calling a preset index creation interface through the rolling index creation message to create a database index corresponding to the target entity class.
8. An index creation apparatus, characterized in that the index creation apparatus comprises the following modules:
the code scanning module is used for scanning the entity class marked with the preset type annotation in the target code to obtain a target entity class;
the data extraction module is used for reading code annotation data from the target entity class;
the message generating module is used for generating an index creation message according to the code annotation data;
and the index creating module is used for calling a preset index creating interface through the index creating message so as to create the database index corresponding to the target entity class.
9. An index creation device, characterized in that the index creation device comprises: a processor, a memory and an index creation program stored on the memory and executable on the processor, the index creation program when executed by the processor implementing the steps of the index creation method as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that an index creation program is stored on the computer-readable storage medium, which when executed implements the steps of the index creation method of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210259724.2A CN114676133A (en) | 2022-03-16 | 2022-03-16 | Index creating method, device, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210259724.2A CN114676133A (en) | 2022-03-16 | 2022-03-16 | Index creating method, device, equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114676133A true CN114676133A (en) | 2022-06-28 |
Family
ID=82073843
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210259724.2A Pending CN114676133A (en) | 2022-03-16 | 2022-03-16 | Index creating method, device, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114676133A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115589440A (en) * | 2022-12-12 | 2023-01-10 | 北京沐融信息科技股份有限公司 | Message annotation configuration method, packet packing method and parsing method |
CN118035251A (en) * | 2024-04-11 | 2024-05-14 | 河北省交通规划设计研究院有限公司 | Urban data model management system and method based on multi-feature fusion |
-
2022
- 2022-03-16 CN CN202210259724.2A patent/CN114676133A/en active Pending
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115589440A (en) * | 2022-12-12 | 2023-01-10 | 北京沐融信息科技股份有限公司 | Message annotation configuration method, packet packing method and parsing method |
CN115589440B (en) * | 2022-12-12 | 2023-03-21 | 北京沐融信息科技股份有限公司 | Message annotation configuration method, packet packing method and parsing method |
CN118035251A (en) * | 2024-04-11 | 2024-05-14 | 河北省交通规划设计研究院有限公司 | Urban data model management system and method based on multi-feature fusion |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109947789B (en) | Method, device, computer equipment and storage medium for processing data of multiple databases | |
CA2684822C (en) | Data transformation based on a technical design document | |
US20020129059A1 (en) | XML auto map generator | |
US20090234818A1 (en) | Systems and Methods for Extracting Data from a Document in an Electronic Format | |
CN108090351B (en) | Method and apparatus for processing request message | |
CN114676133A (en) | Index creating method, device, equipment and storage medium | |
CN106406844B (en) | Method and device for realizing public number menu of communication interaction platform | |
US20170277672A1 (en) | Information processing device, information processing method, and computer program product | |
CN111818175B (en) | Enterprise service bus configuration file generation method, device, equipment and storage medium | |
CN112883030A (en) | Data collection method and device, computer equipment and storage medium | |
CN111666383A (en) | Information processing method, information processing device, electronic equipment and computer readable storage medium | |
CN110502513B (en) | Data acquisition method, device, equipment and computer readable storage medium | |
CN111178025A (en) | Editing method and device of nuclear power plant operation guide rules, computer equipment and storage medium | |
US11244000B2 (en) | Information processing apparatus and non-transitory computer readable medium storing program for creating index for document retrieval | |
CN110162712B (en) | Event acquisition method, device, equipment and storage medium | |
CN114036178A (en) | Service interface generation method, device, computer and readable storage medium | |
CN113779362A (en) | Data searching method and device | |
CN116910496B (en) | Configuration method and device of data quality monitoring rule and readable storage medium | |
CN113643082B (en) | Invoice processing method and device based on artificial intelligence, computer equipment and medium | |
CN106547863A (en) | The method and device of operation HBase | |
CN109508183B (en) | REST code generation method and device in storage cluster | |
CN112015466A (en) | Information retrieval method, information retrieval device, computer equipment and storage medium | |
CN116627908A (en) | Keyword searching method, device and equipment | |
CN117520483A (en) | Information verification method and device based on large model | |
CN114003483A (en) | Data problem checking method, device and equipment and computer readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |