WO2023087673A1 - Hierarchical data retrieval method and apparatus, and device - Google Patents

Hierarchical data retrieval method and apparatus, and device Download PDF

Info

Publication number
WO2023087673A1
WO2023087673A1 PCT/CN2022/097345 CN2022097345W WO2023087673A1 WO 2023087673 A1 WO2023087673 A1 WO 2023087673A1 CN 2022097345 W CN2022097345 W CN 2022097345W WO 2023087673 A1 WO2023087673 A1 WO 2023087673A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
retrieval
database
type
hierarchical
Prior art date
Application number
PCT/CN2022/097345
Other languages
French (fr)
Chinese (zh)
Inventor
田标
崔伟
陈献青
邓捷
王刚
王家宾
黄文文
Original Assignee
天翼数字生活科技有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 天翼数字生活科技有限公司 filed Critical 天翼数字生活科技有限公司
Publication of WO2023087673A1 publication Critical patent/WO2023087673A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution

Definitions

  • the invention relates to the technical field of data retrieval, in particular to a hierarchical data retrieval method, device and equipment.
  • a hierarchical data retrieval method provided by the first aspect of the present invention includes:
  • the retrieval type is index database retrieval
  • the step of querying the attribution information corresponding to the user identifier from a preset database, and determining the database hierarchy type corresponding to the user identifier includes:
  • the affiliation information includes a first affiliation organization ID
  • the relational database includes a plane hierarchical tree information table and a first organization equipment association information table; when the database hierarchy type is a limited hierarchy type, the if If the retrieval type is a relational database retrieval, then the relational database corresponding to the database hierarchy type is retrieved according to the attribution information, and the step of obtaining the first target hierarchy data includes:
  • the retrieval type is a relational database retrieval, then query the equipment information table of the first organization according to the ID of the first affiliation organization, and determine the corresponding equipment data and the branch ID of the hierarchical tree;
  • An association between each branch data of the hierarchical tree and the device data is established to obtain first target hierarchical data.
  • the affiliation information includes a second affiliation organization ID and the superior node ID
  • the relational database includes a tree node information table, a tree node association relationship table, and a second organization equipment association information table; when the database level
  • the retrieval type is a relational database retrieval, the step of retrieving the relational database corresponding to the database hierarchical type according to the attribution information to obtain the first target hierarchical data includes:
  • the retrieval type is a relational database retrieval, then query the equipment information table of the second organization according to the ID of the second affiliation organization, and determine the corresponding equipment data, the ID of the superior node and the node ID of the hierarchical tree;
  • the affiliation information includes a third organization affiliation ID
  • the ES index library includes a flat hierarchical tree index table and a first organization equipment association index table
  • the database hierarchy type is a limited hierarchy type
  • the retrieval type is an index database retrieval, then parsing the data retrieval request to obtain a search condition and a target data format;
  • the affiliation information includes a fourth organization affiliation ID
  • the ES index library includes a tree node information index table and a second organization equipment association index table; when the database hierarchy type is an unrestricted hierarchy type, the If the retrieval type is index database retrieval, then according to the data retrieval request and the attribution information, retrieve the ES index database corresponding to the database hierarchy type, and obtain the second target hierarchy data, including:
  • the retrieval type is an index database retrieval, then parsing the data retrieval request to obtain a search condition;
  • the tree nodes corresponding to each of the hierarchical tree node IDs are associated according to the second node association relationship, and an association with the device data is established to obtain second target hierarchical data.
  • An association between the additional user identifier and the additional device data is established, and an additional ES index table is obtained and stored in the ES index library.
  • the second aspect of the present invention provides a hierarchical data retrieval device, including:
  • a user identification acquisition module configured to obtain a user identification corresponding to the user terminal in response to a login request sent by any user terminal
  • a database hierarchy type determining module configured to query the attribution information corresponding to the user identifier from a preset database, and determine the database hierarchy type corresponding to the user identifier;
  • a retrieval type acquisition module configured to obtain the retrieval type corresponding to the data retrieval request when receiving the data retrieval request sent by the client;
  • a relational data retrieval module configured to retrieve the relational database corresponding to the database hierarchy type according to the attribution information if the retrieval type is a relational database retrieval, to obtain the first target hierarchical data;
  • An index data retrieval module configured to retrieve the ES index library corresponding to the database hierarchy type according to the data retrieval request and the attribution information if the retrieval type is index database retrieval, to obtain second target hierarchical data;
  • a hierarchical data returning module configured to return the first target hierarchical data or the second target hierarchical data to the client.
  • the third aspect of the present invention also provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor is executed as described in the first aspect of the present invention.
  • a computer program is stored in the memory, and when the computer program is executed by the processor, the processor is executed as described in the first aspect of the present invention.
  • the present invention has the following advantages:
  • the present invention obtains the user identification corresponding to the user terminal by responding to a login request sent by any user terminal; queries the attribution information corresponding to the user identification from a preset database, and determines the database hierarchy type corresponding to the user identification; When a data retrieval request is made, obtain the retrieval type corresponding to the data retrieval request; if the retrieval type is a relational database retrieval, retrieve the relational database corresponding to the database hierarchy type according to the attribution information, and obtain the first target hierarchical data; if the retrieval type is an index database retrieval , then according to the data retrieval request and the ES index library corresponding to the attribution information search database level type, obtain the second target level data; return the first target level data or the second target level data to the client.
  • hierarchical tree data can be obtained through one SQL statement or several queries. Furthermore, the efficiency of the data retrieval process under the amount of hundreds of millions of users is more effectively improved.
  • FIG. 1 is a flow chart of the steps of a hierarchical data retrieval method provided by Embodiment 1 of the present invention
  • FIG. 2 is a flow chart of steps of a hierarchical data retrieval method provided by Embodiment 2 of the present invention
  • FIG. 3 is a flow chart of steps for an incremental synchronization process of hierarchical data provided by an embodiment of the present invention
  • Fig. 4 is a flow chart of the steps of the retrieval query process of a kind of ES index library provided by the embodiment of the present invention.
  • FIG. 5 is a structural block diagram of a hierarchical data retrieval device provided by Embodiment 3 of the present invention.
  • the embodiment of the present invention provides a hierarchical data retrieval method, device and equipment, which are used to solve the problem that the traditional hierarchical data retrieval method has low retrieval efficiency in the Internet business search process with hundreds of millions of users due to the limitation of its structure and retrieval path. Low, technical problems that cannot meet the needs of Internet business development.
  • FIG. 1 is a flowchart of steps of a hierarchical data retrieval method provided by Embodiment 1 of the present invention.
  • a hierarchical data retrieval method provided by the present invention includes:
  • Step 101 in response to a login request sent by any client, obtain a user ID corresponding to the client;
  • User ID refers to the client ID carried in the login request when any client sends a login request.
  • the device responds to the login request sent by any client, and performs login verification on the login request, for example, whether the client has the corresponding login authority by checking whether the client is registered, etc., if the login If the verification is passed, the user ID corresponding to the client is obtained from the login request, so as to obtain the data basis for the subsequent client to query hierarchical data.
  • Step 102 query the attribution information corresponding to the user ID from the preset database, and determine the database hierarchy type corresponding to the user ID;
  • the preset database refers to a relational database that stores information such as a client-organization association table, a hierarchical tree branch ID set, and the like.
  • Affiliation information refers to the information indicating the association between the user ID and multiple affiliation organizations, user types and branches of the affiliation tree, including but not limited to the ID of the first affiliation organization, the ID of the second affiliation organization, and the ID of the third affiliation organization , the ID of the fourth affiliation organization, the ID of the superior node, and other information.
  • the user ID After obtaining the user ID carried in the login request, the user ID can be used as a search word to query the corresponding attribution information in the preset database, and at the same time, according to the user ID combined with the login request, the hierarchical database to which the user ID belongs can be judged Database hierarchy type.
  • Step 103 when receiving the data retrieval request sent by the client, obtain the retrieval type corresponding to the data retrieval request;
  • the data retrieval request sent by the client After determining the database level type corresponding to the user ID, if the data retrieval request sent by the client is received, the data retrieval request can be further responded to, and the corresponding retrieval type can be obtained to determine the retrieval method required by the data retrieval request. For example, relational database retrieval or indexed database retrieval, etc.
  • Step 104 if the search type is relational database search, search the relational database corresponding to the database level type according to the attribution information, and obtain the first target level data;
  • a relational database refers to a database built on the basis of a relational database model. It uses concepts and methods such as set algebra to process data in the database. It is also a set of tables organized into a formal descriptive table. Essence is a special collection of data items loaded with data in these tables that can be accessed or recalled in many different ways without reorganizing the database tables.
  • the definition of a relational database results in a table of metadata or in a formal description of tables, columns, scopes and constraints. Each table (sometimes called a relation) contains one or more data types represented by columns. Each row contains a unique data entity of the type defined by the column.
  • the SQL language is the interface of standard users and applications to relational databases. Its advantage is that it is easy to expand, and after the initial database creation, a new data type can be added without modifying all existing application software.
  • the mainstream relational databases include oracle, db2, sqlserver, sybase, mysql, etc.
  • attribution information can be used as a keyword or keyword, and the retrieval method of relational database retrieval is in the The relational database corresponding to the database hierarchy type is retrieved to obtain the first target hierarchy data.
  • Step 105 if the retrieval type is index database retrieval, according to the data retrieval request and the ES index database corresponding to the attribution information retrieval database hierarchy type, the second target hierarchy data is obtained;
  • the ES index library refers to a distributed, highly scalable, high real-time search and data analysis engine.
  • ES indexes are equivalent to tables in relational databases.
  • An index can contain multiple fields of different data types, but ES indexes cannot be associated with tables. It can easily enable large amounts of data to be searched, analyzed and explored. Taking full advantage of the horizontal scalability of Elasticsearch can make data more valuable in the production environment.
  • the implementation principle of Elasticsearch is mainly divided into the following steps. First, the user submits the data to the Elasticsearch database, and then uses the word segmentation controller to segment the corresponding sentence, and stores its weight and word segmentation results into the data. When the user searches for data At that time, the results will be ranked and scored according to the weight, and then the returned results will be presented to the user.
  • the retrieval type is judged to be indexed database retrieval, it indicates that the retrieval method at this time is fuzzy search or full-text search.
  • compound keywords or key words can be formed based on the search conditions specified in the data retrieval request and attribution information. word, search the ES index database corresponding to the database hierarchy type, so as to obtain the second target hierarchy data.
  • Step 106 return the first target level data or the second target level data to the client.
  • the first target level data or the second target level data After the first target level data or the second target level data is acquired, it is returned to the client for display, so that the user can check the level data.
  • the user identifier corresponding to the client is obtained; the attribution information corresponding to the user identifier is queried from a preset database, and the database hierarchy type corresponding to the user identifier is determined;
  • the retrieval type corresponding to the data retrieval request if the retrieval type is a relational database retrieval, then retrieve the relational database corresponding to the database hierarchy type according to the attribution information, and obtain the first target level data; if the retrieval If the type is index database retrieval, then according to the data retrieval request and the ES index library corresponding to the attribution information retrieval database level type, obtain the second target level data; return the first target level data or the second target level data to the client.
  • hierarchical tree data can be obtained through one SQL statement or several queries. Furthermore, the efficiency of the data retrieval process under the amount of hundreds of millions of users is more effectively improved.
  • FIG. 2 is a flowchart of steps of a hierarchical data retrieval method provided by Embodiment 2 of the present invention.
  • a hierarchical data retrieval method provided by the present invention includes:
  • Step 201 in response to a login request sent by any client, obtain a user ID corresponding to the client;
  • step 201 the specific implementation process of step 201 is similar to step 101, and will not be repeated here.
  • Step 202 query the attribution information corresponding to the user ID from the preset database, and determine the database hierarchy type corresponding to the user ID;
  • step 202 may include the following sub-steps:
  • the attribution information may include various contents.
  • the preset database may be queried according to the user identification to obtain the attribution information corresponding to the user identification and cache.
  • the database hierarchy type corresponding to the user ID is limited. At this time, it can be determined that the database hierarchy type corresponding to the user ID is a limited hierarchy type; if it contains a superior node ID, it indicates that the affiliation organization ID in the attribution information at this time has an associated superior Node ID and hierarchical data are stored in the form of node information and node association relationship. At this time, it can be determined that the database hierarchical type corresponding to the user ID is an unrestricted hierarchical type.
  • the affiliation information may also include a user type, which is used to limit the type to which the user terminal belongs, for example, the user terminal belongs to a certain organization, and the embodiment of the present invention does not limit this, such as the user terminal being an independent organization.
  • Step 203 when receiving the data retrieval request sent by the client, obtain the retrieval type corresponding to the data retrieval request;
  • step 203 is similar to that of step 103, and will not be repeated here.
  • a relational database can be constructed in the following ways:
  • an organization information table (saving organization id, name, address, contact information and other organization's own data), an organization and equipment association table, a user information table, a user and organization association table in the relational database, according to SQL
  • the query condition indexes the table.
  • the user information table is used to save the user terminal id, name, mobile phone number and other self-information.
  • the field names of each node should be the abbreviation of the business entity name as much as possible, and the field names numbered in sequence should be used only in special cases.
  • the user-institution association table is used to record the association relationship between the user and the institution to which it belongs.
  • t_region_tree Taking the hierarchical tree from province to street as an example, the flat hierarchical tree information table t_region_tree can be shown in Table 1 below:
  • the primary key is also the hierarchical tree branch id State / province province varchar the province/municipality id province_id bigint the City area city varchar the city/district id city_id bigint the District/County county varchar the district/county id county_id bigint the street/town street varchar the street/town id street_id bigint the
  • a table is used to record the complete branches from the top to the bottom of the hierarchical tree and the relationship information of each node in it.
  • the order of the fields in the table from left to right corresponds to the actual order of the nodes from top to bottom of the hierarchical tree.
  • the equipment information table of the first institution may be shown in Table 2 below:
  • the main fields of the device information table of the first organization may include but not limited to ID of the first affiliated organization, device id, device name, IP address of the device, etc. It can also be a hierarchical tree branch id.
  • the name of the province, city, county, and district as the node name changes very little. If the node name will change frequently, and the number of child nodes in a tree may be relatively large at the same time, in order to avoid the influence of the database update operation, you can also extract all the node names to create a node information table, the main fields include node id, node name, node Encoded so that only one record here needs to be updated each time the node name is updated.
  • the flat hierarchical tree information table only the id or code of the node is saved for each hierarchical tree node, and the id and code are constructed by continuous self-incremental data. At this time, a record can store up to hundreds of hierarchical trees.
  • Table 1 and Table 2 The structural advantages of the above Table 1 and Table 2 include: 1) meet the business needs of hierarchical tree management and storage; 2) can obtain all directory trees of an organization through a SQL query; 3) can obtain a node containing a node through a SQL query 4) Support user data permissions and data security, ensuring that a user can only see the data allowed by his permissions; 5) The impact of management operations such as adding, deleting, and modifying business data on other operations can be controlled within A limited range that does not grow larger as the amount of data increases.
  • the data that needs to be saved is generally large in scale. If the above-mentioned relational database of the restricted hierarchical type is used to save, it will easily lead to slow reading.
  • the above-mentioned flat hierarchical tree information table can be split into The tree node information table t_node_link and the tree node association relationship table t_node_link are established at the same time as the second institutional equipment association information table.
  • the tree node information table records each tree node ID, node name and other fields that can be added according to the business.
  • the tree node association table can be shown in Table 3 below:
  • Step 204 if the search type is relational database search, search the relational database corresponding to the database level type according to the attribution information, and obtain the first target level data;
  • the affiliation information includes a first affiliation organization ID
  • the relational database includes a plane hierarchical tree information table and a first organization equipment association information table
  • step 204 may include the following subsections step:
  • the retrieval type is a relational database retrieval, query the equipment information table of the first organization according to the ID of the first affiliation organization, and determine the corresponding equipment data and the branch ID of the hierarchical tree;
  • An association between branch data of each hierarchical tree and device data is established to obtain the first target hierarchical data.
  • the database hierarchy type is a limited hierarchy type and the retrieval type is a relational database retrieval
  • the data to be retrieved at this time is a relational database of a limited hierarchy type.
  • the first Affiliation organization ID query the first organization equipment information table according to the first affiliation organization ID, determine the equipment data corresponding to the first affiliation organization ID and the corresponding hierarchical tree branch ID, and then query the plane hierarchical tree information table according to the hierarchical tree branch ID , determine the corresponding hierarchical tree branch data, that is, the above-mentioned entire hierarchical tree branch from the province to the bottom village, and finally establish the association between each hierarchical tree branch data and equipment data to obtain the first target hierarchical data.
  • the branch data of the hierarchical tree After obtaining the branch data of the hierarchical tree, you can put the branch data of the hierarchical tree, all the device data under the branch and the corresponding branch ID of the hierarchical tree into a record, and the device data can be used as a collection type field to form the branch data of the branch ID of the hierarchical tree A property of an object.
  • the affiliation information includes a second affiliation organization ID and a superior node ID
  • the relational database includes a tree node information table, a tree node association relationship table, and a second organization equipment association information table; when the database hierarchy type is non-
  • step 204 may include the following sub-steps:
  • the retrieval type is a relational database retrieval, query the equipment information table of the second organization according to the ID of the second affiliation organization, and determine the corresponding equipment data, upper node ID and hierarchical tree node ID;
  • the tree nodes corresponding to each tree node ID are associated according to the first node association relationship, and the association between the superior node ID and the device data is established to obtain the first target level data.
  • the database hierarchy type is an unrestricted hierarchy type and the retrieval type is a relational database retrieval
  • the relational database to be retrieved at this time is an unrestricted hierarchy type
  • the second affiliation organization ID can be queried.
  • Organization equipment information table determine the equipment data associated with the second affiliation organization ID, superior node ID and hierarchical tree node ID; then use the superior node ID and hierarchical tree node ID to retrieve the tree node information table to determine the hierarchical tree node ID All the tree node IDs of the entire hierarchical tree where the corresponding tree nodes are located, and then respectively retrieve the tree node association relationship table according to each tree node ID, to determine the first node association relationship between the tree nodes corresponding to each tree node ID, according to the The first node association relationship associates the tree nodes corresponding to each tree node ID and establishes an association between the superior node ID and the device data to obtain the first target hierarchical data.
  • the ES index library in order to ensure the stability and accuracy of the index library, is usually built after establishing a certain scale relational database and running for a period of time. At the same time, in order to realize the periodic update of the ES index library, you can Execute the preset configuration file according to the preset update cycle, perform field conversion on the relational data in the relational database to obtain the corresponding ES index field, and then synchronize the ES index field to the ES index library.
  • the data synchronization of the ES index library can be realized through the following steps S11-S15 or steps S21-S26:
  • the Chinese region name needs to be modified in ib/logstash/filters/geoip.rb under the logstash installation directory for each obtained region name
  • ib/logstash/filters/geoip.rb under the logstash installation directory for each obtained region name
  • the IP address information here is saved in a csv file, so you can also maintain your own address library, and you can also call the IP analysis service through the ruby code in geoip.rb to obtain relevant Chinese area information ;
  • the open source data synchronization tool canal can be well decoupled from the business system because it directly operates MySQL's binlog, and its operation puts very little pressure on MySQL.
  • a hierarchical tree branch has not been fully formed Synchronizing it to ES will only increase useless ES update operations. Due to differences in business rules, it is common for business entity data in different states not to be fully synchronized.
  • data processing and verification may require querying other Database or ES, so you need to control the incremental synchronization of data through the canal client.
  • Figure 3 The steps are as follows:
  • the table can be constructed in the following ways:
  • the ES index library of unrestricted hierarchical type may include but not limited to node information index table, flat hierarchical tree index table and first organization device association index table.
  • the flat hierarchical tree index table may be shown in Table 4 below:
  • fields that need to be searched for business can also be added to the index, such as the geographic location of the device, device name, device label, device capability, etc.
  • the first agency equipment association index table may be shown in Table 5 below:
  • special query annotations can be encapsulated for specific types of queries in ES.
  • a new annotation FuzzyQuery and its processing flow can be encapsulated according to the implementation and processing flow of Query annotations, specifying the query that needs to be queried
  • the field, the identification of the corresponding parameter value, and the logical relationship between the fields when assembling are processed by logical AND by default, and the parameters in the method where the FuzzyQuery annotation of the Repository interface is directly replaced in order at runtime; the specified return field list or For the list of fields to be excluded, directly generate the corresponding content through string processing in the painless script of the query request, and keep the same effect as the Query annotation in other respects.
  • the specific construction of the flat hierarchical tree index table is similar to the above table 4, and the node information index table can be shown in the following table 6:
  • the second agency equipment association index table may be shown in Table 7 below:
  • the affiliation information includes a third organization affiliation ID
  • the ES index library includes a flat hierarchical tree index table and a first organization equipment association index table
  • step 205 may include the following Substeps:
  • the retrieval type is indexed database retrieval
  • the data retrieval request is parsed to obtain the search condition and the target data format
  • the attribution ID of the third organization retrieve the organization's equipment association index table, and determine the corresponding equipment data
  • the association between the hierarchical tree information and the equipment data is established and converted into the target data format to obtain the second target hierarchical data.
  • Search criteria refer to data restriction information that may not be exactly the same as the fields in the ES index library but is related.
  • the target data format refers to the hierarchical tree data required by the client or the unique data format of the client.
  • the data retrieval request may be parsed to obtain the search conditions and the target data format.
  • the search conditions and the affiliation ID of the third organization asynchronously search from the organization equipment management index table and the flat hierarchical tree index table to determine the equipment data corresponding to the third organization affiliation ID and the hierarchical tree information that meets the search conditions; and then establish a hierarchy
  • the association between the tree information and the device data is converted into the target data format to obtain the second target level data.
  • the retrieval query of the ES index library can be realized through the following steps S31-S34:
  • the user obtains the attribution ID of the third organization from the cache, and if not found, first queries the relational database MySQL, updates the cache, and then continues;
  • S32 Asynchronously search for eligible data from the institutional device management index table and the flat hierarchical tree index table according to the third organization's affiliation ID and search conditions, and obtain hierarchical tree information and device data that meet the search conditions as search results;
  • the node information of the tree and the relationship between the nodes of the plane hierarchical tree are respectively stored in different indexes, then asynchronously and simultaneously Search the institutional equipment management index table and the flat hierarchical tree index table to obtain the search results.
  • you do not need to assemble the search results into tree data you can directly return the results requested by the client, otherwise you can query MySQL again through the cache to obtain the tree node relationship data, and finally the application service assembles the result data into the required data from the client. returned after the data.
  • the affiliation information includes a fourth organization affiliation ID
  • the ES index library includes a tree node information index table and a second organization equipment association index table
  • retrieval type is index database retrieval
  • the tree nodes corresponding to the tree node IDs of each hierarchy are associated according to the second node association relationship, and the association with the device data is established to obtain the second target hierarchy data.
  • the retrieval type is index database retrieval and the index database is an unrestricted hierarchical type
  • the data retrieval request is parsed to obtain the search conditions
  • the second organization's equipment association index table is retrieved according to the fourth organization's attribution ID, and the corresponding Device data and the branch ID of the hierarchical tree to which it belongs
  • search the tree node information index table according to the search conditions, and obtain multiple hierarchical tree node IDs that meet the search conditions
  • Step 206 return the first target level data or the second target level data to the client.
  • step 206 is similar to that of step 106, and will not be repeated here.
  • Step 207 when receiving the device reallocation request sent by the additional client, create an additional user identifier corresponding to the additional client;
  • Step 208 determine the corresponding additional device data according to the device reallocation request
  • Step 209 establishing the association between the additional user identifier and the additional device data, obtaining an additional ES index table and saving it to the ES index library.
  • the client is usually under a certain organization, and the same organization can include multiple client terminals at the same time, but due to business requirements, it may be necessary to allocate equipment for a single user.
  • the additional client when receiving When the device reallocation request is sent by the additional client, create an additional user ID corresponding to the additional client, and determine the additional device data required by the additional client according to the device reallocation request, such as device name, device ID, and device location , device label, device capability, etc., and then establish the association between the additional user identifier and the additional device data to obtain the additional ES index table.
  • the additional ES index table can be saved to the ES index library.
  • Table 8 shows an additional ES index table of the embodiment of the present invention:
  • the user's role or the above attribute data of the user are respectively extracted from the database when the user logs in, and then cached in the Redis cluster.
  • the subsequent user initiates a search request, it can be judged based on the value of the cached data that the corresponding Users search this part of the index, so as to realize the control of user data permissions synchronously.
  • the device data can be updated in the following ways: There are two main technical methods for the perception of device going offline events: Based on the establishment and disconnection of the socket through the TCP/IP communication connection, based on the reported data of the device heartbeat, the latter will receive the heartbeat data of the device regularly and if it has not been received after a certain period of time, it will be considered that the device has been offline. Both require a dedicated device access service, which can receive device communication requests through the MQTT protocol, a custom protocol based on Netty, or even a device heartbeat request of the HTTP protocol.
  • the device access service instance can first save the device id (continuously increasing number) and its status in the memory through ConcurrentHashMap, and then confirm the device When the connection is established or disconnected, or when the device heartbeat request is received, or the device request is not received after a timeout, set the device online status to true and false respectively.
  • ConcurrentHashMap When multiple devices have status changes at the same time, directly call ConcurrentHashMap concurrently through multiple threads
  • the put() method can modify the state of the corresponding device id.
  • the application service instance in the device access service cluster regularly refreshes these data to the multi-master and multi-slave Redis cluster at regular intervals (the interval is allowed to be configured), and Redis saves the online status of the device through its bitset, and the master instance of each Redis.
  • the key of the bitset is the id of the branch of the hierarchical tree; when the maximum number of levels is not limited, the key is the id of the device next to the upper node. If the id changes, the key cached here needs to be updated synchronously.
  • a group of tree branch ids or device IDs of adjacent nodes can be sent in batches through the pipeline mechanism of Redis to obtain the total number of online devices of a key through BITCOUNT, and then the application The service assembles the resulting data and returns it. If the user can only access some devices under one node, the Redis pipeline mechanism can be used to send batches of commands to get the online status of a device id through GETBIT, and the device corresponding to the table name of 1 is returned online, and then accumulated in the application service memory The total number of online devices is returned to the client.
  • the total number of devices of each node can be queried in the database and cached in the Redis cluster for subsequent query of the total number of devices under the node to be obtained directly from the cache.
  • the id of the tree branch or node can be used as the key through hash, and the total number of devices can be stored as an attribute.
  • the hash value of the corresponding key can be added or subtracted.
  • the total device data of any key in Redis is found to be empty, the data is loaded from the data source and cached in the hash of Redis.
  • the implementation effect of the user-side hierarchical tree is to open the hierarchical tree step by step, and only open the first-level nodes at the beginning by default, then the implementation is simpler: as long as the user double-clicks to open a node, directly open the next-level tree node,
  • the number of online devices can be obtained directly from Redis through the BITCOUNT command according to the id of this node. If the user can only access some of the devices, obtain the online status of each device from Redis in batches through the pipeline and accumulate them in memory. The result of accumulating the devices owned by the user is the total number of the current node. Number of online devices. Since the whole process is mainly carried out in memory, and the good scalability and availability of Redis multi-resident multi-slave cluster, the calculation of the number of online devices can not only be performed in real time, but also have better performance.
  • the user identifier corresponding to the client is obtained; the attribution information corresponding to the user identifier is queried from a preset database, and the database hierarchy type corresponding to the user identifier is determined;
  • the retrieval type corresponding to the data retrieval request if the retrieval type is a relational database retrieval, then retrieve the relational database corresponding to the database hierarchy type according to the attribution information, and obtain the first target level data; if the retrieval If the type is index database retrieval, then according to the data retrieval request and the ES index library corresponding to the attribution information retrieval database level type, obtain the second target level data; return the first target level data or the second target level data to the client.
  • hierarchical tree data can be obtained through one SQL statement or several queries. Furthermore, the efficiency of the data retrieval process under the amount of hundreds of millions of users is more effectively improved.
  • FIG. 5 is a structural block diagram of a hierarchical data retrieval device provided by Embodiment 3 of the present invention.
  • An embodiment of the present invention provides a hierarchical data retrieval device, including:
  • the user identification acquisition module 501 is configured to obtain a user identification corresponding to the user terminal in response to a login request sent by any user terminal;
  • a database hierarchy type determining module 502 configured to query the attribution information corresponding to the user identifier from a preset database, and determine the database hierarchy type corresponding to the user identifier;
  • a retrieval type obtaining module 503, configured to obtain the retrieval type corresponding to the data retrieval request when receiving the data retrieval request sent by the client;
  • a relational data retrieval module 504 configured to retrieve the relational database corresponding to the database hierarchy type according to the attribution information if the retrieval type is a relational database retrieval, to obtain the first target hierarchical data;
  • the index data retrieval module 505 is used for if the retrieval type is an index database retrieval, then according to the data retrieval request and the ES index library corresponding to the attribution information retrieval database hierarchy type, obtain the second target hierarchy data;
  • Hierarchical data return module 506, used to return the first target hierarchical data or the second target hierarchical data to the client.
  • the database hierarchy type determination module 502 is specifically used for:
  • the affiliation information includes the first affiliation organization ID
  • the relational database includes a plane hierarchical tree information table and a first organization equipment association information table; when the database hierarchy type is a limited hierarchy type, the relational data retrieval module 504 is specifically used for:
  • the retrieval type is a relational database retrieval, query the equipment information table of the first organization according to the ID of the first affiliation organization, and determine the corresponding equipment data and the branch ID of the hierarchical tree;
  • An association between branch data of each hierarchical tree and device data is established to obtain the first target hierarchical data.
  • the affiliation information includes a second affiliation organization ID and a superior node ID
  • the relational database includes a tree node information table, a tree node association relationship table and a second organization equipment association information table; when the database hierarchy type is an unrestricted hierarchy type,
  • the relational data retrieval module 504 is specifically used for:
  • the retrieval type is a relational database retrieval, query the equipment information table of the second organization according to the ID of the second affiliation organization, and determine the corresponding equipment data, upper node ID and hierarchical tree node ID;
  • the tree nodes corresponding to each tree node ID are associated according to the first node association relationship, and the association between the superior node ID and the device data is established to obtain the first target level data.
  • the affiliation information includes a third organization affiliation ID
  • the ES index storehouse includes a flat hierarchical tree index table and a first organization equipment association index table
  • the index data retrieval module 505 includes:
  • the retrieval type is indexed database retrieval
  • the data retrieval request is parsed to obtain the search condition and the target data format
  • the attribution ID of the third organization retrieve the organization's equipment association index table, and determine the corresponding equipment data
  • the association between the hierarchical tree information and the equipment data is established and converted into the target data format to obtain the second target hierarchical data.
  • the affiliation information includes a fourth organization affiliation ID
  • the ES index library includes a tree node information index table and a second organization equipment association index table
  • the index data retrieval module 505 includes:
  • retrieval type is index database retrieval
  • each hierarchical tree node ID respectively retrieve the second mechanism equipment association index table, and determine the second node association relationship corresponding to each hierarchical tree node ID;
  • the tree nodes corresponding to the tree node IDs of each hierarchy are associated according to the second node association relationship, and the association with the device data is established to obtain the second target hierarchy data.
  • the device also includes:
  • a user identification creation module configured to create an additional user identification corresponding to the additional user end when receiving a device reallocation request sent by the additional user end;
  • An additional equipment data determining module configured to determine corresponding additional equipment data according to the equipment reallocation request
  • the association establishing module is used to establish the association between the additional user identification and the additional device data, obtain the additional ES index table and save it to the ES index library.
  • the device also includes:
  • the field conversion module is used to execute the preset configuration file according to the preset update cycle, perform field conversion on the relational data in the relational database, and obtain the ES index field;
  • the field synchronization module is used to synchronize the ES index fields to the ES index library.
  • An embodiment of the present invention also provides an electronic device, including a memory and a processor, and a computer program is stored in the memory.
  • the processor executes the hierarchical data retrieval method according to any embodiment of the present invention. step.
  • the disclosed devices and methods can be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the units is only a logical function division. In actual implementation, there may be other division methods.
  • multiple units or components can be combined or May be integrated into another system, or some features may be ignored, or not implemented.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • each functional unit in each embodiment of the present invention may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
  • the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.
  • the computer software product is stored in a storage medium , including several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in each embodiment of the present invention.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disc, etc., which can store program codes. .

Abstract

Provided are a hierarchical data retrieval method and apparatus, and a device. The method comprises: in response to a login request sent by any user end, acquiring a user identifier corresponding to the user end (101); querying, from a preset database, attribution information corresponding to the user identifier, and determining a database hierarchical type corresponding to the user identifier (102); when a data retrieval request sent by the user end is received, acquiring a retrieval type corresponding to the data retrieval request (103); if the retrieval type is relational database retrieval, retrieving, according to the attribution information, a relational database corresponding to the database hierarchical type, so as to obtain first target hierarchical data (104); if the retrieval type is index database retrieval, retrieving, according to the data retrieval request and the attribution information, an ES index database corresponding to the database hierarchical type, so as to obtain second target hierarchical data (105); and returning the first target hierarchical data or the second target hierarchical data to the user end (106). On the basis of simplifying a retrieval architecture and a retrieval path, the efficiency of a data retrieval process for hundreds of millions of users is effectively improved.

Description

一种层次数据检索方法、装置和设备A Hierarchical Data Retrieval Method, Device and Equipment 技术领域technical field
本发明涉及数据检索技术领域,尤其涉及一种层次数据检索方法、装置和设备。The invention relates to the technical field of data retrieval, in particular to a hierarchical data retrieval method, device and equipment.
背景技术Background technique
层次数据,也叫目录树,在UI上类似Windows的资源管理器,指的是通过树形结构逐层存储的数据。其管理、搜索、分析是互联网业务中的常见需求,例如企业的各层级的部门及其员工以及员工之间上下级数据的管理、存储和查询;多层次商品类别、商品及相关企业和用户数据的管理和查询;物联网业务中的多层次地域及其包含的设备、设备生产企业及设备投入使用后所属的企业、用户数据的管理、搜索等,数据的层次可以有十几级甚至不限,对应的数据量可能达到百万级甚至更大;视联网业务中的多层次视频类别、视频搜索、用户数据的管理、搜索等,对应的数据量可达到亿级甚至更大。这些需求涉及到的用户及管理员(包括区域管理员)往往需要不同的数据权限。Hierarchical data, also called directory tree, is similar to Windows Explorer on the UI, and refers to data stored layer by layer through a tree structure. Its management, search, and analysis are common needs in Internet business, such as the management, storage, and query of departments at all levels of the enterprise and their employees, as well as the upper and lower levels of data between employees; multi-level commodity categories, commodities, and related enterprise and user data management and query; the management and search of multi-level regions in the Internet of Things business and the equipment, equipment manufacturers and enterprises to which the equipment belongs after the equipment is put into use, user data, etc., the data level can have more than ten levels or even unlimited , the corresponding data volume may reach one million or even greater; the corresponding data volume of multi-level video categories, video search, user data management, search, etc. in the Internet of View business may reach billions or even greater. Users and administrators (including regional administrators) involved in these requirements often require different data permissions.
为此,传统的层次数据存储和搜索的方法通常是采用关系数据库MySQL、Oracle或Microsoft SQL Server来保存层次数据;或者是采用字段记录层次关系的方式进行存储和检索查询。For this reason, traditional hierarchical data storage and search methods usually use relational database MySQL, Oracle or Microsoft SQL Server to store hierarchical data; or use field records to store and retrieve hierarchical relationships.
但随着亿级用户量的互联网业务的不断扩大,层次树实体数据之间的关联会的数据量会进一步增加,按照传统关系数据库理论构建的层次数据管理、搜索服务,常见的表设计方案只能循环或者递归地用Java等编程语言从数据库查询,而且层次树越多,循环次数或递归的层次越深;且由于应用系统、数据库往往运行在不同的服务器上,每次访问数据库时都会经过网络通信、数据库服务器内部的处理、硬盘I/O交互等过程,在数据量和并发量较大的情况下系统响应缓慢且难以提供大规模的并发访问,从而导致层次数据的搜索效率降低,无 法满足互联网业务发展需求。However, with the continuous expansion of Internet services with hundreds of millions of users, the amount of data associated with hierarchical tree entity data will further increase. For hierarchical data management and search services constructed according to traditional relational database theory, the common table design scheme is only It can loop or recursively use Java and other programming languages to query from the database, and the more hierarchical trees, the deeper the number of loops or the level of recursion; and because the application system and database often run on different servers, each access to the database will go through In the process of network communication, database server internal processing, hard disk I/O interaction and other processes, the system responds slowly and it is difficult to provide large-scale concurrent access when the amount of data and concurrency are large, which leads to a decrease in the search efficiency of hierarchical data and cannot Meet the needs of Internet business development.
发明内容Contents of the invention
本发明提供了一种层次数据检索方法、装置和设备,解决了传统的层次数据检索方法由于其架构和检索路径的限制,在亿级用户量的互联网业务搜索过程中的检索效率较低,无法满足互联网业务发展需求的技术问题。The present invention provides a hierarchical data retrieval method, device and equipment, which solves the problem that the traditional hierarchical data retrieval method has low retrieval efficiency in the Internet business search process with hundreds of millions of users due to the limitation of its structure and retrieval path. Technical issues that meet the needs of Internet business development.
本发明第一方面提供的一种层次数据检索方法,包括:A hierarchical data retrieval method provided by the first aspect of the present invention includes:
响应于任一用户端发送的登录请求,获取所述用户端对应的用户标识;In response to a login request sent by any client, obtain the user ID corresponding to the client;
从预设数据库中查询所述用户标识对应的归属信息,并确定所述用户标识对应的数据库层级类型;Querying the attribution information corresponding to the user identifier from a preset database, and determining the database hierarchy type corresponding to the user identifier;
当接收所述用户端发送的数据检索请求时,获取所述数据检索请求对应的检索类型;When receiving the data retrieval request sent by the client, obtain the retrieval type corresponding to the data retrieval request;
若所述检索类型为关系数据库检索,则根据所述归属信息检索所述数据库层级类型对应的关系数据库,得到第一目标层次数据;If the search type is a relational database search, then search the relational database corresponding to the database level type according to the attribution information to obtain the first target level data;
若所述检索类型为索引数据库检索,则根据所述数据检索请求与所述归属信息检索所述数据库层级类型对应的ES索引库,得到第二目标层次数据;If the retrieval type is index database retrieval, then according to the data retrieval request and the attribution information, retrieve the ES index database corresponding to the database hierarchy type to obtain the second target hierarchy data;
返回所述第一目标层次数据或所述第二目标层次数据至所述用户端。returning the first target level data or the second target level data to the client.
可选地,所述从预设数据库中查询所述用户标识对应的归属信息,并确定所述用户标识对应的数据库层级类型的步骤,包括:Optionally, the step of querying the attribution information corresponding to the user identifier from a preset database, and determining the database hierarchy type corresponding to the user identifier includes:
按照所述用户标识检索预设数据库,获取所述用户标识对应的归属信息并缓存;Retrieving a preset database according to the user ID, obtaining attribution information corresponding to the user ID and caching it;
判断所述归属信息是否包含上级节点ID;judging whether the attribution information includes a superior node ID;
若否,则判定所述用户标识对应的数据库层级类型为限定层级类型;If not, then determine that the database hierarchy type corresponding to the user identifier is a limited hierarchy type;
若是,则判定所述用户标识对应的数据库层级类型为非限定层级类型。If yes, it is determined that the database hierarchy type corresponding to the user identifier is an unrestricted hierarchy type.
可选地,所述归属信息包括第一归属机构ID,所述关系数据库包括平面层级树信息表和第一机构设备关联信息表;当所述数据库层级类型为限定层级类型时,所述若所述检索类型为关系数据库检索,则根据所述归属信息检索所述数据库层级类型对应的关系数据库,得到第一目标层次数据的步骤,包括:Optionally, the affiliation information includes a first affiliation organization ID, and the relational database includes a plane hierarchical tree information table and a first organization equipment association information table; when the database hierarchy type is a limited hierarchy type, the if If the retrieval type is a relational database retrieval, then the relational database corresponding to the database hierarchy type is retrieved according to the attribution information, and the step of obtaining the first target hierarchy data includes:
若所述检索类型为关系数据库检索,则按照所述第一归属机构ID查询所述第一机构设备信息表,确定对应的设备数据以及层级树分支ID;If the retrieval type is a relational database retrieval, then query the equipment information table of the first organization according to the ID of the first affiliation organization, and determine the corresponding equipment data and the branch ID of the hierarchical tree;
按照所述层级树分支ID查询所述平面层级树信息表,确定对应的层级树分支数据;Querying the flat hierarchical tree information table according to the hierarchical tree branch ID to determine the corresponding hierarchical tree branch data;
建立每个所述层级树分支数据与所述设备数据之间的关联,得到第一目标层次数据。An association between each branch data of the hierarchical tree and the device data is established to obtain first target hierarchical data.
可选地,所述归属信息包括第二归属机构ID和所述上级节点ID,所述关系数据库包括树节点信息表、树节点关联关系表和第二机构设备关联信息表;当所述数据库层级类型为非限定层级类型时,所述若所述检索类型为关系数据库检索,则根据所述归属信息检索所述数据库层级类型对应的关系数据库,得到第一目标层次数据的步骤,包括:Optionally, the affiliation information includes a second affiliation organization ID and the superior node ID, and the relational database includes a tree node information table, a tree node association relationship table, and a second organization equipment association information table; when the database level When the type is an unrestricted hierarchical type, if the retrieval type is a relational database retrieval, the step of retrieving the relational database corresponding to the database hierarchical type according to the attribution information to obtain the first target hierarchical data includes:
若所述检索类型为关系数据库检索,则按照所述第二归属机构ID查询所述第二机构设备信息表,确定对应的设备数据、所述上级节点ID以及层级树节点ID;If the retrieval type is a relational database retrieval, then query the equipment information table of the second organization according to the ID of the second affiliation organization, and determine the corresponding equipment data, the ID of the superior node and the node ID of the hierarchical tree;
采用所述上级节点ID和所述层级树节点ID检索所述树节点信息表,确定关联的全部树节点ID;Retrieving the tree node information table by using the superior node ID and the hierarchical tree node ID to determine all associated tree node IDs;
按照各个所述树节点ID分别检索所述树节点关联关系表,得到各个所述树节点ID分别对应的第一节点关联关系;Retrieving the tree node association relationship table according to each of the tree node IDs to obtain the first node association relationship corresponding to each of the tree node IDs;
按照所述第一节点关联关系关联各个所述树节点ID对应的树节点并建立所述上级节点ID与所述设备数据之间的关联,得到第一目标层次数据。Associating the tree nodes corresponding to each of the tree node IDs according to the first node association relationship and establishing an association between the upper-level node ID and the device data to obtain first target hierarchical data.
可选地,所述归属信息包括第三机构归属ID;所述ES索引库包括平面层级树索引表和第一机构设备关联索引表;当所述数据库层级类型为限定层级类型时,所述若所述检索类型为索引数据库检索,则根据所述数据检索请求与所述归属信息检索所述数据库层级类型对应的ES索引库,得到第二目标层次数据的步骤,包括:Optionally, the affiliation information includes a third organization affiliation ID; the ES index library includes a flat hierarchical tree index table and a first organization equipment association index table; when the database hierarchy type is a limited hierarchy type, the if The retrieval type is an index database retrieval, then according to the data retrieval request and the attribution information, retrieve the ES index database corresponding to the database hierarchy type, and obtain the second target hierarchy data, including:
若所述检索类型为索引数据库检索,则解析所述数据检索请求得到搜索条件和目标数据格式;If the retrieval type is an index database retrieval, then parsing the data retrieval request to obtain a search condition and a target data format;
按照所述第三机构归属ID检索所述机构设备关联索引表,确定对应的设备 数据;Retrieve the organization equipment association index table according to the third organization attribution ID, and determine the corresponding equipment data;
按照所述搜索条件搜索所述平面层级树索引表,确定对应的层级树信息;Search the flat hierarchical tree index table according to the search condition, and determine the corresponding hierarchical tree information;
建立所述层级树信息与所述设备数据之间的关联并转换为所述目标数据格式,得到第二目标层次数据。Establishing the association between the hierarchical tree information and the device data and converting it into the target data format to obtain second target hierarchical data.
可选地,所述归属信息包括第四机构归属ID,所述ES索引库包括树节点信息索引表和第二机构设备关联索引表;当所述数据库层级类型为非限定层级类型时,所述若所述检索类型为索引数据库检索,则根据所述数据检索请求与所述归属信息检索所述数据库层级类型对应的ES索引库,得到第二目标层次数据的步骤,包括:Optionally, the affiliation information includes a fourth organization affiliation ID, and the ES index library includes a tree node information index table and a second organization equipment association index table; when the database hierarchy type is an unrestricted hierarchy type, the If the retrieval type is index database retrieval, then according to the data retrieval request and the attribution information, retrieve the ES index database corresponding to the database hierarchy type, and obtain the second target hierarchy data, including:
若所述检索类型为索引数据库检索,则解析所述数据检索请求得到搜索条件;If the retrieval type is an index database retrieval, then parsing the data retrieval request to obtain a search condition;
按照所述第四机构归属ID检索所述第二机构设备关联索引表,确定对应的设备数据和所属层次树分支ID;Retrieving the second organization's equipment association index table according to the fourth organization's attribution ID, and determining the corresponding equipment data and the hierarchical tree branch ID to which it belongs;
按照所述搜索条件搜索所述树节点信息索引表,得到多个符合所述搜索条件的层次树节点ID;Searching the tree node information index table according to the search condition to obtain a plurality of hierarchical tree node IDs meeting the search condition;
按照各个所述层次树节点ID分别检索所述第二机构设备关联索引表,确定各个所述层次树节点ID对应的第二节点关联关系;Retrieving the second organization equipment association index table according to each of the hierarchical tree node IDs, and determining the second node association relationship corresponding to each of the hierarchical tree node IDs;
按照所述第二节点关联关系关联各个所述层次树节点ID对应的树节点,并建立与所述设备数据之间的关联,得到第二目标层次数据。The tree nodes corresponding to each of the hierarchical tree node IDs are associated according to the second node association relationship, and an association with the device data is established to obtain second target hierarchical data.
可选地,还包括:Optionally, also include:
当接收到额外用户端发送的设备再分配请求时,创建与所述额外用户端对应的额外用户标识;When receiving the device reallocation request sent by the additional client, creating an additional user identifier corresponding to the additional client;
按照所述设备再分配请求确定对应的额外设备数据;determining corresponding additional device data according to the device reallocation request;
建立所述额外用户标识与所述额外设备数据之间的关联,得到额外ES索引表并保存至所述ES索引库。An association between the additional user identifier and the additional device data is established, and an additional ES index table is obtained and stored in the ES index library.
可选地,还包括:Optionally, also include:
按照预设的更新周期执行预设的配置文件,对所述关系数据库内的关系数据进行字段转换,得到ES索引字段;Executing a preset configuration file according to a preset update cycle, performing field conversion on the relational data in the relational database, and obtaining ES index fields;
将所述ES索引字段同步至所述ES索引库。Synchronize the ES index field to the ES index library.
本发明第二方面提供了一种层次数据检索装置,包括:The second aspect of the present invention provides a hierarchical data retrieval device, including:
用户标识获取模块,用于响应于任一用户端发送的登录请求,获取所述用户端对应的用户标识;A user identification acquisition module, configured to obtain a user identification corresponding to the user terminal in response to a login request sent by any user terminal;
数据库层级类型确定模块,用于从预设数据库中查询所述用户标识对应的归属信息,并确定所述用户标识对应的数据库层级类型;A database hierarchy type determining module, configured to query the attribution information corresponding to the user identifier from a preset database, and determine the database hierarchy type corresponding to the user identifier;
检索类型获取模块,用于当接收所述用户端发送的数据检索请求时,获取所述数据检索请求对应的检索类型;A retrieval type acquisition module, configured to obtain the retrieval type corresponding to the data retrieval request when receiving the data retrieval request sent by the client;
关系数据检索模块,用于若所述检索类型为关系数据库检索,则根据所述归属信息检索所述数据库层级类型对应的关系数据库,得到第一目标层次数据;A relational data retrieval module, configured to retrieve the relational database corresponding to the database hierarchy type according to the attribution information if the retrieval type is a relational database retrieval, to obtain the first target hierarchical data;
索引数据检索模块,用于若所述检索类型为索引数据库检索,则根据所述数据检索请求与所述归属信息检索所述数据库层级类型对应的ES索引库,得到第二目标层次数据;An index data retrieval module, configured to retrieve the ES index library corresponding to the database hierarchy type according to the data retrieval request and the attribution information if the retrieval type is index database retrieval, to obtain second target hierarchical data;
层次数据返回模块,用于返回所述第一目标层次数据或所述第二目标层次数据至所述用户端。A hierarchical data returning module, configured to return the first target hierarchical data or the second target hierarchical data to the client.
本发明第三方面还提供了一种电子设备,包括存储器及处理器,所述存储器中储存有计算机程序,所述计算机程序被所述处理器执行时,使得所述处理器执行如本发明第一方面任一项所述的层次数据检索方法的步骤。The third aspect of the present invention also provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor is executed as described in the first aspect of the present invention. In one aspect, the steps of the hierarchical data retrieval method described in any one aspect.
从以上技术方案可以看出,本发明具有以下优点:As can be seen from the above technical solutions, the present invention has the following advantages:
本发明通过响应于任一用户端发送的登录请求,获取用户端对应的用户标识;从预设数据库中查询用户标识对应的归属信息,并确定用户标识对应的数据库层级类型;当接收用户端发送的数据检索请求时,获取数据检索请求对应的检索类型;若检索类型为关系数据库检索,则根据归属信息检索数据库层级类型对应的关系数据库,得到第一目标层次数据;若检索类型为索引数据库检索,则根据数据检索请求与归属信息检索数据库层级类型对应的ES索引库,得到第二目标层次数据;返回第一目标层次数据或第二目标层次数据至用户端。从而通过划分检索类型和数据库层级类型,在简化检索架构和检索路径的基础上,经数据库设计和ES搜索库设计互相配合,可以通过一个SQL语句或是数 次查询的方式获取到层次树数据,进而更为有效地提高了亿级用户量下数据检索过程的效率。The present invention obtains the user identification corresponding to the user terminal by responding to a login request sent by any user terminal; queries the attribution information corresponding to the user identification from a preset database, and determines the database hierarchy type corresponding to the user identification; When a data retrieval request is made, obtain the retrieval type corresponding to the data retrieval request; if the retrieval type is a relational database retrieval, retrieve the relational database corresponding to the database hierarchy type according to the attribution information, and obtain the first target hierarchical data; if the retrieval type is an index database retrieval , then according to the data retrieval request and the ES index library corresponding to the attribution information search database level type, obtain the second target level data; return the first target level data or the second target level data to the client. Therefore, by dividing the retrieval type and database hierarchy type, on the basis of simplifying the retrieval structure and retrieval path, through the cooperation of database design and ES search library design, hierarchical tree data can be obtained through one SQL statement or several queries. Furthermore, the efficiency of the data retrieval process under the amount of hundreds of millions of users is more effectively improved.
附图说明Description of drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其它的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only These are some embodiments of the present invention. For those skilled in the art, other drawings can also be obtained according to these drawings on the premise of not paying creative efforts.
图1为本发明实施例一提供的一种层次数据检索方法的步骤流程图;FIG. 1 is a flow chart of the steps of a hierarchical data retrieval method provided by Embodiment 1 of the present invention;
图2为本发明实施例二提供的一种层次数据检索方法的步骤流程图;FIG. 2 is a flow chart of steps of a hierarchical data retrieval method provided by Embodiment 2 of the present invention;
图3为本发明实施例提供的一种层次数据数据的增量同步过程的步骤流程图;FIG. 3 is a flow chart of steps for an incremental synchronization process of hierarchical data provided by an embodiment of the present invention;
图4为本发明实施例提供的一种ES索引库的检索查询流程的步骤流程图;Fig. 4 is a flow chart of the steps of the retrieval query process of a kind of ES index library provided by the embodiment of the present invention;
图5为本发明实施例三提供的一种层次数据检索装置的结构框图。FIG. 5 is a structural block diagram of a hierarchical data retrieval device provided by Embodiment 3 of the present invention.
具体实施方式Detailed ways
本发明实施例提供了一种层次数据检索方法、装置和设备,用于解决传统的层次数据检索方法由于其架构和检索路径的限制,在亿级用户量的互联网业务搜索过程中的检索效率较低,无法满足互联网业务发展需求的技术问题。The embodiment of the present invention provides a hierarchical data retrieval method, device and equipment, which are used to solve the problem that the traditional hierarchical data retrieval method has low retrieval efficiency in the Internet business search process with hundreds of millions of users due to the limitation of its structure and retrieval path. Low, technical problems that cannot meet the needs of Internet business development.
为使得本发明的发明目的、特征、优点能够更加的明显和易懂,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,下面所描述的实施例仅仅是本发明一部分实施例,而非全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本发明保护的范围。In order to make the purpose, features and advantages of the present invention more obvious and understandable, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the following The described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.
请参阅图1,图1为本发明实施例一提供的一种层次数据检索方法的步骤流程图。Please refer to FIG. 1 . FIG. 1 is a flowchart of steps of a hierarchical data retrieval method provided by Embodiment 1 of the present invention.
本发明提供的一种层次数据检索方法,包括:A hierarchical data retrieval method provided by the present invention includes:
步骤101,响应于任一用户端发送的登录请求,获取用户端对应的用户标识; Step 101, in response to a login request sent by any client, obtain a user ID corresponding to the client;
用户标识指的是任一用户端在发送登录请求时,登录请求所携带的用户端 ID。User ID refers to the client ID carried in the login request when any client sends a login request.
在本发明实施例中,本装置响应于任一用户端发送的登录请求,并对登录请求进行登录验证,例如通过是用户端是否注册来判断该用户端是否拥有对应的登录权限等,若登录验证通过,则从登录请求获取该用户端对应的用户标识,以得到后续用户端查询层次数据的数据基础。In the embodiment of the present invention, the device responds to the login request sent by any client, and performs login verification on the login request, for example, whether the client has the corresponding login authority by checking whether the client is registered, etc., if the login If the verification is passed, the user ID corresponding to the client is obtained from the login request, so as to obtain the data basis for the subsequent client to query hierarchical data.
步骤102,从预设数据库中查询用户标识对应的归属信息,并确定用户标识对应的数据库层级类型; Step 102, query the attribution information corresponding to the user ID from the preset database, and determine the database hierarchy type corresponding to the user ID;
预设数据库指的是存储有用户端-机构关联表、层次树分支ID集合等信息的关系型数据库。The preset database refers to a relational database that stores information such as a client-organization association table, a hierarchical tree branch ID set, and the like.
归属信息指的是表示该用户标识与多个归属机构、用户类型和归属树分支之间的关联关系的信息,包括但不限于第一归属机构ID、第二归属机构ID、第三归属机构ID、第四归属机构ID和上级节点ID等信息。Affiliation information refers to the information indicating the association between the user ID and multiple affiliation organizations, user types and branches of the affiliation tree, including but not limited to the ID of the first affiliation organization, the ID of the second affiliation organization, and the ID of the third affiliation organization , the ID of the fourth affiliation organization, the ID of the superior node, and other information.
在获取到登录请求所携带的用户标识后,可以采用该用户标识作为检索字,在预设数据库中查询对应的归属信息,同时按照该用户标识结合登录请求,判断该用户标识所属的层次数据库的数据库层级类型。After obtaining the user ID carried in the login request, the user ID can be used as a search word to query the corresponding attribution information in the preset database, and at the same time, according to the user ID combined with the login request, the hierarchical database to which the user ID belongs can be judged Database hierarchy type.
步骤103,当接收用户端发送的数据检索请求时,获取数据检索请求对应的检索类型; Step 103, when receiving the data retrieval request sent by the client, obtain the retrieval type corresponding to the data retrieval request;
在确定用户标识对应的数据库层级类型后,若是接收到用户端发送的数据检索请求,则可以进一步响应该数据检索请求,获取其中对应的检索类型,以确定该数据检索请求所需要的检索方式,例如关系数据库检索或索引数据库检索等。After determining the database level type corresponding to the user ID, if the data retrieval request sent by the client is received, the data retrieval request can be further responded to, and the corresponding retrieval type can be obtained to determine the retrieval method required by the data retrieval request. For example, relational database retrieval or indexed database retrieval, etc.
步骤104,若检索类型为关系数据库检索,则根据归属信息检索数据库层级类型对应的关系数据库,得到第一目标层次数据; Step 104, if the search type is relational database search, search the relational database corresponding to the database level type according to the attribution information, and obtain the first target level data;
关系数据库指的是建立在关系数据库模型基础上的数据库,借助于集合代数等概念和方法来处理数据库中的数据,同时也是一个被组织成一组拥有正式描述性的表格,该形式的表格作用的实质是装载着数据项的特殊收集体,这些表格中的数据能以许多不同的方式被存取或重新召集而不需要重新组织数据库表格。关系数据库的定义造成元数据的一张表格或造成表格、列、范围和约束的正式描述。每个表格(有时被称为一个关系)包含用列表示的一个或更多的 数据种类。每行包含一个唯一的数据实体,这些数据是被列定义的种类。当创造一个关系数据库的时候,你能定义数据列的可能值的范围和可能应用于那个数据值的进一步约束。而SQL语言是标准用户和应用程序到关系数据库的接口。其优势是容易扩充,且在最初的数据库创造之后,一个新的数据种类能被添加而不需要修改所有的现有应用软件。主流的关系数据库有oracle、db2、sqlserver、sybase、mysql等。A relational database refers to a database built on the basis of a relational database model. It uses concepts and methods such as set algebra to process data in the database. It is also a set of tables organized into a formal descriptive table. Essence is a special collection of data items loaded with data in these tables that can be accessed or recalled in many different ways without reorganizing the database tables. The definition of a relational database results in a table of metadata or in a formal description of tables, columns, scopes and constraints. Each table (sometimes called a relation) contains one or more data types represented by columns. Each row contains a unique data entity of the type defined by the column. When creating a relational database, you can define the range of possible values for a data column and further constraints that may be applied to that data value. The SQL language is the interface of standard users and applications to relational databases. Its advantage is that it is easy to expand, and after the initial database creation, a new data type can be added without modifying all existing application software. The mainstream relational databases include oracle, db2, sqlserver, sybase, mysql, etc.
若是判定检索类型为关系数据库检索的情况下,由于数据检索请求中的数据请求已经由归属信息的形式提取得到,此时可以采用归属信息作为关键字或关键词,按照关系数据库检索的检索方式在数据库层级类型对应的关系数据库进行检索,以得到第一目标层次数据。If it is determined that the retrieval type is relational database retrieval, since the data request in the data retrieval request has been extracted in the form of attribution information, at this time, attribution information can be used as a keyword or keyword, and the retrieval method of relational database retrieval is in the The relational database corresponding to the database hierarchy type is retrieved to obtain the first target hierarchy data.
步骤105,若检索类型为索引数据库检索,则根据数据检索请求与归属信息检索数据库层级类型对应的ES索引库,得到第二目标层次数据; Step 105, if the retrieval type is index database retrieval, according to the data retrieval request and the ES index database corresponding to the attribution information retrieval database hierarchy type, the second target hierarchy data is obtained;
ES索引库指的是一个分布式、高扩展、高实时的搜索与数据分析引擎。用关系数据库的概念理解的话,ES的索引相当于关系数据库中的表,一个索引中可以包含多个不同数据类型的字段,只是ES的索引之间不能做表之间的关联。它能很方便的使大量数据具有搜索、分析和探索的能力。充分利用Elasticsearch的水平伸缩性,能使数据在生产环境变得更有价值。Elasticsearch的实现原理主要分为以下几个步骤,首先用户将数据提交到Elasticsearch数据库中,再通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据,当用户搜索数据时候,再根据权重将结果排名,打分,再将返回结果呈现给用户。The ES index library refers to a distributed, highly scalable, high real-time search and data analysis engine. Using the concept of relational databases, ES indexes are equivalent to tables in relational databases. An index can contain multiple fields of different data types, but ES indexes cannot be associated with tables. It can easily enable large amounts of data to be searched, analyzed and explored. Taking full advantage of the horizontal scalability of Elasticsearch can make data more valuable in the production environment. The implementation principle of Elasticsearch is mainly divided into the following steps. First, the user submits the data to the Elasticsearch database, and then uses the word segmentation controller to segment the corresponding sentence, and stores its weight and word segmentation results into the data. When the user searches for data At that time, the results will be ranked and scored according to the weight, and then the returned results will be presented to the user.
若是检索类型判定为索引数据库检索的情况下,表明此时的检索方式为模糊搜索或全文搜索,为提高后续搜索效率,可以基于数据检索请求所指定的搜索条件结合归属信息组成复合关键字或关键词,检索数据库层级类型对应的ES索引库,从而得到第二目标层次数据。If the retrieval type is judged to be indexed database retrieval, it indicates that the retrieval method at this time is fuzzy search or full-text search. In order to improve the efficiency of subsequent searches, compound keywords or key words can be formed based on the search conditions specified in the data retrieval request and attribution information. word, search the ES index database corresponding to the database hierarchy type, so as to obtain the second target hierarchy data.
步骤106,返回第一目标层次数据或第二目标层次数据至用户端。 Step 106, return the first target level data or the second target level data to the client.
在获取到第一目标层次数据或第二目标层次数据后,将其返回至用户端供用户端显示,使得用户能够进行层次数据的查阅。After the first target level data or the second target level data is acquired, it is returned to the client for display, so that the user can check the level data.
在本发明实施例中,通过响应于任一用户端发送的登录请求,获取用户端对应的用户标识;从预设数据库中查询用户标识对应的归属信息,并确定用户 标识对应的数据库层级类型;当接收用户端发送的数据检索请求时,获取数据检索请求对应的检索类型;若检索类型为关系数据库检索,则根据归属信息检索数据库层级类型对应的关系数据库,得到第一目标层次数据;若检索类型为索引数据库检索,则根据数据检索请求与归属信息检索数据库层级类型对应的ES索引库,得到第二目标层次数据;返回第一目标层次数据或第二目标层次数据至用户端。从而通过划分检索类型和数据库层级类型,在简化检索架构和检索路径的基础上,经数据库设计和ES搜索库设计互相配合,可以通过一个SQL语句或是数次查询的方式获取到层次树数据,进而更为有效地提高了亿级用户量下数据检索过程的效率。In the embodiment of the present invention, by responding to a login request sent by any client, the user identifier corresponding to the client is obtained; the attribution information corresponding to the user identifier is queried from a preset database, and the database hierarchy type corresponding to the user identifier is determined; When receiving the data retrieval request sent by the client, obtain the retrieval type corresponding to the data retrieval request; if the retrieval type is a relational database retrieval, then retrieve the relational database corresponding to the database hierarchy type according to the attribution information, and obtain the first target level data; if the retrieval If the type is index database retrieval, then according to the data retrieval request and the ES index library corresponding to the attribution information retrieval database level type, obtain the second target level data; return the first target level data or the second target level data to the client. Therefore, by dividing the retrieval type and database hierarchy type, on the basis of simplifying the retrieval structure and retrieval path, through the cooperation of database design and ES search library design, hierarchical tree data can be obtained through one SQL statement or several queries. Furthermore, the efficiency of the data retrieval process under the amount of hundreds of millions of users is more effectively improved.
请参阅图2,图2为本发明实施例二提供的一种层次数据检索方法的步骤流程图。Please refer to FIG. 2 . FIG. 2 is a flowchart of steps of a hierarchical data retrieval method provided by Embodiment 2 of the present invention.
本发明提供的一种层次数据检索方法,包括:A hierarchical data retrieval method provided by the present invention includes:
步骤201,响应于任一用户端发送的登录请求,获取用户端对应的用户标识; Step 201, in response to a login request sent by any client, obtain a user ID corresponding to the client;
在本发明实施例中,步骤201的具体实施过程与步骤101类似,在此不再赘述。In the embodiment of the present invention, the specific implementation process of step 201 is similar to step 101, and will not be repeated here.
步骤202,从预设数据库中查询用户标识对应的归属信息,并确定用户标识对应的数据库层级类型; Step 202, query the attribution information corresponding to the user ID from the preset database, and determine the database hierarchy type corresponding to the user ID;
可选地,步骤202可以包括以下子步骤:Optionally, step 202 may include the following sub-steps:
按照用户标识检索预设数据库,获取用户标识对应的归属信息并缓存;Retrieve the preset database according to the user ID, obtain the attribution information corresponding to the user ID and cache it;
判断归属信息是否包含上级节点ID;Determine whether the attribution information contains the superior node ID;
若否,则判定用户标识对应的数据库层级类型为限定层级类型;If not, determine that the database hierarchy type corresponding to the user identifier is a limited hierarchy type;
若是,则判定用户标识对应的数据库层级类型为非限定层级类型。If yes, it is determined that the database hierarchy type corresponding to the user identifier is an unrestricted hierarchy type.
在本发明实施例中,归属信息可以包括多种内容,为进一步提高后续检索效率,可以在得到用户标识后,可以按照用户标识对预设数据库进行查询,以获取到用户标识对应的归属信息并缓存。In the embodiment of the present invention, the attribution information may include various contents. In order to further improve the subsequent retrieval efficiency, after obtaining the user identification, the preset database may be queried according to the user identification to obtain the attribution information corresponding to the user identification and cache.
与此同时,解析归属信息判断其中是否包含有上级节点ID这一信息,若没有包含上级节点ID,则表明此时归属信息中的归属机构ID并不具有关联的上级节点ID,也就是说该用户标识所对应的数据库层级类型是有限的,此时可以判 定用户标识对应的数据库层级类型为限定层级类型;若是包含有上级节点ID,则表明此时归属信息中的归属机构ID具有关联的上级节点ID,层级数据是以节点信息、节点关联关系的形式存储,此时可以判定用户标识对应的数据库层级类型为非限定层级类型。At the same time, analyze the attribution information to judge whether it contains the information of the upper-level node ID. If it does not contain the upper-level node ID, it indicates that the affiliation organization ID in the attribution information does not have an associated upper-level node ID. The database hierarchy type corresponding to the user ID is limited. At this time, it can be determined that the database hierarchy type corresponding to the user ID is a limited hierarchy type; if it contains a superior node ID, it indicates that the affiliation organization ID in the attribution information at this time has an associated superior Node ID and hierarchical data are stored in the form of node information and node association relationship. At this time, it can be determined that the database hierarchical type corresponding to the user ID is an unrestricted hierarchical type.
值得一提的是,归属信息还可以包括用户类型,用于限定该用户端所属类型,例如用户端属于某一机构,用户端作为独立机构等本发明实施例对此不作限定。It is worth mentioning that the affiliation information may also include a user type, which is used to limit the type to which the user terminal belongs, for example, the user terminal belongs to a certain organization, and the embodiment of the present invention does not limit this, such as the user terminal being an independent organization.
步骤203,当接收用户端发送的数据检索请求时,获取数据检索请求对应的检索类型; Step 203, when receiving the data retrieval request sent by the client, obtain the retrieval type corresponding to the data retrieval request;
在本发明实施例中,步骤203的具体实施过程与步骤103类似,在此不再赘述。In the embodiment of the present invention, the specific implementation process of step 203 is similar to that of step 103, and will not be repeated here.
在具体实现中,关系数据库可以通过以下方式进行构建:In a specific implementation, a relational database can be constructed in the following ways:
1)限定层级类型的关系数据库1) Relational database with limited hierarchical type
通过在关系数据库中建立平面层级树信息表、机构信息表(保存机构id、名称、地址、联系信息等机构自身数据)、机构与设备关联表、用户信息表、用户和机构关联表,根据SQL查询条件为表建立索引。其中,用户信息表用来保存用户端id、名称、手机号等自身信息。各个节点的字段名应尽量是业务实体名的简称,应在特殊情况下才使用按顺序编号的字段名。用户与机构关联表用于记录用户与所属机构之间的关联关系。By establishing a flat hierarchical tree information table, an organization information table (saving organization id, name, address, contact information and other organization's own data), an organization and equipment association table, a user information table, a user and organization association table in the relational database, according to SQL The query condition indexes the table. Among them, the user information table is used to save the user terminal id, name, mobile phone number and other self-information. The field names of each node should be the abbreviation of the business entity name as much as possible, and the field names numbered in sequence should be used only in special cases. The user-institution association table is used to record the association relationship between the user and the institution to which it belongs.
以从省到街道的层级树为例,平面层级树信息表t_region_tree可如下表1所示:Taking the hierarchical tree from province to street as an example, the flat hierarchical tree information table t_region_tree can be shown in Table 1 below:
字段含义field meaning 字段名field name 数据类型type of data 备注Remark
idid idid bigintbigint 主键,也是层级树分支idThe primary key is also the hierarchical tree branch id
省/直辖市State / Province provinceprovince varcharvarchar  the
省/直辖市idProvince/municipality id province_idprovince_id bigintbigint  the
市/辖区City area citycity varcharvarchar  the
市/辖区idcity/district id city_idcity_id bigintbigint  the
区/县District/County countycounty varcharvarchar  the
区/县iddistrict/county id county_idcounty_id bigintbigint  the
街道/镇street/town streetstreet varcharvarchar  the
街道/镇idstreet/town id street_idstreet_id bigintbigint  the
社区/村community/village communitycommunity varcharvarchar  the
社区/村idcommunity/village id community_idcommunity_id bigintbigint  the
底层村/小区Underground village/community villagevillage varcharvarchar  the
底层村/小区idUnderlying village/community id village_idvillage_id bigintbigint  the
表1Table 1
其中,采用一个表记录层次树从顶层至最底层的完整分支以及其中各个节点的关系信息,表中字段从左至右的顺序按照层次树从上至下各节点的实际顺序一一对应,主要字段可以包括各个节点的名称、节点编号等信息,具有相同根节点的所有记录构成了这个根节点树的所有分支。如果需要更新节点名,以街道名为例,执行update t_region_tree set street=’新名’where street=’旧街道名’。删除层次树的节点时,直接执行update操作清空对应记录中的节点字段,表明层次树分支中忽略这个节点来组装分支;被清空的节点后续还可以通过update操作再写入新的节点名从而使之加入到树的分支中。Among them, a table is used to record the complete branches from the top to the bottom of the hierarchical tree and the relationship information of each node in it. The order of the fields in the table from left to right corresponds to the actual order of the nodes from top to bottom of the hierarchical tree. The main Fields can include information such as the name of each node, node number, etc., and all records with the same root node constitute all branches of the root node tree. If you need to update the node name, take the street name as an example, execute update t_region_tree set street='new name' where street='old street name'. When deleting a node in the hierarchical tree, directly execute the update operation to clear the node field in the corresponding record, indicating that this node is ignored in the branch of the hierarchical tree to assemble the branch; the cleared node can also be written into a new node name through the update operation to make are added to the branches of the tree.
而第一机构设备信息表可以如下表2所示:The equipment information table of the first institution may be shown in Table 2 below:
Figure PCTCN2022097345-appb-000001
Figure PCTCN2022097345-appb-000001
表2Table 2
如表2所示,第一机构设备信息表主要字段可以包括但不限于第一归属机构ID、设备id、设备名、设备IP地址等,若是第一归属机构仅存在一个层级树分支时,id也可以为层级树分支id。As shown in Table 2, the main fields of the device information table of the first organization may include but not limited to ID of the first affiliated organization, device id, device name, IP address of the device, etc. It can also be a hierarchical tree branch id.
而在上述示例中,作为节点名的省市县区名变化的频率很低。如果节点名会频繁变化,同时一个树的子节点数可能比较多,为避免数据库update操作的影响,还可以把所有节点名抽出来建立一个节点信息表,主要字段包括节点id、节点名、节点编码,这样每次更新节点名称时只需更新这里的一条记录即可。平面层级树信息表中对每个层级树节点只保存节点的id或编码,id和编码按连 续自增数据构建,此时一条记录可以存储多达数百个层级的层次树。However, in the above example, the name of the province, city, county, and district as the node name changes very little. If the node name will change frequently, and the number of child nodes in a tree may be relatively large at the same time, in order to avoid the influence of the database update operation, you can also extract all the node names to create a node information table, the main fields include node id, node name, node Encoded so that only one record here needs to be updated each time the node name is updated. In the flat hierarchical tree information table, only the id or code of the node is saved for each hierarchical tree node, and the id and code are constructed by continuous self-incremental data. At this time, a record can store up to hundreds of hierarchical trees.
上述表1与表2的结构优势包括:1)满足层次树管理、存储上的业务需求;2)能够通过一次SQL查询获得一个机构的所有目录树;3)能够通过一次SQL查询获得包含一个节点的层次树的完整信息;4)支持用户数据权限及数据安全,保证一个用户只能看到其权限允许看到的数据;5)业务数据的增删改等管理操作对其他操作的影响可以控制在一个有限的范围,不会随着数据量的增加越来越大。The structural advantages of the above Table 1 and Table 2 include: 1) meet the business needs of hierarchical tree management and storage; 2) can obtain all directory trees of an organization through a SQL query; 3) can obtain a node containing a node through a SQL query 4) Support user data permissions and data security, ensuring that a user can only see the data allowed by his permissions; 5) The impact of management operations such as adding, deleting, and modifying business data on other operations can be controlled within A limited range that does not grow larger as the amount of data increases.
2)非限定层级类型的关系数据库2) Relational database of unrestricted hierarchical type
对于非限定层级类型的关系数据库,通常需要保存的数据规模较大,若是采用上述限定层级类型的关系数据库的方式保存,容易导致读取缓慢,此时可以将上述平面层级树信息表拆分为树节点信息表t_node_link和树节点关联关系表t_node_link,同时建立第二机构设备关联信息表。For a relational database of an unrestricted hierarchical type, the data that needs to be saved is generally large in scale. If the above-mentioned relational database of the restricted hierarchical type is used to save, it will easily lead to slow reading. At this time, the above-mentioned flat hierarchical tree information table can be split into The tree node information table t_node_link and the tree node association relationship table t_node_link are established at the same time as the second institutional equipment association information table.
具体地,树节点信息表记载有各个树节点ID、节点名以及其他可根据业务增加的字段。树节点关联关系表可以如下表3所示:Specifically, the tree node information table records each tree node ID, node name and other fields that can be added according to the business. The tree node association table can be shown in Table 3 below:
Figure PCTCN2022097345-appb-000002
Figure PCTCN2022097345-appb-000002
表3table 3
当t_node_link用来保存节点自身时,high_id=node_id,distance都为0;对于叶子节点is_leaf为1,否则为0。另外,还用这个表保存所有非叶子节点和其所有下级节点之间的关联数据,即distance的值至少是0。When t_node_link is used to save the node itself, high_id=node_id and distance are both 0; for the leaf node is_leaf is 1, otherwise it is 0. In addition, this table is also used to save the associated data between all non-leaf nodes and all their subordinate nodes, that is, the value of distance is at least 0.
做这样的数据库设计下,不但可以一次性查出一个树的所有记录,层次树数据的管理、查询都不复杂,新增、删除节点时仅仅影响节点所在分支的改动位置及下级节点相关的记录。修改节点信息时不会影响t_node_link。例如:在需要新增(删除)、删除节点时,通过high_id字段可方便地实现,类似对链表 增加或删除节点,对distance的调整可以从UI上方便地计算新层级的相对值;要查询一个节点的各个下级的所有节点,可以使用SQL:select*from t_node_link l,t_node n where n.name=’要查询的节点名’and n.id=l.high_id and l.distance!=0,其中节点id也可以用节点编号替换;要查询任意节点的所有直属下级节点,可以使用SQL:select*from t_node_link l,t_node n where n.name=’要查询的节点名’and n.id=l.node_id and l.distance=1;要查询任意节点的所有上级节点,可以使用SQL:select*from t_node_link l,t_node n where n.name=’要查询的节点名’and n.id=l.node_id and l.distance!=0,通过节点表的node_id=节点间关联表的node_id、distance!=0;根据is_root=1可以方便地查询所有树的根节点。With such a database design, not only can all the records of a tree be found at one time, but also the management and query of hierarchical tree data are not complicated. When adding or deleting nodes, only the changed position of the branch where the node is located and the records related to the subordinate nodes are affected. . t_node_link will not be affected when modifying node information. For example: when it is necessary to add (delete) or delete nodes, it can be easily realized through the high_id field, similar to adding or deleting nodes to a linked list, and adjusting the distance can easily calculate the relative value of the new level from the UI; to query a All nodes of each lower level of the node can use SQL: select*from t_node_link l, t_node n where n.name='the name of the node to be queried'and n.id=l.high_id and l.distance! =0, where the node id can also be replaced by the node number; to query all directly subordinate nodes of any node, you can use SQL: select*from t_node_link l, t_node n where n.name='node name to be queried'and n. id=l.node_id and l.distance=1; to query all the superior nodes of any node, you can use SQL: select*from t_node_link l, t_node n where n.name='the name of the node to be queried'and n.id= l.node_id and l.distance! = 0, through the node_id of the node table = the node_id and distance of the inter-node association table! =0; according to is_root=1, it is convenient to query the root nodes of all trees.
步骤204,若检索类型为关系数据库检索,则根据归属信息检索数据库层级类型对应的关系数据库,得到第一目标层次数据; Step 204, if the search type is relational database search, search the relational database corresponding to the database level type according to the attribution information, and obtain the first target level data;
在本发明的一个示例中,归属信息包括第一归属机构ID,关系数据库包括平面层级树信息表和第一机构设备关联信息表;当数据库层级类型为限定层级类型时,步骤204可以包括以下子步骤:In an example of the present invention, the affiliation information includes a first affiliation organization ID, and the relational database includes a plane hierarchical tree information table and a first organization equipment association information table; when the database hierarchy type is a limited hierarchy type, step 204 may include the following subsections step:
若检索类型为关系数据库检索,则按照第一归属机构ID查询第一机构设备信息表,确定对应的设备数据以及层级树分支ID;If the retrieval type is a relational database retrieval, query the equipment information table of the first organization according to the ID of the first affiliation organization, and determine the corresponding equipment data and the branch ID of the hierarchical tree;
按照层级树分支ID查询平面层级树信息表,确定对应的层级树分支数据;Query the plane hierarchical tree information table according to the hierarchical tree branch ID, and determine the corresponding hierarchical tree branch data;
建立每个层级树分支数据与设备数据之间的关联,得到第一目标层次数据。An association between branch data of each hierarchical tree and device data is established to obtain the first target hierarchical data.
在本实施例中,当判定数据库层级类型为限定层级类型且检索类型为关系数据库检索时,说明此时需要检索的数据为限定层级类型的关系数据库,此时可以从归属信息中获取到第一归属机构ID,按照该第一归属机构ID查询第一机构设备信息表,确定该第一归属机构ID对应的设备数据以及对应的层级树分支ID,再按照层级树分支ID查询平面层级树信息表,确定对应的层级树分支数据,也就是上述的从省至底层村整个层级树分支,最后建立每个层级树分支数据与设备数据之间的关联,得到第一目标层次数据。In this embodiment, when it is determined that the database hierarchy type is a limited hierarchy type and the retrieval type is a relational database retrieval, it means that the data to be retrieved at this time is a relational database of a limited hierarchy type. At this time, the first Affiliation organization ID, query the first organization equipment information table according to the first affiliation organization ID, determine the equipment data corresponding to the first affiliation organization ID and the corresponding hierarchical tree branch ID, and then query the plane hierarchical tree information table according to the hierarchical tree branch ID , determine the corresponding hierarchical tree branch data, that is, the above-mentioned entire hierarchical tree branch from the province to the bottom village, and finally establish the association between each hierarchical tree branch data and equipment data to obtain the first target hierarchical data.
在具体实现中,还可以通过构建SQL语句的方式进行查询,其中SQL语句为:select t.*,d.device_id,d.device_name from t_org_device d,t_tree t where d.org_id=user_org_id and d.branch_id=t.id,其中user_org_id是第一归属机构ID, branch_id为层级树分支ID,t.id为层级树分支数据。In the specific implementation, you can also query by constructing SQL statements, where the SQL statements are: select t.*, d.device_id, d.device_name from t_org_device d, t_tree t where d.org_id=user_org_id and d.branch_id= t.id, where user_org_id is the first affiliation organization ID, branch_id is the hierarchical tree branch ID, and t.id is the hierarchical tree branch data.
在得到层级树分支数据后,可把层级树分支数据及该分支下的所有设备数据以及对应的层级树分支ID放到一条记录中,设备数据可以作为集合类型字段构成层级树分支ID的分支数据对象的一个属性。After obtaining the branch data of the hierarchical tree, you can put the branch data of the hierarchical tree, all the device data under the branch and the corresponding branch ID of the hierarchical tree into a record, and the device data can be used as a collection type field to form the branch data of the branch ID of the hierarchical tree A property of an object.
在本发明的另一个实例中,归属信息包括第二归属机构ID和上级节点ID,关系数据库包括树节点信息表、树节点关联关系表和第二机构设备关联信息表;当数据库层级类型为非限定层级类型时,步骤204可以包括以下子步骤:In another example of the present invention, the affiliation information includes a second affiliation organization ID and a superior node ID, and the relational database includes a tree node information table, a tree node association relationship table, and a second organization equipment association information table; when the database hierarchy type is non- When defining the level type, step 204 may include the following sub-steps:
若检索类型为关系数据库检索,则按照第二归属机构ID查询第二机构设备信息表,确定对应的设备数据、上级节点ID以及层级树节点ID;If the retrieval type is a relational database retrieval, query the equipment information table of the second organization according to the ID of the second affiliation organization, and determine the corresponding equipment data, upper node ID and hierarchical tree node ID;
采用上级节点ID和层级树节点ID检索树节点信息表,确定关联的全部树节点ID;Use the superior node ID and the hierarchical tree node ID to retrieve the tree node information table, and determine all associated tree node IDs;
按照各个树节点ID分别检索树节点关联关系表,得到各个树节点ID分别对应的第一节点关联关系;Retrieve the tree node association relationship table according to each tree node ID, and obtain the first node association relationship corresponding to each tree node ID;
按照第一节点关联关系关联各个树节点ID对应的树节点并建立上级节点ID与设备数据之间的关联,得到第一目标层次数据。The tree nodes corresponding to each tree node ID are associated according to the first node association relationship, and the association between the superior node ID and the device data is established to obtain the first target level data.
在本实施例中,当判定数据库层级类型为非限定层级类型且检索类型为关系数据库检索时,说明此时需要检索的关系数据库为非限定层级类型的,可以按照第二归属机构ID查询第二机构设备信息表,确定该第二归属机构ID所关联的设备数据、上级节点ID和层级树节点ID;再采用上级节点ID和层级树节点ID检索树节点信息表,以确定该层级树节点ID对应的树节点所处整个层级树的全部树节点ID,再按照各个树节点ID分别检索树节点关联关系表,以确定各个树节点ID对应的树节点之间的第一节点关联关系,按照该第一节点关联关系关联各个树节点ID对应的树节点并建立上级节点ID与设备数据之间的关联,得到第一目标层次数据。In this embodiment, when it is determined that the database hierarchy type is an unrestricted hierarchy type and the retrieval type is a relational database retrieval, it means that the relational database to be retrieved at this time is an unrestricted hierarchy type, and the second affiliation organization ID can be queried. Organization equipment information table, determine the equipment data associated with the second affiliation organization ID, superior node ID and hierarchical tree node ID; then use the superior node ID and hierarchical tree node ID to retrieve the tree node information table to determine the hierarchical tree node ID All the tree node IDs of the entire hierarchical tree where the corresponding tree nodes are located, and then respectively retrieve the tree node association relationship table according to each tree node ID, to determine the first node association relationship between the tree nodes corresponding to each tree node ID, according to the The first node association relationship associates the tree nodes corresponding to each tree node ID and establishes an association between the superior node ID and the device data to obtain the first target hierarchical data.
可选地,本方法还可以包括以下步骤:Optionally, the method may also include the following steps:
按照预设的更新周期执行预设的配置文件,对关系数据库内的关系数据进行字段转换,得到ES索引字段;Execute the preset configuration file according to the preset update cycle, perform field conversion on the relational data in the relational database, and obtain ES index fields;
将ES索引字段同步至ES索引库。Synchronize ES index fields to ES index library.
在具体实现中,为保证索引库的稳定性和准确性,ES索引库通常是在建立 一定规模的关系数据库并运行一段时间后再进行建设,同时为实现对ES索引库的周期性更新,可以按照预设的更新周期执行预设的配置文件,对关系数据库内的关系数据进行字段转换,以得到对应的ES索引字段,再将ES索引字段同步至ES索引库。In the specific implementation, in order to ensure the stability and accuracy of the index library, the ES index library is usually built after establishing a certain scale relational database and running for a period of time. At the same time, in order to realize the periodic update of the ES index library, you can Execute the preset configuration file according to the preset update cycle, perform field conversion on the relational data in the relational database to obtain the corresponding ES index field, and then synchronize the ES index field to the ES index library.
以上述层级树信息表t_plain_tree的同步为例,可以通过以下步骤S11-S15或步骤S21-S26实现ES索引库的数据同步:Taking the synchronization of the above-mentioned hierarchical tree information table t_plain_tree as an example, the data synchronization of the ES index library can be realized through the following steps S11-S15 or steps S21-S26:
S11、安装logstash-integration-jdbc等相关插件。参照官方文档配置数据库连接以及获取数据的SQL:SELECT distinct p.*from t_plain_tree p,t_org_device d WHERE p.id=d.branch_id and p.id>=:sql_last_value。更多需求可以通过调整这里的SQL实现;S11. Install related plug-ins such as logstash-integration-jdbc. Refer to the official document to configure the database connection and SQL for obtaining data: SELECT distinct p.*from t_plain_tree p, t_org_device d WHERE p.id=d.branch_id and p.id>=:sql_last_value. More requirements can be realized by adjusting the SQL here;
S12、编辑logstash配置文件,使之利用配置项tracking_column=>id、record_last_run=>true、clean_run=>false分页地追踪并记录id字段,用上述SQL从MySQL查询数据后保存到ES。使用插件logstash-filter-mutate、logstash-filter-ruby可以新增、移除、分拆字段或者改变字段的值,通过logstash-filter-geoip可以根据设备IP从IP地址库GeoLite2-City.mmdb解析出设备位置对应的经纬度、省市县名并在ES中生成对应的字段,这种情况下中文区域名需修改logstash安装目录下的ib/logstash/filters/geoip.rb来对每个获得的区域名继续调用get(″zh-CN″),由于这里的IP地址信息通过csv文件保存,因此也可以维护自己的地址库,还可以在geoip.rb中通过ruby代码调用IP解析服务获得相关中文区域信息;S12. Edit the logstash configuration file to use the configuration items tracking_column=>id, record_last_run=>true, clean_run=>false to track and record the id field in pages, use the above SQL to query the data from MySQL and save it to ES. Use the plug-ins logstash-filter-mutate and logstash-filter-ruby to add, remove, split fields or change the value of the field, and use logstash-filter-geoip to parse it from the IP address database GeoLite2-City.mmdb according to the device IP The longitude and latitude corresponding to the device location, the names of provinces, cities and counties, and generate the corresponding fields in ES. In this case, the Chinese region name needs to be modified in ib/logstash/filters/geoip.rb under the logstash installation directory for each obtained region name Continue to call get("zh-CN"), because the IP address information here is saved in a csv file, so you can also maintain your own address library, and you can also call the IP analysis service through the ruby code in geoip.rb to obtain relevant Chinese area information ;
S13、通过logstash-filter-mutate插件把中文区域信息、经纬度信息分别添加到ES索引的字段device_location、device_pos中;S13. Add the Chinese region information and latitude and longitude information to the fields device_location and device_pos of the ES index through the logstash-filter-mutate plug-in;
S14、继续编辑logstash配置文件,利用logstash-output-elasticsearch把上述处理结果写入到ES;S14. Continue to edit the logstash configuration file, and use logstash-output-elasticsearch to write the above processing results to ES;
S15、使用上述配置文件启动logstash,运行至全量数据迁移完毕后停止;这里也可以利用logstash配置文件中的schedule设置定时地从MySQL同步数据到ES。S15. Use the above configuration file to start logstash, run until the full amount of data migration is completed, and stop; here you can also use the schedule setting in the logstash configuration file to periodically synchronize data from MySQL to ES.
在另一个示例中,开源数据同步工具canal由于直接操作MySQL的binlog因此能很好地与业务系统解耦,同时其操作给MySQL带来的压力也很有限,但 是当一个层次树分支尚未完全形成时就把其同步到ES只会增加没用的ES更新操作,由于业务规则的差异,不同状态的业务实体数据也常见不需要全部同步的情况,另外,数据的处理和验证可能还需要查询其他数据库或ES,所以需要通过canal客户端来控制数据的增量同步,具体可参照图3,步骤如下:In another example, the open source data synchronization tool canal can be well decoupled from the business system because it directly operates MySQL's binlog, and its operation puts very little pressure on MySQL. However, when a hierarchical tree branch has not been fully formed Synchronizing it to ES will only increase useless ES update operations. Due to differences in business rules, it is common for business entity data in different states not to be fully synchronized. In addition, data processing and verification may require querying other Database or ES, so you need to control the incremental synchronization of data through the canal client. For details, please refer to Figure 3. The steps are as follows:
通过实现canal的接口InitializingBean和ParseCanal来创建canal的监听客户端,解析数据变更,获得发生变化的数据库表及数据;当发现表t_plain_tree、t_node的数据发生变化时,检查表t_org_device中是否存在变化的数据的id对应的设备关联记录,如果不存在则不同步对应的节点数据,否则继续同步;在正式同步数据前,先通过反射获得变更的数据对应的实体类;在需要同步t_plain_tree、t_node的数据到ES时,如果是新增记录则直接在对应的ES索引中写入新记录,如果是update操作则直接更新ES索引的对应记录;如果是delete操作,先删除机构设备索引中delete操作对应的id的记录,再删除表t_plain_tree、t_node相应的索引中的数据;如果机构设备关联表发生变化时,对表t_org_device的新增数据,直接把新增的记录写入到对应的ES索引;对于这个表的update、delete的数据,根据其id更新或者删除ES索引中对应的记录;如果有更多数据需要同步,则从继续监听是否发生数据变更。Create a canal listening client by implementing the canal interface InitializingBean and ParseCanal, parse the data changes, and obtain the changed database tables and data; when the data in the tables t_plain_tree and t_node changes, check whether there is any changed data in the table t_org_device If the device association record corresponding to the id does not exist, the corresponding node data will not be synchronized, otherwise the synchronization will continue; before formally synchronizing the data, first obtain the entity class corresponding to the changed data through reflection; when it is necessary to synchronize the data of t_plain_tree and t_node to In ES, if it is a new record, write the new record directly in the corresponding ES index, if it is an update operation, directly update the corresponding record in the ES index; if it is a delete operation, first delete the id corresponding to the delete operation in the organization equipment index record, and then delete the data in the corresponding index of the tables t_plain_tree and t_node; if the institutional device association table changes, for the new data in the table t_org_device, directly write the new record into the corresponding ES index; for this table The update and delete data of the database will update or delete the corresponding record in the ES index according to its id; if more data needs to be synchronized, it will continue to monitor whether data changes occur.
在具体实现中,ES索引库在进行关系数据的同步后,为方便后续数据检索,可以通过以下方式进行表格构建:In the specific implementation, after the ES index library synchronizes the relational data, in order to facilitate the subsequent data retrieval, the table can be constructed in the following ways:
1)限定层级类型的ES索引库1) ES index library with limited hierarchical type
对于非限定层级类型的ES索引库,可以包括但不限于节点信息索引表、平面层级树索引表和第一机构设备关联索引表。For the ES index library of unrestricted hierarchical type, it may include but not limited to node information index table, flat hierarchical tree index table and first organization device association index table.
具体地,平面层级树索引表可以如下表4所示:Specifically, the flat hierarchical tree index table may be shown in Table 4 below:
Figure PCTCN2022097345-appb-000003
Figure PCTCN2022097345-appb-000003
Figure PCTCN2022097345-appb-000004
Figure PCTCN2022097345-appb-000004
表4Table 4
值得一提的是,在上述表4中还可以在索引中增加业务上需要搜索的字段,例如设备所在地理位置、设备名、设备标签、设备能力等。It is worth mentioning that in the above Table 4, fields that need to be searched for business can also be added to the index, such as the geographic location of the device, device name, device label, device capability, etc.
第一机构设备关联索引表可以如下表5所示:The first agency equipment association index table may be shown in Table 5 below:
Figure PCTCN2022097345-appb-000005
Figure PCTCN2022097345-appb-000005
表5table 5
值得一提的是,基于上述数据库及ES的索引设计,在研发实现上提供两个配套措施,一方面简化基于Java语言的开发,尽量减少必须开发的代码量,另外还提高搜索操作的性能。Spring Data Elasticsearch继承了Spring Data的优点,包括不需要写实现代码只需要接口和@Repository、@Query注解就能实现对ES中数据的模糊查询和搜索,但是其默认的findAll()方法如果在生产环境下存在大量数据时被频繁调用来查看全部数据,可能会导致服务不稳定;另外@Query注解的内容写法与ES的painless脚本一致,不容易理解和记忆,易用性上远不如SQL查询语法,还不支持在查询结果中控制返回索引中的哪些字段,现有实现实际返回所有字段。It is worth mentioning that, based on the above-mentioned database and ES index design, two supporting measures are provided in the R&D implementation. On the one hand, it simplifies the development based on the Java language, minimizes the amount of code that must be developed, and improves the performance of search operations. Spring Data Elasticsearch inherits the advantages of Spring Data, including the fuzzy query and search of data in ES without writing implementation code and only needing interfaces and @Repository and @Query annotations. However, if its default findAll() method is used in production When there is a large amount of data in the environment, it is frequently called to view all the data, which may lead to unstable services; in addition, the content of the @Query annotation is written in the same way as the painless script of ES, which is not easy to understand and remember, and is far inferior to SQL query syntax in terms of ease of use , does not yet support controlling which fields in the index are returned in query results, the existing implementation actually returns all fields.
为解决第一个问题,由于默认的findAll()方法的具体实现代码在类SimpleElasticsearchRepository中,并且在META-INF中默认通过spring.factories 中指定由ElasticsearchRepositoryFactory控制通过哪个类提供ES查询方法的实现类。因此可以继承SimpleElasticsearchRepository这个类,重写其中的findAll()方法,其中增加warn或error级别的告警输出,并且给这个方法增加@Deprecated注解,然后再继承ElasticsearchRepositoryFactory并调用新开发的SimpleElasticsearchRepository的子类,并且在spring.factories中指定ElasticsearchRepositoryFactory的子类作为RepositoryFactorySupport。To solve the first problem, since the specific implementation code of the default findAll() method is in the class SimpleElasticsearchRepository, and by default in META-INF, it is specified in spring.factories that the ElasticsearchRepositoryFactory controls which class provides the implementation class of the ES query method. Therefore, you can inherit the SimpleElasticsearchRepository class, rewrite the findAll() method, add warn or error level alarm output, and add @Deprecated annotation to this method, then inherit ElasticsearchRepositoryFactory and call the newly developed SimpleElasticsearchRepository subclass, and Specify a subclass of ElasticsearchRepositoryFactory in spring.factories as RepositoryFactorySupport.
为解决第二个问题,可以针对ES的特定类型的查询封装专门的查询注解,例如针对模糊查询,可以对照Query注解的实现和处理流程封装一个新的注解FuzzyQuery及其处理流程,指定需要查询的字段、对应的参数值的标识、字段之间组装时的逻辑关系,默认按逻辑与处理,在运行时直接通过Repository接口的FuzzyQuery注解所在的方法中的参数按顺序替换;在指定返回字段列表或需排除的字段列表时,直接在查询请求的painless脚本中通过字符串处理生成对应的内容,其他方面保持和Query注解相同的效果。然后在类ElasticsearchQueryMethod、ElasticsearchRepositoryFactory中按上述新增的功能解析注解FuzzyQuery的内容并对应生成painless脚本内容,这样既可避免输入{\″wildcard\″:{、\″bool\″:或{\″must\″:这样的内容,也可以避免许多{、}、[、]这些符号带来的困扰。最后,重新打包生成jar后给业务系统替换原来使用的jar文件即可。In order to solve the second problem, special query annotations can be encapsulated for specific types of queries in ES. For example, for fuzzy queries, a new annotation FuzzyQuery and its processing flow can be encapsulated according to the implementation and processing flow of Query annotations, specifying the query that needs to be queried The field, the identification of the corresponding parameter value, and the logical relationship between the fields when assembling are processed by logical AND by default, and the parameters in the method where the FuzzyQuery annotation of the Repository interface is directly replaced in order at runtime; the specified return field list or For the list of fields to be excluded, directly generate the corresponding content through string processing in the painless script of the query request, and keep the same effect as the Query annotation in other respects. Then in the class ElasticsearchQueryMethod and ElasticsearchRepositoryFactory, analyze and annotate the content of FuzzyQuery according to the above-mentioned new functions and generate the corresponding painless script content, so as to avoid inputting {\″wildcard\″:{, \″bool\″: or {\″must \″: Such content can also avoid the troubles caused by many {, }, [,] symbols. Finally, after repackaging and generating the jar, replace the original jar file for the business system.
2)非限定层级类型的ES索引库2) ES index library of unrestricted hierarchical type
对于非限定层级类型的ES索引库,可以包括但不限于节点信息索引表、平面层级树索引表和第一机构设备关联索引表。For the ES index library of unrestricted hierarchical type, it may include but not limited to node information index table, flat hierarchical tree index table and first organization device association index table.
具体的,平面层级树索引表的具体构建与上述表4类似,节点信息索引表可以如下表6所示:Specifically, the specific construction of the flat hierarchical tree index table is similar to the above table 4, and the node information index table can be shown in the following table 6:
Figure PCTCN2022097345-appb-000006
Figure PCTCN2022097345-appb-000006
表6Table 6
第二机构设备关联索引表可以如下表7所示:The second agency equipment association index table may be shown in Table 7 below:
Figure PCTCN2022097345-appb-000007
Figure PCTCN2022097345-appb-000007
表7Table 7
值得一提的是,在实际搜索时,经过Java的CompletableFuture的supplyAsync()方法同时向上述两个索引发起搜索请求,再通过allOf()方法汇总所有的异步请求,最终整个的耗时稍高于两个请求中耗时最久的。当不需要返回层次树形式的结果数据时,直接返回这里的搜索结果即可,否则通过Java代码再根据这里的得到的节点信息可以从层次树各节点之间关联信息表查询到节点对应的所有树的分支数据,接下来组装成完整的层次树数据返回即可。It is worth mentioning that in the actual search, the supplyAsync() method of Java's CompletableFuture simultaneously initiates search requests to the above two indexes, and then summarizes all asynchronous requests through the allOf() method. Finally, the entire time-consuming is slightly higher than The longest of the two requests. When there is no need to return the result data in the form of a hierarchical tree, you can directly return the search results here. Otherwise, you can query all the corresponding nodes from the association information table between the nodes in the hierarchical tree through the Java code and then according to the node information obtained here. The branch data of the tree can then be assembled into a complete hierarchical tree data and returned.
步骤205,若检索类型为索引数据库检索,则根据数据检索请求与归属信息检索数据库层级类型对应的ES索引库,得到第二目标层次数据; Step 205, if the retrieval type is index database retrieval, according to the data retrieval request and the ES index database corresponding to the attribution information retrieval database hierarchy type, the second target hierarchy data is obtained;
在本发明的一个示例中,归属信息包括第三机构归属ID;ES索引库包括平面层级树索引表和第一机构设备关联索引表;当数据库层级类型为限定层级类型时,步骤205可以包括以下子步骤:In an example of the present invention, the affiliation information includes a third organization affiliation ID; the ES index library includes a flat hierarchical tree index table and a first organization equipment association index table; when the database hierarchy type is a limited hierarchy type, step 205 may include the following Substeps:
若检索类型为索引数据库检索,则解析数据检索请求得到搜索条件和目标数据格式;If the retrieval type is indexed database retrieval, the data retrieval request is parsed to obtain the search condition and the target data format;
按照第三机构归属ID检索机构设备关联索引表,确定对应的设备数据;According to the attribution ID of the third organization, retrieve the organization's equipment association index table, and determine the corresponding equipment data;
按照搜索条件搜索平面层级树索引表,确定对应的层级树信息;Search the flat hierarchical tree index table according to the search conditions to determine the corresponding hierarchical tree information;
建立层级树信息与设备数据之间的关联并转换为目标数据格式,得到第二目标层次数据。The association between the hierarchical tree information and the equipment data is established and converted into the target data format to obtain the second target hierarchical data.
搜索条件指的是可能与ES索引库内的字段不完全相同但相关的数据限制信息。目标数据格式指的是用户端所需求的层级树数据或是用户端特有的的数据格式。Search criteria refer to data restriction information that may not be exactly the same as the fields in the ES index library but is related. The target data format refers to the hierarchical tree data required by the client or the unique data format of the client.
在本发明实施例中,当确定数据库层级类型为限定层级类型下,若是需要进行索引数据库检索,则可以解析数据检索请求以获取到搜索条件以及目标数据格式。按照搜索条件以及第三机构归属ID,异步地从机构设备管理索引表以及平面层级树索引表内进行检索,确定第三机构归属ID对应的设备数据以及满足搜索条件的层级树信息;再建立层级树信息和设备数据之间的关联并转换为目标数据格式,得到第二目标层次数据。In the embodiment of the present invention, when it is determined that the database hierarchy type is a limited hierarchy type, if index database retrieval is required, the data retrieval request may be parsed to obtain the search conditions and the target data format. According to the search conditions and the affiliation ID of the third organization, asynchronously search from the organization equipment management index table and the flat hierarchical tree index table to determine the equipment data corresponding to the third organization affiliation ID and the hierarchical tree information that meets the search conditions; and then establish a hierarchy The association between the tree information and the device data is converted into the target data format to obtain the second target level data.
在具体实现中,可参照图4,通过以下步骤S31-S34实现ES索引库的检索查询:In specific implementation, with reference to FIG. 4, the retrieval query of the ES index library can be realized through the following steps S31-S34:
S31、用户从缓存中获取第三机构归属ID,如果找不到则先查询关系数据库MySQL、更新缓存后再继续;S31. The user obtains the attribution ID of the third organization from the cache, and if not found, first queries the relational database MySQL, updates the cache, and then continues;
S32、根据第三机构归属ID、搜索条件异步地从机构设备管理索引表、平面层级树索引表中搜索符合条件的数据,得到满足搜索条件的层级树信息以及设备数据作为搜索结果;S32. Asynchronously search for eligible data from the institutional device management index table and the flat hierarchical tree index table according to the third organization's affiliation ID and search conditions, and obtain hierarchical tree information and device data that meet the search conditions as search results;
可选地,在上述S32中,如果树的节点信息与平面层级树各节点间的关系分别存储在不同的索引中,则直接根据缓存的层级树分支id集合、第三机构归属ID异步地同时搜索机构设备管理索引表、平面层级树索引表得到搜索结果。接下来如果不需要把搜索结果组装成树形数据可以直接按客户端要求的结果返回,否则可以再次通过缓存查询MySQL获得树的节点关系数据,最后再由应用服务把结果数据组装成用户端需要的数据后返回。Optionally, in the above S32, if the node information of the tree and the relationship between the nodes of the plane hierarchical tree are respectively stored in different indexes, then asynchronously and simultaneously Search the institutional equipment management index table and the flat hierarchical tree index table to obtain the search results. Next, if you do not need to assemble the search results into tree data, you can directly return the results requested by the client, otherwise you can query MySQL again through the cache to obtain the tree node relationship data, and finally the application service assembles the result data into the required data from the client. returned after the data.
S33、若是搜索结果的记录数超过指定的阈值,则向用户端返回第一页(允许配置每一页有多少条记录)的结果及结果集的总数据量;S33, if the number of records of the search result exceeds the specified threshold, the result of the first page (how many records are allowed to be configured on each page) and the total data volume of the result set are returned to the client;
S34、在内存中通过Java代码将上述搜索结果组织成用户端需要的字段、数据格式后,得到第二目标层次数据返回用户端即可;S34. After the above-mentioned search results are organized into fields and data formats required by the client through the Java code in the memory, the second target level data is obtained and returned to the client;
在本发明的另一个示例中,归属信息包括第四机构归属ID,ES索引库包括树节点信息索引表和第二机构设备关联索引表;当数据库层级类型为非限定层级类型时,步骤205可以包括以下子步骤:In another example of the present invention, the affiliation information includes a fourth organization affiliation ID, and the ES index library includes a tree node information index table and a second organization equipment association index table; when the database hierarchy type is an unrestricted hierarchy type, step 205 can be Include the following sub-steps:
若检索类型为索引数据库检索,则解析数据检索请求得到搜索条件;If the retrieval type is index database retrieval, then parse the data retrieval request to obtain the search conditions;
按照第四机构归属ID检索第二机构设备关联索引表,确定对应的设备数据和所属层次树分支ID;Retrieve the equipment association index table of the second organization according to the belonging ID of the fourth organization, and determine the corresponding equipment data and the branch ID of the hierarchical tree to which it belongs;
按照搜索条件搜索树节点信息索引表,得到多个符合搜索条件的层次树节点ID;Search the tree node information index table according to the search conditions to obtain multiple hierarchical tree node IDs that meet the search conditions;
按照各个层次树节点ID分别检索第二机构设备关联索引表,确定各个层次树节点ID对应的第二节点关联关系;According to each hierarchical tree node ID, respectively retrieve the second mechanism equipment association index table, and determine the second node association relationship corresponding to each hierarchical tree node ID;
按照第二节点关联关系关联各个层次树节点ID对应的树节点,并建立与设备数据之间的关联,得到第二目标层次数据。The tree nodes corresponding to the tree node IDs of each hierarchy are associated according to the second node association relationship, and the association with the device data is established to obtain the second target hierarchy data.
在本发明实施例中,若检索类型为索引数据库检索且索引数据库为非限定层级类型,则解析数据检索请求得到搜索条件;按照第四机构归属ID检索第二机构设备关联索引表,确定对应的设备数据和所属层次树分支ID;按照搜索条件搜索树节点信息索引表,得到多个符合搜索条件的层次树节点ID;按照各个层次树节点ID分别检索第二机构设备关联索引表,确定各个层次树节点ID对应的第二节点关联关系;按照第二节点关联关系关联各个层次树节点ID对应的树节点,并建立与设备数据之间的关联,得到第二目标层次数据。In the embodiment of the present invention, if the retrieval type is index database retrieval and the index database is an unrestricted hierarchical type, the data retrieval request is parsed to obtain the search conditions; the second organization's equipment association index table is retrieved according to the fourth organization's attribution ID, and the corresponding Device data and the branch ID of the hierarchical tree to which it belongs; search the tree node information index table according to the search conditions, and obtain multiple hierarchical tree node IDs that meet the search conditions; search the second organization's equipment association index table according to each hierarchical tree node ID to determine each level The second node association relationship corresponding to the tree node ID; associate the tree nodes corresponding to the tree node IDs of each hierarchy according to the second node association relationship, and establish an association with the device data to obtain the second target hierarchy data.
步骤206,返回第一目标层次数据或第二目标层次数据至用户端。 Step 206, return the first target level data or the second target level data to the client.
在本发明实施例中,步骤206的具体实施过程与步骤106类似,在此不再赘述。In the embodiment of the present invention, the specific implementation process of step 206 is similar to that of step 106, and will not be repeated here.
步骤207,当接收到额外用户端发送的设备再分配请求时,创建与额外用户端对应的额外用户标识; Step 207, when receiving the device reallocation request sent by the additional client, create an additional user identifier corresponding to the additional client;
步骤208,按照设备再分配请求确定对应的额外设备数据; Step 208, determine the corresponding additional device data according to the device reallocation request;
步骤209,建立额外用户标识与额外设备数据之间的关联,得到额外ES索引表并保存至ES索引库。 Step 209, establishing the association between the additional user identifier and the additional device data, obtaining an additional ES index table and saving it to the ES index library.
在具体实现中,用户端通常是处于某一机构下,同一机构可以同时包括多个用户端,但可能由于业务需求,需要为单独某一用户进行设备的分配,为解决该技术问题,当接收到额外用户端发送的设备再分配请求时,创建与该额外用户端对应的额外用户标识,按照设备再分配请求确定该额外用户端所需求的额外设备数据,例如设备名、设备ID、设备位置、设备标签和设备能力等,再建立额外用户标识与额外设备数据之间的关联,得到额外ES索引表。而为方便后续检索,可以将该额外ES索引表保存至ES索引库。In a specific implementation, the client is usually under a certain organization, and the same organization can include multiple client terminals at the same time, but due to business requirements, it may be necessary to allocate equipment for a single user. In order to solve this technical problem, when receiving When the device reallocation request is sent by the additional client, create an additional user ID corresponding to the additional client, and determine the additional device data required by the additional client according to the device reallocation request, such as device name, device ID, and device location , device label, device capability, etc., and then establish the association between the additional user identifier and the additional device data to obtain the additional ES index table. To facilitate subsequent retrieval, the additional ES index table can be saved to the ES index library.
在本发明一个示例中,表8示出了本发明实施例的一种额外ES索引表:In an example of the present invention, Table 8 shows an additional ES index table of the embodiment of the present invention:
Figure PCTCN2022097345-appb-000008
Figure PCTCN2022097345-appb-000008
表8Table 8
在本发明的另一个示例中,为了区分这类用户并专门处理,在应用系统设计上,可以为这种这类用户非单独的角色或者为其创建专门的用户属性表示是否已经单独为其分配设备。如果通过角色控制,在为用户分配设备前先检查用户是否是要求的角色,检查通过后才能为这类用户分配设备;如果通过专用用户属性表示已单独为其分配设备,则通过一个关系数据库的事务包装为用户分配设备、设置这个属性值的操作,使得在数据库中成功保存为用户分配的设备后总是成功为相应用户设置对应的属性值。根据选择上述哪种方案,在用户登录时分别从数据库提取用户的角色或用户的上述属性数据后缓存在Redis集群中,后续用户发起搜索请求时,可以根据缓存的数据的值,判断应该对相应的用户搜索这部分的索引,从而同步实现对用户数据权限的控制。In another example of the present invention, in order to distinguish such users and deal with them specially, in the application system design, it is possible to create a special user attribute for this kind of users or create a special user attribute to indicate whether they have been assigned separately equipment. If the user is controlled by role, before assigning equipment to the user, check whether the user is the required role, and the equipment can only be allocated to this type of user after the check is passed; The transaction wraps the operation of assigning equipment to users and setting this attribute value, so that after successfully saving the equipment assigned to the user in the database, the corresponding attribute value is always successfully set for the corresponding user. According to which of the above options is selected, the user's role or the above attribute data of the user are respectively extracted from the database when the user logs in, and then cached in the Redis cluster. When the subsequent user initiates a search request, it can be judged based on the value of the cached data that the corresponding Users search this part of the index, so as to realize the control of user data permissions synchronously.
值得一提的是,在层级树内的各个树节点可能还存在设备上下线的情况,此时可以通过以下方式实现设备数据的更新:设备上下线事件的感知在技术上主要有两种途径:基于socket通过TCP/IP通信连接的建立和断开、基于设备心跳的上报数据,后者会定时收到设备的心跳数据并且在超过一定时间后如果一直收不到会认定设备已下线。二者都需要专门的设备接入服务,该服务可以通过MQTT协议、基于Netty的自定义协议甚至HTTP协议的设备心跳请求接收设备的通信请求。It is worth mentioning that there may still be devices going offline at each tree node in the hierarchical tree. At this time, the device data can be updated in the following ways: There are two main technical methods for the perception of device going offline events: Based on the establishment and disconnection of the socket through the TCP/IP communication connection, based on the reported data of the device heartbeat, the latter will receive the heartbeat data of the device regularly and if it has not been received after a certain period of time, it will be considered that the device has been offline. Both require a dedicated device access service, which can receive device communication requests through the MQTT protocol, a custom protocol based on Netty, or even a device heartbeat request of the HTTP protocol.
在线设备数的实时计算方案的细节包括:The details of the real-time calculation scheme for the number of online devices include:
为实时计算层次树节点下属设备的在线数,每当设备在线状态变化时,设备接入服务实例可以先在内存中通过ConcurrentHashMap保存设备的id(连续增长的数字)及其状态,在确认到设备的连接建立、断开,或者收到设备心跳请 求、超时收不到设备请求时,分别设置设备在线状态为true、false,多个设备同时出现状态变化时,直接通过多个线程并发地调用ConcurrentHashMap的put()方法修改对应设备id的状态即可。然后由设备接入服务集群中的应用服务实例定时(间隔允许配置)地把这些数据同步刷新到多主多从的Redis集群,Redis再通过其bitset保存设备的在线状态,各个Redis的master实例。在层次树最大层级数固定时,bitset的key是层次树分支的id;当最大层级数不限时,key为设备紧邻上级节点的id,如果这个id发生变化,需要同步更新这里缓存的key。bitset中每一位的序号与对应的设备id相等,这个位的值通过0、1分别表示设备不在线、在线。通过Redis的SETBIT、GETBIT、BITCOUNT指令可以方便地设置、获取一个序号的bit对应的设备id的在线状态、一个key下的总在线设备数。如果某个节点下的设备id普遍大于一个数字,可以在操作Redis时把所有的设备id都减去一个数,例如其中最小的设备id,有助于节约内存占用。当需要获取层次树各节点的在线设备数时,可以批量地把一组树分支id或设备紧邻节点的id,通过Redis的pipeline机制批量发送通过BITCOUNT获取一个key的总在线设备数,然后由应用服务组装结果数据并返回。如果用户只能访问一个节点下的部分设备,可以通过Redis的pipeline机制批量发送通过GETBIT获取一个设备id的在线状态的指令,返回1表名对应的设备在线,在应用服务内存中累计后再把总在线设备数返回给用户端。各个节点的总设备数,可以数据库中查询后缓存到Redis集群中供后续查询节点下的总设备数时直接从缓存获取。Redis中可以通过hash按树分支或节点的id作为key,总设备数作为属性来存储,在发生设备新增、删除或移动操作时,对相应key的hash值作加、减对应设备数的操作,在发现Redis中任意key的总设备数据为空时,从数据源加载数据并缓存在Redis的hash中。如果用户端层次树的实现效果是逐级打开层次树,默认开始时只打开第一级节点,那实现上更简单:只要在用户双击打开某个节点时,直接打开下一级的树节点,当要打开的是最后一级树节点时,直接根据这个节点的id从Redis中通过BITCOUNT指令获取在线设备数即可。如果用户只能访问其中部分设备,把这些设备的id分批次从Redis通过pipeline获取每个设备的在线状态后在内存中累计,把用户拥有的设备累计完成后的结果即为当前节点的总在线设备数。由于整个过程主要在内存中进行,而且Redis多住多从集 群的良好可扩展性和可用性,在线设备数的计算不仅能实时进行,还会具有较好的性能。In order to calculate the online number of the subordinate devices of the hierarchical tree node in real time, whenever the online status of the device changes, the device access service instance can first save the device id (continuously increasing number) and its status in the memory through ConcurrentHashMap, and then confirm the device When the connection is established or disconnected, or when the device heartbeat request is received, or the device request is not received after a timeout, set the device online status to true and false respectively. When multiple devices have status changes at the same time, directly call ConcurrentHashMap concurrently through multiple threads The put() method can modify the state of the corresponding device id. Then, the application service instance in the device access service cluster regularly refreshes these data to the multi-master and multi-slave Redis cluster at regular intervals (the interval is allowed to be configured), and Redis saves the online status of the device through its bitset, and the master instance of each Redis. When the maximum number of levels in the hierarchical tree is fixed, the key of the bitset is the id of the branch of the hierarchical tree; when the maximum number of levels is not limited, the key is the id of the device next to the upper node. If the id changes, the key cached here needs to be updated synchronously. The serial number of each bit in the bitset is equal to the corresponding device id, and the value of this bit indicates that the device is offline or online respectively through 0 and 1. Through the SETBIT, GETBIT, and BITCOUNT commands of Redis, you can easily set and obtain the online status of the device id corresponding to the bit of a serial number, and the total number of online devices under a key. If the device IDs under a certain node are generally greater than a number, you can subtract a number from all device IDs when operating Redis, such as the smallest device ID among them, which helps to save memory usage. When it is necessary to obtain the number of online devices of each node of the hierarchical tree, a group of tree branch ids or device IDs of adjacent nodes can be sent in batches through the pipeline mechanism of Redis to obtain the total number of online devices of a key through BITCOUNT, and then the application The service assembles the resulting data and returns it. If the user can only access some devices under one node, the Redis pipeline mechanism can be used to send batches of commands to get the online status of a device id through GETBIT, and the device corresponding to the table name of 1 is returned online, and then accumulated in the application service memory The total number of online devices is returned to the client. The total number of devices of each node can be queried in the database and cached in the Redis cluster for subsequent query of the total number of devices under the node to be obtained directly from the cache. In Redis, the id of the tree branch or node can be used as the key through hash, and the total number of devices can be stored as an attribute. When a device is added, deleted or moved, the hash value of the corresponding key can be added or subtracted. , when the total device data of any key in Redis is found to be empty, the data is loaded from the data source and cached in the hash of Redis. If the implementation effect of the user-side hierarchical tree is to open the hierarchical tree step by step, and only open the first-level nodes at the beginning by default, then the implementation is simpler: as long as the user double-clicks to open a node, directly open the next-level tree node, When the last level of tree node is to be opened, the number of online devices can be obtained directly from Redis through the BITCOUNT command according to the id of this node. If the user can only access some of the devices, obtain the online status of each device from Redis in batches through the pipeline and accumulate them in memory. The result of accumulating the devices owned by the user is the total number of the current node. Number of online devices. Since the whole process is mainly carried out in memory, and the good scalability and availability of Redis multi-resident multi-slave cluster, the calculation of the number of online devices can not only be performed in real time, but also have better performance.
在本发明实施例中,通过响应于任一用户端发送的登录请求,获取用户端对应的用户标识;从预设数据库中查询用户标识对应的归属信息,并确定用户标识对应的数据库层级类型;当接收用户端发送的数据检索请求时,获取数据检索请求对应的检索类型;若检索类型为关系数据库检索,则根据归属信息检索数据库层级类型对应的关系数据库,得到第一目标层次数据;若检索类型为索引数据库检索,则根据数据检索请求与归属信息检索数据库层级类型对应的ES索引库,得到第二目标层次数据;返回第一目标层次数据或第二目标层次数据至用户端。从而通过划分检索类型和数据库层级类型,在简化检索架构和检索路径的基础上,经数据库设计和ES搜索库设计互相配合,可以通过一个SQL语句或是数次查询的方式获取到层次树数据,进而更为有效地提高了亿级用户量下数据检索过程的效率。In the embodiment of the present invention, by responding to a login request sent by any client, the user identifier corresponding to the client is obtained; the attribution information corresponding to the user identifier is queried from a preset database, and the database hierarchy type corresponding to the user identifier is determined; When receiving the data retrieval request sent by the client, obtain the retrieval type corresponding to the data retrieval request; if the retrieval type is a relational database retrieval, then retrieve the relational database corresponding to the database hierarchy type according to the attribution information, and obtain the first target level data; if the retrieval If the type is index database retrieval, then according to the data retrieval request and the ES index library corresponding to the attribution information retrieval database level type, obtain the second target level data; return the first target level data or the second target level data to the client. Therefore, by dividing the retrieval type and database hierarchy type, on the basis of simplifying the retrieval structure and retrieval path, through the cooperation of database design and ES search library design, hierarchical tree data can be obtained through one SQL statement or several queries. Furthermore, the efficiency of the data retrieval process under the amount of hundreds of millions of users is more effectively improved.
请参阅图5,图5为本发明实施例三提供的一种层次数据检索装置的结构框图。Please refer to FIG. 5 . FIG. 5 is a structural block diagram of a hierarchical data retrieval device provided by Embodiment 3 of the present invention.
本发明实施例提供了一种层次数据检索装置,包括:An embodiment of the present invention provides a hierarchical data retrieval device, including:
用户标识获取模块501,用于响应于任一用户端发送的登录请求,获取用户端对应的用户标识;The user identification acquisition module 501 is configured to obtain a user identification corresponding to the user terminal in response to a login request sent by any user terminal;
数据库层级类型确定模块502,用于从预设数据库中查询用户标识对应的归属信息,并确定用户标识对应的数据库层级类型;A database hierarchy type determining module 502, configured to query the attribution information corresponding to the user identifier from a preset database, and determine the database hierarchy type corresponding to the user identifier;
检索类型获取模块503,用于当接收用户端发送的数据检索请求时,获取数据检索请求对应的检索类型;A retrieval type obtaining module 503, configured to obtain the retrieval type corresponding to the data retrieval request when receiving the data retrieval request sent by the client;
关系数据检索模块504,用于若检索类型为关系数据库检索,则根据归属信息检索数据库层级类型对应的关系数据库,得到第一目标层次数据;A relational data retrieval module 504, configured to retrieve the relational database corresponding to the database hierarchy type according to the attribution information if the retrieval type is a relational database retrieval, to obtain the first target hierarchical data;
索引数据检索模块505,用于若检索类型为索引数据库检索,则根据数据检索请求与归属信息检索数据库层级类型对应的ES索引库,得到第二目标层次数据;The index data retrieval module 505 is used for if the retrieval type is an index database retrieval, then according to the data retrieval request and the ES index library corresponding to the attribution information retrieval database hierarchy type, obtain the second target hierarchy data;
层次数据返回模块506,用于返回第一目标层次数据或第二目标层次数据至 用户端。Hierarchical data return module 506, used to return the first target hierarchical data or the second target hierarchical data to the client.
可选地,数据库层级类型确定模块502具体用于:Optionally, the database hierarchy type determination module 502 is specifically used for:
按照用户标识检索预设数据库,获取用户标识对应的归属信息并缓存;Retrieve the preset database according to the user ID, obtain the attribution information corresponding to the user ID and cache it;
判断归属信息是否包含上级节点ID;Determine whether the attribution information contains the superior node ID;
若否,则判定用户标识对应的数据库层级类型为限定层级类型;If not, determine that the database hierarchy type corresponding to the user identifier is a limited hierarchy type;
若是,则判定用户标识对应的数据库层级类型为非限定层级类型。If yes, it is determined that the database hierarchy type corresponding to the user identifier is an unrestricted hierarchy type.
可选地,归属信息包括第一归属机构ID,关系数据库包括平面层级树信息表和第一机构设备关联信息表;当数据库层级类型为限定层级类型时,关系数据检索模块504具体用于:Optionally, the affiliation information includes the first affiliation organization ID, and the relational database includes a plane hierarchical tree information table and a first organization equipment association information table; when the database hierarchy type is a limited hierarchy type, the relational data retrieval module 504 is specifically used for:
若检索类型为关系数据库检索,则按照第一归属机构ID查询第一机构设备信息表,确定对应的设备数据以及层级树分支ID;If the retrieval type is a relational database retrieval, query the equipment information table of the first organization according to the ID of the first affiliation organization, and determine the corresponding equipment data and the branch ID of the hierarchical tree;
按照层级树分支ID查询平面层级树信息表,确定对应的层级树分支数据;Query the plane hierarchical tree information table according to the hierarchical tree branch ID, and determine the corresponding hierarchical tree branch data;
建立每个层级树分支数据与设备数据之间的关联,得到第一目标层次数据。An association between branch data of each hierarchical tree and device data is established to obtain the first target hierarchical data.
可选地,归属信息包括第二归属机构ID和上级节点ID,关系数据库包括树节点信息表、树节点关联关系表和第二机构设备关联信息表;当数据库层级类型为非限定层级类型时,关系数据检索模块504具体用于:Optionally, the affiliation information includes a second affiliation organization ID and a superior node ID, and the relational database includes a tree node information table, a tree node association relationship table and a second organization equipment association information table; when the database hierarchy type is an unrestricted hierarchy type, The relational data retrieval module 504 is specifically used for:
若检索类型为关系数据库检索,则按照第二归属机构ID查询第二机构设备信息表,确定对应的设备数据、上级节点ID以及层级树节点ID;If the retrieval type is a relational database retrieval, query the equipment information table of the second organization according to the ID of the second affiliation organization, and determine the corresponding equipment data, upper node ID and hierarchical tree node ID;
采用上级节点ID和层级树节点ID检索树节点信息表,确定关联的全部树节点ID;Use the superior node ID and the hierarchical tree node ID to retrieve the tree node information table, and determine all associated tree node IDs;
按照各个树节点ID分别检索树节点关联关系表,得到各个树节点ID分别对应的第一节点关联关系;Retrieve the tree node association relationship table according to each tree node ID, and obtain the first node association relationship corresponding to each tree node ID;
按照第一节点关联关系关联各个树节点ID对应的树节点并建立上级节点ID与设备数据之间的关联,得到第一目标层次数据。The tree nodes corresponding to each tree node ID are associated according to the first node association relationship, and the association between the superior node ID and the device data is established to obtain the first target level data.
可选地,归属信息包括第三机构归属ID;ES索引库包括平面层级树索引表和第一机构设备关联索引表;当数据库层级类型为限定层级类型时,索引数据检索模块505包括:Optionally, the affiliation information includes a third organization affiliation ID; the ES index storehouse includes a flat hierarchical tree index table and a first organization equipment association index table; when the database hierarchy type is a limited hierarchy type, the index data retrieval module 505 includes:
若检索类型为索引数据库检索,则解析数据检索请求得到搜索条件和目标数据格式;If the retrieval type is indexed database retrieval, the data retrieval request is parsed to obtain the search condition and the target data format;
按照第三机构归属ID检索机构设备关联索引表,确定对应的设备数据;According to the attribution ID of the third organization, retrieve the organization's equipment association index table, and determine the corresponding equipment data;
按照搜索条件搜索平面层级树索引表,确定对应的层级树信息;Search the flat hierarchical tree index table according to the search conditions to determine the corresponding hierarchical tree information;
建立层级树信息与设备数据之间的关联并转换为目标数据格式,得到第二目标层次数据。The association between the hierarchical tree information and the equipment data is established and converted into the target data format to obtain the second target hierarchical data.
可选地,归属信息包括第四机构归属ID,ES索引库包括树节点信息索引表和第二机构设备关联索引表;当数据库层级类型为非限定层级类型时,索引数据检索模块505包括:Optionally, the affiliation information includes a fourth organization affiliation ID, and the ES index library includes a tree node information index table and a second organization equipment association index table; when the database hierarchy type is an unrestricted hierarchy type, the index data retrieval module 505 includes:
若检索类型为索引数据库检索,则解析数据检索请求得到搜索条件;If the retrieval type is index database retrieval, then parse the data retrieval request to obtain the search conditions;
按照第四机构归属ID检索第二机构设备关联索引表,确定对应的设备数据和所属层次树分支ID;Retrieve the equipment association index table of the second organization according to the belonging ID of the fourth organization, and determine the corresponding equipment data and the branch ID of the hierarchical tree to which it belongs;
按照搜索条件搜索树节点信息索引表,得到多个符合搜索条件的层次树节点ID;Search the tree node information index table according to the search conditions to obtain multiple hierarchical tree node IDs that meet the search conditions;
按照各个层次树节点ID分别检索第二机构设备关联索引表,确定各个层次树节点ID对应的第二节点关联关系;According to each hierarchical tree node ID, respectively retrieve the second mechanism equipment association index table, and determine the second node association relationship corresponding to each hierarchical tree node ID;
按照第二节点关联关系关联各个层次树节点ID对应的树节点,并建立与设备数据之间的关联,得到第二目标层次数据。The tree nodes corresponding to the tree node IDs of each hierarchy are associated according to the second node association relationship, and the association with the device data is established to obtain the second target hierarchy data.
可选地,装置还包括:Optionally, the device also includes:
用户标识创建模块,用于当接收到额外用户端发送的设备再分配请求时,创建与额外用户端对应的额外用户标识;A user identification creation module, configured to create an additional user identification corresponding to the additional user end when receiving a device reallocation request sent by the additional user end;
额外设备数据确定模块,用于按照设备再分配请求确定对应的额外设备数据;An additional equipment data determining module, configured to determine corresponding additional equipment data according to the equipment reallocation request;
关联建立模块,用于建立额外用户标识与额外设备数据之间的关联,得到额外ES索引表并保存至ES索引库。The association establishing module is used to establish the association between the additional user identification and the additional device data, obtain the additional ES index table and save it to the ES index library.
可选地,装置还包括:Optionally, the device also includes:
字段转换模块,用于按照预设的更新周期执行预设的配置文件,对关系数据库内的关系数据进行字段转换,得到ES索引字段;The field conversion module is used to execute the preset configuration file according to the preset update cycle, perform field conversion on the relational data in the relational database, and obtain the ES index field;
字段同步模块,用于将ES索引字段同步至ES索引库。The field synchronization module is used to synchronize the ES index fields to the ES index library.
本发明实施例还提供了一种电子设备,包括存储器及处理器,存储器中储存有计算机程序,计算机程序被处理器执行时,使得处理器执行如本发明任一 实施例的层次数据检索方法的步骤。An embodiment of the present invention also provides an electronic device, including a memory and a processor, and a computer program is stored in the memory. When the computer program is executed by the processor, the processor executes the hierarchical data retrieval method according to any embodiment of the present invention. step.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的装置和模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the above-described devices and modules can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.
在本发明所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or May be integrated into another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。If the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the essence of the technical solution of the present invention or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , including several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disc, etc., which can store program codes. .
以上所述,以上实施例仅用以说明本发明的技术方案,而非对其限制;尽 管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。As mentioned above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: it can still understand the foregoing The technical solutions recorded in each embodiment are modified, or some of the technical features are replaced equivalently; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.

Claims (10)

  1. 一种层次数据检索方法,其特征在于,包括:A hierarchical data retrieval method, characterized in that it includes:
    响应于任一用户端发送的登录请求,获取所述用户端对应的用户标识;In response to a login request sent by any client, obtain the user ID corresponding to the client;
    从预设数据库中查询所述用户标识对应的归属信息,并确定所述用户标识对应的数据库层级类型;Querying the attribution information corresponding to the user identifier from a preset database, and determining the database hierarchy type corresponding to the user identifier;
    当接收所述用户端发送的数据检索请求时,获取所述数据检索请求对应的检索类型;When receiving the data retrieval request sent by the client, obtain the retrieval type corresponding to the data retrieval request;
    若所述检索类型为关系数据库检索,则根据所述归属信息检索所述数据库层级类型对应的关系数据库,得到第一目标层次数据;If the search type is a relational database search, then search the relational database corresponding to the database level type according to the attribution information to obtain the first target level data;
    若所述检索类型为索引数据库检索,则根据所述数据检索请求与所述归属信息检索所述数据库层级类型对应的ES索引库,得到第二目标层次数据;If the retrieval type is index database retrieval, then according to the data retrieval request and the attribution information, retrieve the ES index database corresponding to the database hierarchy type to obtain the second target hierarchy data;
    返回所述第一目标层次数据或所述第二目标层次数据至所述用户端。returning the first target level data or the second target level data to the client.
  2. 根据权利要求1所述的方法,其特征在于,所述从预设数据库中查询所述用户标识对应的归属信息,并确定所述用户标识对应的数据库层级类型的步骤,包括:The method according to claim 1, wherein the step of querying the attribution information corresponding to the user ID from a preset database and determining the database hierarchy type corresponding to the user ID includes:
    按照所述用户标识检索预设数据库,获取所述用户标识对应的归属信息并缓存;Retrieving a preset database according to the user ID, obtaining attribution information corresponding to the user ID and caching it;
    判断所述归属信息是否包含上级节点ID;judging whether the attribution information includes a superior node ID;
    若否,则判定所述用户标识对应的数据库层级类型为限定层级类型;If not, then determine that the database hierarchy type corresponding to the user identifier is a limited hierarchy type;
    若是,则判定所述用户标识对应的数据库层级类型为非限定层级类型。If yes, it is determined that the database hierarchy type corresponding to the user identifier is an unrestricted hierarchy type.
  3. 根据权利要求2所述的方法,其特征在于,所述归属信息包括第一归属机构ID,所述关系数据库包括平面层级树信息表和第一机构设备关联信息表;当所述数据库层级类型为限定层级类型时,所述若所述检索类型为关系数据库检索,则根据所述归属信息检索所述数据库层级类型对应的关系数据库,得到第一目标层次数据的步骤,包括:The method according to claim 2, wherein the affiliation information includes a first affiliation organization ID, and the relational database includes a plane hierarchical tree information table and a first organization equipment association information table; when the database hierarchy type is When defining the hierarchy type, if the retrieval type is a relational database retrieval, the step of retrieving the relational database corresponding to the database hierarchy type according to the attribution information to obtain the first target hierarchy data includes:
    若所述检索类型为关系数据库检索,则按照所述第一归属机构ID查询所述第一机构设备信息表,确定对应的设备数据以及层级树分支ID;If the retrieval type is a relational database retrieval, then query the equipment information table of the first organization according to the ID of the first affiliation organization, and determine the corresponding equipment data and the branch ID of the hierarchical tree;
    按照所述层级树分支ID查询所述平面层级树信息表,确定对应的层级树分支数据;Querying the flat hierarchical tree information table according to the hierarchical tree branch ID to determine the corresponding hierarchical tree branch data;
    建立每个所述层级树分支数据与所述设备数据之间的关联,得到第一目标层次数据。An association between each branch data of the hierarchical tree and the device data is established to obtain first target hierarchical data.
  4. 根据权利要求2所述的方法,其特征在于,所述归属信息包括第二归属机构ID和所述上级节点ID,所述关系数据库包括树节点信息表、树节点关联关系表和第二机构设备关联信息表;当所述数据库层级类型为非限定层级类型时,所述若所述检索类型为关系数据库检索,则根据所述归属信息检索所述数据库层级类型对应的关系数据库,得到第一目标层次数据的步骤,包括:The method according to claim 2, wherein the affiliation information includes a second affiliation organization ID and the superior node ID, and the relational database includes a tree node information table, a tree node association table and a second organization device Association information table; when the database hierarchy type is an unrestricted hierarchy type, if the retrieval type is a relational database retrieval, search the relational database corresponding to the database hierarchy type according to the attribution information, and obtain the first target Steps for hierarchical data, including:
    若所述检索类型为关系数据库检索,则按照所述第二归属机构ID查询所述第二机构设备信息表,确定对应的设备数据、所述上级节点ID以及层级树节点ID;If the retrieval type is a relational database retrieval, then query the equipment information table of the second organization according to the ID of the second affiliation organization, and determine the corresponding equipment data, the ID of the superior node and the node ID of the hierarchical tree;
    采用所述上级节点ID和所述层级树节点ID检索所述树节点信息表,确定关联的全部树节点ID;Retrieving the tree node information table by using the superior node ID and the hierarchical tree node ID to determine all associated tree node IDs;
    按照各个所述树节点ID分别检索所述树节点关联关系表,得到各个所述树节点ID分别对应的第一节点关联关系;Retrieving the tree node association relationship table according to each of the tree node IDs to obtain the first node association relationship corresponding to each of the tree node IDs;
    按照所述第一节点关联关系关联各个所述树节点ID对应的树节点并建立所述上级节点ID与所述设备数据之间的关联,得到第一目标层次数据。Associating the tree nodes corresponding to each of the tree node IDs according to the first node association relationship and establishing an association between the upper-level node ID and the device data to obtain first target hierarchical data.
  5. 根据权利要求2所述的方法,其特征在于,所述归属信息包括第三机构归属ID;所述ES索引库包括平面层级树索引表和第一机构设备关联索引表;当所述数据库层级类型为限定层级类型时,所述若所述检索类型为索引数据库检索,则根据所述数据检索请求与所述归属信息检索所述数据库层级类型对应的ES索引库,得到第二目标层次数据的步骤,包括:The method according to claim 2, wherein the affiliation information includes the affiliation ID of the third organization; the ES index library includes a flat hierarchy tree index table and a first organization equipment association index table; when the database hierarchy type When the hierarchical type is defined, if the retrieval type is an index database retrieval, then according to the data retrieval request and the attribution information, search the ES index library corresponding to the database hierarchical type to obtain the second target hierarchical data ,include:
    若所述检索类型为索引数据库检索,则解析所述数据检索请求得到搜索条件和目标数据格式;If the retrieval type is an index database retrieval, then parsing the data retrieval request to obtain a search condition and a target data format;
    按照所述第三机构归属ID检索所述机构设备关联索引表,确定对应的设备数据;Retrieving the institutional equipment association index table according to the third institutional attribution ID to determine the corresponding equipment data;
    按照所述搜索条件搜索所述平面层级树索引表,确定对应的层级树信息;Search the flat hierarchical tree index table according to the search condition, and determine the corresponding hierarchical tree information;
    建立所述层级树信息与所述设备数据之间的关联并转换为所述目标数据格式,得到第二目标层次数据。Establishing the association between the hierarchical tree information and the device data and converting it into the target data format to obtain second target hierarchical data.
  6. 根据权利要求2所述的方法,其特征在于,所述归属信息包括第四机构归属ID,所述ES索引库包括树节点信息索引表和第二机构设备关联索引表;当所述数据库层级类型为非限定层级类型时,所述若所述检索类型为索引数据库检索,则根据所述数据检索请求与所述归属信息检索所述数据库层级类型对应的ES索引库,得到第二目标层次数据的步骤,包括:The method according to claim 2, wherein the affiliation information includes a fourth organization affiliation ID, and the ES index library includes a tree node information index table and a second organization equipment association index table; when the database hierarchy type When it is an unrestricted hierarchy type, if the retrieval type is an index database retrieval, search the ES index library corresponding to the database hierarchy type according to the data retrieval request and the attribution information, and obtain the second target hierarchy data steps, including:
    若所述检索类型为索引数据库检索,则解析所述数据检索请求得到搜索条件;If the retrieval type is an index database retrieval, then parsing the data retrieval request to obtain a search condition;
    按照所述第四机构归属ID检索所述第二机构设备关联索引表,确定对应的设备数据和所属层次树分支ID;Retrieving the second organization's equipment association index table according to the fourth organization's attribution ID, and determining the corresponding equipment data and the hierarchical tree branch ID to which it belongs;
    按照所述搜索条件搜索所述树节点信息索引表,得到多个符合所述搜索条件的层次树节点ID;Searching the tree node information index table according to the search condition to obtain a plurality of hierarchical tree node IDs meeting the search condition;
    按照各个所述层次树节点ID分别检索所述第二机构设备关联索引表,确定各个所述层次树节点ID对应的第二节点关联关系;Retrieving the second organization equipment association index table according to each of the hierarchical tree node IDs, and determining the second node association relationship corresponding to each of the hierarchical tree node IDs;
    按照所述第二节点关联关系关联各个所述层次树节点ID对应的树节点,并建立与所述设备数据之间的关联,得到第二目标层次数据。The tree nodes corresponding to each of the hierarchical tree node IDs are associated according to the second node association relationship, and an association with the device data is established to obtain second target hierarchical data.
  7. 根据权利要求1所述的方法,其特征在于,还包括:The method according to claim 1, further comprising:
    当接收到额外用户端发送的设备再分配请求时,创建与所述额外用户端对应的额外用户标识;When receiving the device reallocation request sent by the additional client, creating an additional user identifier corresponding to the additional client;
    按照所述设备再分配请求确定对应的额外设备数据;determining corresponding additional device data according to the device reallocation request;
    建立所述额外用户标识与所述额外设备数据之间的关联,得到额外ES索引表并保存至所述ES索引库。An association between the additional user identifier and the additional device data is established, and an additional ES index table is obtained and stored in the ES index database.
  8. 根据权利要求1-7任一项所述的方法,其特征在于,还包括:The method according to any one of claims 1-7, further comprising:
    按照预设的更新周期执行预设的配置文件,对所述关系数据库内的关系数据进行字段转换,得到ES索引字段;Executing a preset configuration file according to a preset update cycle, performing field conversion on the relational data in the relational database, and obtaining ES index fields;
    将所述ES索引字段同步至所述ES索引库。Synchronize the ES index field to the ES index library.
  9. 一种层次数据检索装置,其特征在于,包括:A hierarchical data retrieval device, characterized in that it includes:
    用户标识获取模块,用于响应于任一用户端发送的登录请求,获取所述用户端对应的用户标识;A user identification acquisition module, configured to obtain a user identification corresponding to the user terminal in response to a login request sent by any user terminal;
    数据库层级类型确定模块,用于从预设数据库中查询所述用户标识对应的归属信息,并确定所述用户标识对应的数据库层级类型;A database hierarchy type determining module, configured to query the attribution information corresponding to the user identifier from a preset database, and determine the database hierarchy type corresponding to the user identifier;
    检索类型获取模块,用于当接收所述用户端发送的数据检索请求时,获取所述数据检索请求对应的检索类型;A retrieval type acquisition module, configured to obtain the retrieval type corresponding to the data retrieval request when receiving the data retrieval request sent by the client;
    关系数据检索模块,用于若所述检索类型为关系数据库检索,则根据所述归属信息检索所述数据库层级类型对应的关系数据库,得到第一目标层次数据;A relational data retrieval module, configured to retrieve the relational database corresponding to the database hierarchy type according to the attribution information if the retrieval type is a relational database retrieval, to obtain the first target hierarchical data;
    索引数据检索模块,用于若所述检索类型为索引数据库检索,则根据所述数据检索请求与所述归属信息检索所述数据库层级类型对应的ES索引库,得到第二目标层次数据;An index data retrieval module, configured to retrieve the ES index library corresponding to the database hierarchy type according to the data retrieval request and the attribution information if the retrieval type is index database retrieval, to obtain second target hierarchical data;
    层次数据返回模块,用于返回所述第一目标层次数据或所述第二目标层次数据至所述用户端。A hierarchical data returning module, configured to return the first target hierarchical data or the second target hierarchical data to the client.
  10. 一种电子设备,其特征在于,包括存储器及处理器,所述存储器中储存有计算机程序,所述计算机程序被所述处理器执行时,使得所述处理器执行如权利要求1-8任一项所述的层次数据检索方法的步骤。An electronic device, characterized by comprising a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor executes any one of claims 1-8. The steps of the hierarchical data retrieval method described in item .
PCT/CN2022/097345 2021-11-19 2022-06-07 Hierarchical data retrieval method and apparatus, and device WO2023087673A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111389373.9A CN114116716A (en) 2021-11-19 2021-11-19 Hierarchical data retrieval method, device and equipment
CN202111389373.9 2021-11-19

Publications (1)

Publication Number Publication Date
WO2023087673A1 true WO2023087673A1 (en) 2023-05-25

Family

ID=80439691

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/097345 WO2023087673A1 (en) 2021-11-19 2022-06-07 Hierarchical data retrieval method and apparatus, and device

Country Status (2)

Country Link
CN (1) CN114116716A (en)
WO (1) WO2023087673A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116484066A (en) * 2023-06-21 2023-07-25 广东广宇科技发展有限公司 Multi-class data processing method
CN117094301A (en) * 2023-10-17 2023-11-21 北京云枢创新软件技术有限公司 Verification plan creation system

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114116716A (en) * 2021-11-19 2022-03-01 天翼数字生活科技有限公司 Hierarchical data retrieval method, device and equipment
CN114996297B (en) * 2022-04-14 2023-09-26 建信金融科技有限责任公司 Data processing method, device, equipment and medium
CN115033608B (en) * 2022-08-12 2022-11-04 广东采日能源科技有限公司 Energy storage system information grading processing method and system
CN116756301B (en) * 2023-08-17 2023-11-10 北京睿企信息科技有限公司 User information searching method, electronic equipment and storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010021929A1 (en) * 2000-02-21 2001-09-13 International Business Machines Corporation User-oriented method and system for database query
CN102769709A (en) * 2012-06-25 2012-11-07 百度在线网络技术(北京)有限公司 Method and device for supplying service contact information to users
CN110489445A (en) * 2019-08-02 2019-11-22 四川宏力信息科技有限责任公司 It is a kind of based on polymorphic compound mass data method for quickly querying
CN110580255A (en) * 2018-06-08 2019-12-17 深圳艾派网络科技股份有限公司 method and system for storing and retrieving data
CN110837515A (en) * 2019-11-06 2020-02-25 北京天融信网络安全技术有限公司 Database-based data processing method and electronic equipment
CN112347105A (en) * 2020-11-06 2021-02-09 中国电子科技集团公司第三十八研究所 General data service platform based on resource tree
CN114116716A (en) * 2021-11-19 2022-03-01 天翼数字生活科技有限公司 Hierarchical data retrieval method, device and equipment

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010021929A1 (en) * 2000-02-21 2001-09-13 International Business Machines Corporation User-oriented method and system for database query
CN102769709A (en) * 2012-06-25 2012-11-07 百度在线网络技术(北京)有限公司 Method and device for supplying service contact information to users
CN110580255A (en) * 2018-06-08 2019-12-17 深圳艾派网络科技股份有限公司 method and system for storing and retrieving data
CN110489445A (en) * 2019-08-02 2019-11-22 四川宏力信息科技有限责任公司 It is a kind of based on polymorphic compound mass data method for quickly querying
CN110837515A (en) * 2019-11-06 2020-02-25 北京天融信网络安全技术有限公司 Database-based data processing method and electronic equipment
CN112347105A (en) * 2020-11-06 2021-02-09 中国电子科技集团公司第三十八研究所 General data service platform based on resource tree
CN114116716A (en) * 2021-11-19 2022-03-01 天翼数字生活科技有限公司 Hierarchical data retrieval method, device and equipment

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116484066A (en) * 2023-06-21 2023-07-25 广东广宇科技发展有限公司 Multi-class data processing method
CN116484066B (en) * 2023-06-21 2023-12-01 广东广宇科技发展有限公司 Multi-class data processing method
CN117094301A (en) * 2023-10-17 2023-11-21 北京云枢创新软件技术有限公司 Verification plan creation system
CN117094301B (en) * 2023-10-17 2024-01-26 北京云枢创新软件技术有限公司 Verification plan creation system

Also Published As

Publication number Publication date
CN114116716A (en) 2022-03-01

Similar Documents

Publication Publication Date Title
WO2023087673A1 (en) Hierarchical data retrieval method and apparatus, and device
US11816126B2 (en) Large scale unstructured database systems
CN104160394B (en) Scalable analysis platform for semi-structured data
RU2409847C2 (en) Mapping system model to database object
US6502088B1 (en) Method and system for improved access to non-relational databases
EP2874077B1 (en) Stateless database cache
US20030195889A1 (en) Unified relational database model for data mining
US20110238703A1 (en) Time in databases and applications of databases
WO2014182852A1 (en) System for managing graph queries on relationships among entities using graph index
CN101833568B (en) Web data management system
CN102054025A (en) Traffic information resource integration processing method and system
CA2717673A1 (en) Detecting and applying database schema changes to reports
CN102999563A (en) Network resource semantic retrieval method and system based on resource description framework
US7624117B2 (en) Complex data assembly identifier thesaurus
US10762068B2 (en) Virtual columns to expose row specific details for query execution in column store databases
EP4155964A1 (en) Centralized metadata repository with relevancy identifiers
CN112699100A (en) Management and analysis system based on metadata
Arputhamary et al. A review on big data integration
Bruckner et al. A framework for a multidimensional OLAP model using topic maps
Pokorny Databases in the 3rd millennium: trends and research directions
Senapati et al. A survey on data warehouse architecture
EP4170516A1 (en) Metadata elements with persistent identifiers
Muñoz-Sánchez et al. Managing Physical Schemas in MongoDB Stores
KR100743927B1 (en) Method for an aggregate information management of spatiotemporal data in spatial data warehouse
Shah et al. Improving query performance using materialized XML views: A learning-based approach

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22894216

Country of ref document: EP

Kind code of ref document: A1