A query method, device, electronic device and storage medium

By extracting and associating database query results based on aggregate name in the query method, the problem that the actual meaning of query results in the prior art is difficult to directly provide, and more efficient and accurate query results are achieved.

CN114840724BActive Publication Date: 2025-02-28BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210451281.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-26
Publication Date
2025-02-28
Estimated Expiration
2042-04-26

AI Technical Summary

Technical Problem

When providing database query results, it is difficult to provide the actual meaning of the query results directly and efficiently, resulting in low efficiency and accuracy when processing query results.

Method used

In the query method, based on the N aggregation names in the query request, the results to be feedback are extracted from the aggregation results obtained in the database, and the aggregate name is associated with the results to be feedback to obtain the target query results.

Benefits of technology

It realizes providing query results with the aggregate name associated with them, ensuring that the actual meaning of query results is conveyed to users more accurately and efficiently, and improving the efficiency of users after processing query results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure HDA0003617271860000011
    Figure HDA0003617271860000011
  • Figure HDA0003617271860000021
    Figure HDA0003617271860000021
  • Figure HDA0003617271860000031
    Figure HDA0003617271860000031
Patent Text Reader

Abstract

The present disclosure provides a query method, device, electronic device and storage medium, which relate to the field of knowledge graphs, and in particular to natural language processing. The specific implementation scheme is: based on the query request, a first query result is obtained from the database. When the first query result contains an aggregated result, the result to be fed back is extracted from the aggregated result based on the N aggregated names in the query request; N is an integer greater than or equal to 1; the N aggregated names are associated with the result to be fed back to obtain the target query result. The technical scheme of the embodiment of the present disclosure can make the final target query result contain the various results obtained by this query and their associated aggregated names, thereby ensuring that the actual meaning of this query result is provided more accurately and efficiently.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the fields of artificial intelligence technologies such as knowledge graphs and natural language processing. Background Art

[0002] In the related art, when performing data query on a database, usually based on the query request of the user device, the query result is directly obtained from the database, and finally the query result is fed back to the user device. However, how to provide the actual meaning of the query result obtained this time more directly and efficiently becomes a problem that needs to be solved. Summary of the invention

[0003] The present disclosure provides a query method, device, electronic device and storage medium.

[0004] According to a first aspect of the present disclosure, a query method is provided, comprising:

[0005] Obtaining a first query result from a database based on the query request;

[0006] In the case where the first query result includes an aggregated result, based on the N aggregated names in the query request, the result to be fed back is extracted from the aggregated result; N is an integer greater than or equal to 1;

[0007] Associate N aggregation names with the results to be fed back to obtain the target query results.

[0008] According to a second aspect of the present disclosure, a query device is provided, including:

[0009] A query module, used to obtain a first query result from a database based on a query request;

[0010] An extraction module, configured to extract the results to be fed back from the aggregated results based on N aggregated names in the query request when the first query result includes the aggregated results; N is an integer greater than or equal to 1;

[0011] The connection module is used to associate N aggregation names with the results to be fed back to obtain the target query results.

[0012] According to a third aspect of the present disclosure, there is provided an electronic device, including:

[0013] at least one processor; and

[0014] a memory communicatively connected to the at least one processor; wherein,

[0015] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the aforementioned method.

[0016] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the aforementioned method.

[0017] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, which implements the aforementioned method when executed by a processor.

[0018] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description.

[0019] The solution provided in this embodiment can ensure that the final target query result includes the various results obtained by this query and their associated aggregation names, thereby ensuring that the actual meaning of this query result is provided more accurately and efficiently; and further ensure that after obtaining the target query result, the user side can more efficiently and accurately perform subsequent related processing based on the various results contained in the target query result, thereby improving the overall processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0021] Figure 1 is a flowchart of a query method according to an embodiment of the present disclosure;

[0022] Figure 2 is another flowchart of a query method according to an embodiment of the present disclosure;

[0023] Figure 3 is a schematic diagram of a scenario of a query method according to an embodiment of the present disclosure;

[0024] Figure 4 is a schematic diagram of a composition structure of a query device according to an embodiment of the present disclosure;

[0025] Figure 5 It is a block diagram of an electronic device used to implement the query method of the embodiment of the present disclosure. DETAILED DESCRIPTION

[0026] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0027] The first aspect of the present disclosure provides a query method, such as Figure 1 As shown, including:

[0028] S101: Acquire a first query result from a database based on a query request;

[0029] S102: When the first query result includes an aggregated result, based on N aggregate names in the query request, extract the result to be fed back from the aggregated result; N is an integer greater than or equal to 1;

[0030] S103: Associating the N aggregate names with the results to be fed back to obtain a target query result.

[0031] The query method provided in this embodiment can be applied to an electronic device, and specifically the electronic device can be a server.

[0032] The database may be an ElasticSearch database. It should be understood that the database may be other types of databases in addition to the above-mentioned ElasticSearch database, but the examples are not exhaustive here.

[0033] The query request may be sent from other devices, where the other devices may be user devices used by users, for example, any one of a smart phone, a tablet computer, a laptop computer, a personal computer, etc., which is not limited here.

[0034] After obtaining the target query result, the method may further include: feeding back the target query result to the user device.

[0035] It can be seen that by adopting the above scheme, after obtaining the first query result from the database based on the query request, the results to be fed back can be further extracted from the aggregated results of the first query result based on the aggregated name contained in the query result, and finally the aggregated name and the results to be fed back are associated to obtain the target query result of this query. In this way, the target query result finally obtained can include the various results obtained by this query and their associated aggregated names, thereby ensuring that the actual meaning of this query result is provided more accurately and efficiently; furthermore, it can ensure that after obtaining the target query result, the user side can more efficiently and accurately perform subsequent related processing based on the various results contained in the target query result, thereby improving the overall processing efficiency.

[0036] Specifically, any query request received may include query content. The query content may include at least a target index and a query statement; wherein the number of target indexes may be one or more; the query statement may specifically be a query expression (or a query DSL (Domain Specific Language)); the query expression may include description information of the content to be queried this time, such as the "match" parameter may be used to implement a precise or fuzzy query of the full text, the "range" parameter may be used to implement a query of documents or data with a specified range of values ​​contained in a specified field, etc. Various types of parameters that may be included in the query expression are not exhaustively listed in this embodiment.

[0037] Furthermore, based on the actual needs of the user side, in addition to the above query content, any query request received may also include N aggregation names; here, the N aggregation names may form a list, and the N aggregation names may specifically be N field names specified by the user for aggregate query. It should be understood that N here is only an exemplary description, and does not mean that the number of aggregation names included in different query requests needs to be the same, but is only used to indicate that different query requests may include one or more aggregation names. This embodiment is particularly suitable for scenarios where N is greater than or equal to 2.

[0038] In one embodiment, obtaining a first query result from a database based on a query request may include: when the query request includes N aggregation names, obtaining the first query result from the database based on the query content included in the query request and the N aggregation names.

[0039] Wherein, obtaining the first query result from the database based on the query content and N aggregation names included in the query request may specifically include: obtaining the initial query result from the database based on the query content included in the query request, and aggregating the initial query result based on the N aggregation names included in the query request to obtain N aggregation results; using the initial query result and the N aggregation results as the first query result. For example, extracting matching objects from the database based on the target index included in the query request; extracting the initial query result from the matching objects based on the query statement included in the query request; further, obtaining the aggregation results corresponding to each aggregation name from the initial query result in turn based on the N aggregation names included in the query request; and finally using the initial query result and the N aggregation results corresponding to the N aggregation names as the first query result.

[0040] In addition, it may also include: when the query request does not contain N aggregate names, a second query result is obtained from the database based on the query content contained in the query request. That is, if the query request does not contain N aggregate names, it can be determined that aggregation is not required; therefore, it is only necessary to extract matching objects from the database based on the target index contained in the query request, and then obtain the second query result from the matching objects based on the query statement contained in the query request. Furthermore, the second query result can be directly fed back to the user device.

[0041] The above-mentioned obtaining of the second query result from the matched object based on the query statement contained in the query request may also include: obtaining a third query result from the matched object based on the query statement contained in the query request; determining whether the third query result contains original data; if the third query result contains original data, obtaining the original data from the third query result and using the original data as the second query result; if the third query result does not contain original data, using the third query result directly as the second query result. Wherein, determining whether the third query result contains original data may specifically refer to determining whether the third query result contains a "_source (original)" key; further, if the third query result contains a "_source (original)" key, it is determined that the third query result contains original data.

[0042] In one embodiment, after obtaining the first query result from the database based on the query request, it can also include: determining whether the first query result contains aggregated results; if the first query result contains aggregated results, extracting N results to be fed back from the aggregated results based on the N aggregate names in the query request; N is an integer greater than or equal to 1; if the first query result does not contain aggregated results, end the processing.

[0043] Here, judging whether the first query result contains an aggregated result may specifically refer to judging whether the first query result contains an "aggregation" result field. This is because if N aggregation names are included in the query request, a first query result containing the aggregated result can be obtained after querying the database based on the query request; and if the first query result does not contain an aggregated result, it may be because there are no documents or data in the database of the current server that meet the conditions of the query content, so the aggregated result cannot be obtained, and the processing can be terminated at this time. In addition, when it is determined to terminate the processing, a prompt message indicating that the query result is empty can also be returned to the user device, and then the user can readjust the query request based on the prompt message, and query again based on the adjusted query request, which is not limited here.

[0044] In one embodiment, when the first query result includes the aggregation result, based on the N aggregation names in the query request, extracting the results to be fed back from the aggregation result includes: when the first query result includes the aggregation result, determining whether the order of the N aggregation field names included in the aggregation result is consistent with the order of the N aggregation names included in the query request; if they are consistent, extracting the results to be fed back from the aggregation result based on the N aggregation names in the query request.

[0045] In addition, it may also include: if there is inconsistency, then the processing is terminated. It should be understood that, in the case of determining to terminate the processing, a prompt message indicating that the query result is empty may also be returned to the user device, and then the user may readjust the query request based on the prompt message, and perform the query again based on the adjusted query request, which is not limited here.

[0046] In one embodiment, based on the N aggregation names in the query request, the results to be fed back are extracted from the aggregation results, including: based on the order of the N aggregation names in the query request, extracting the aggregation bucket results and the aggregation indicator results from the aggregation results; and using the aggregation bucket results and the aggregation indicator results as the results to be fed back.

[0047] The above-mentioned embodiment has described that N is an integer greater than or equal to 1. In a preferred example, N is an integer greater than or equal to 2.

[0048] That is to say, the N aggregation names in the above query request, i.e., the aggregation names specified by the user, can be used to extract the aggregation bucket results and the aggregation index results from the aggregation results in sequence based on the N aggregation names, and then use the aggregation bucket results and the aggregation index results as the results to be fed back. In this way, the corresponding aggregation bucket results and the aggregation index results can be extracted in sequence from the aggregation results in combination with the order of the aggregation names in the query request, thereby ensuring the consistency of the order between the various results and the aggregation names in the final target query result.

[0049] In one implementation, based on the order of the N aggregation names in the query request, extracting the aggregation bucket results and the aggregation index results from the aggregation results may include:

[0050] When the current recursion depth is less than or equal to N-1, extract the current aggregation name in sequence based on the order of the first N-1 aggregation names in the query request, extract the current bucket aggregation intermediate result from the previous bucket aggregation intermediate result based on the current aggregation name, and increase the current recursion depth by one; wherein the previous bucket aggregation intermediate result is obtained based on the aggregation result;

[0051] When the current recursion depth is greater than N-1, the current bucket aggregation intermediate result is used as the aggregate bucket result, and the aggregate indicator result is extracted from the aggregate result based on the Nth aggregation name in the query request.

[0052] The initial value of the current recursion depth may be 0. In the case where the current recursion depth is less than or equal to N-1, the current aggregation name is extracted in sequence based on the order of the first N-1 aggregation names in the query request, the current bucket aggregation intermediate result is extracted from the previous bucket aggregation intermediate result based on the current aggregation name, and the current recursion depth is increased by one. Specifically, it may include: determining whether the current recursion depth is less than or equal to N-1, if the current recursion depth is less than or equal to N-1, determining to perform this recursive processing, extracting the current aggregation name based on the order of the first N-1 aggregation names in the query request, extracting the current bucket aggregation intermediate result from the previous bucket aggregation intermediate result based on the current aggregation name, and increasing the current recursion depth by one.

[0053] That is to say, each time a recursive process is executed, it is first determined whether the current recursive depth is less than or equal to N-1. This is because when the query request contains N aggregation names, the first N-1 aggregation names default to the aggregation names corresponding to the N-1 aggregation buckets, and the Nth aggregation name defaults to the indicator aggregation name. Therefore, N-1 recursive processes need to be executed to extract the above aggregation bucket results.

[0054] Among them, if this recursive processing is the first recursive processing, the previous bucket aggregation intermediate result is obtained based on the aggregation result, which specifically refers to: the aggregation result is directly used as the previous bucket aggregation intermediate result. If this recursive processing is not the first recursive processing, the previous bucket aggregation intermediate result is obtained based on the aggregation result, which specifically refers to the previous bucket aggregation intermediate result being obtained after executing multiple recursive processing based on the aggregation result.

[0055] Furthermore, each time a recursive process is completed, the current recursive depth is increased by 1 to obtain an updated current recursive depth; it is determined again whether the current recursive depth is less than or equal to N-1. If the current recursive depth is less than or equal to N-1, it is determined to execute the next recursive process.

[0056] When the current recursion depth is greater than N-1, the current bucket aggregation intermediate result is used as the aggregate bucket result, that is, the bucket aggregation intermediate result obtained by executing the last recursive processing is used as the aggregate bucket result. In addition, when it is determined that the current recursion depth is greater than N-1, it can be determined that there is still an Nth aggregation name left in the query result. At this time, based on the Nth aggregation name in the query request, the aggregate index result is extracted from the aggregation result. In other words, the Nth aggregation name (that is, the last aggregation name) is used as the index aggregation name, and the aggregate index result is extracted from the aggregation result based on the index aggregation name.

[0057] It should be noted that the number of the aforementioned aggregate bucket results may be one or more, and the number of the aforementioned aggregate indicator results may also be one or more.

[0058] By adopting the above solution, the aggregate bucket results and aggregate index results can be extracted from the aggregate results in sequence based on the order of the N aggregate names contained in the query request. In this way, the order of the aggregate bucket results and aggregate index results finally extracted can match the order of the N aggregate names, ensuring the accuracy of the target query results finally obtained.

[0059] In one implementation, based on the Nth aggregation name in the query request, extracting the aggregation indicator result from the aggregation result includes:

[0060] Based on the order of M aggregation indicator names contained in the Nth aggregation name in the query request, M indicator calculation results are extracted from the aggregation result, and the aggregation indicator result is generated based on the M indicator calculation results; M is an integer greater than or equal to 1.

[0061] In one example, M is equal to 1, that is, the Nth aggregation name contains only one aggregation indicator name, and based on the aggregation indicator name, the corresponding indicator calculation result can be directly extracted from the aggregation result as the aggregation indicator result.

[0062] It should be noted that, when there is one aggregation indicator name, one or more indicator calculation results corresponding to the aggregation indicator name can be extracted from the aggregation result, that is, one or more aggregation indicator results can be obtained. The number of the aggregation indicator results can be the same as the number of the aforementioned aggregation bucket results. For example, if the aforementioned N aggregation names are 4, they are: city, region, street, and sum. Correspondingly, the first three aggregation names are used to extract the aggregation bucket results, and the number of the finally extracted aggregation bucket results can be one or more, for example, it can include the first aggregation bucket result of city 1, region 1 and street 1, the second aggregation bucket result of city 1, region 2 and street 2, the third aggregation bucket result of city 2, region 3 and street 3, the fourth aggregation bucket result of city 2, region 3 and street 4, and so on. In addition, if the last aggregation name is the indicator aggregation name "sum", one or more aggregation indicator results are extracted from all the aggregation results. Corresponding to the above, if there are 4 aggregation bucket results, the corresponding aggregation indicator results can also be 4 groups (or 4), for example, sum result 1, sum result 2, sum result 3 and sum result 4 can be extracted. For another example, if the aforementioned N aggregation names are 4, namely: city 1, region 1, street, and average; accordingly, the first three aggregation names are used to extract the aggregation bucket results, and the number of the finally extracted aggregation bucket results can be one or more, for example, it can include the first aggregation bucket result of city 1, region 1 and street 11, and the second aggregation bucket result of city 1, region 1 and street 12. In addition, the last aggregation name is the indicator aggregation name "average", then one or more aggregation indicator results are extracted from all the aggregation results; corresponding to the above, if there are 2 aggregation bucket results, the corresponding aggregation indicator results can also be 2 groups (or 2), for example, average value calculation result 1 and average value calculation result 2 can be extracted.

[0063] In another example, M is greater than 1, that is, the Nth aggregation name contains M aggregation indicator names, and the M aggregation indicator names may appear in the form of an array. Other possible forms of the M aggregation indicator names are not limited here.

[0064] The aforementioned process of extracting M indicator calculation results from the aggregation results based on the order of the M aggregation indicator names contained in the Nth aggregation name in the query request, and generating the aggregation indicator result based on the M indicator calculation results, may specifically include: extracting M indicator calculation results from the aggregation results in sequence based on the order of the M aggregation indicator names contained in the Nth aggregation name in the query request, and taking the M indicator calculation results obtained each time as an aggregation indicator result. In other words, the above process of extracting M indicator calculation results based on M aggregation indicator names and forming the M indicator calculation results into an aggregation indicator result may be a traversal operation, that is, after traversing the aggregation results, one or more aggregation indicator results may be obtained, and each aggregation indicator result may contain M indicator calculation results. It should be understood that the indicator calculation results contained in each of the aforementioned aggregation indicator results may specifically be numerical values.

[0065] It should be pointed out that when there are 2 or more aggregation indicator names, 2 or more aggregation indicator names can be used as an aggregation indicator name group. Based on an aggregation indicator name group, one or more different indicator calculation results can be extracted from the aggregation result each time as an aggregation indicator result, and finally one or more aggregation indicator results can be obtained. The number of the aggregation indicator results can be the same as the number of the aforementioned aggregation bucket results. For example, if the aforementioned N aggregation names are 4, they are: city, region, street, (sum, average). Correspondingly, the first three aggregation names are used to extract the aggregation bucket results, and the number of the aggregation bucket results finally extracted can be one or more, for example, it can include the first aggregation bucket result of city 1, region 1 and street 1, the second aggregation bucket result of city 1, region 2 and street 2, the third aggregation bucket result of city 2, region 3 and street 3, the fourth aggregation bucket result of city 2, region 3 and street 4, and so on. In addition, if the last aggregation name is the indicator aggregation name "sum, average", the sum result and the average calculation result are extracted from all the aggregation results in sequence as an aggregation indicator result. Corresponding to the above, if there are 4 aggregation bucket results, the corresponding aggregation indicator results can also be 4 groups (or 4), for example, (sum result 1, average calculation result 1), (sum result 2, average calculation result 2), (sum result 3, average calculation result 3) and (sum result 4, average calculation result 4) can be extracted.

[0066] It can be seen that by adopting the above solution, when the Nth aggregation name contains one or more aggregation indicator names, the aggregation indicator results can be extracted from the aggregation results in sequence based on the order of the aggregation indicator names. Thus, the order of the aggregation indicator results is guaranteed to be consistent with the order of the aggregation indicator names, thereby ensuring the accuracy of the final target query result.

[0067] In one embodiment, N aggregation names are associated with the results to be fed back to obtain a target query result, including: associating the aggregation bucket results and aggregation indicator results contained in the results to be fed back to obtain the associated total aggregation result; associating N aggregation names with the total aggregation result to obtain the target query result.

[0068] Specifically, the number of aggregate bucket results is one or more; each aggregate bucket result in one or more aggregate bucket results is a result extracted based on the aforementioned N-1 aggregate names. For example, the N-1 aggregate names are "time 1-time 2", "city" and "street". Accordingly, based on these three aggregate names, an aggregate bucket result under street A1 in city A from time 1 to time 2 can be obtained, and another aggregate bucket result under street B1 in city B can be obtained based on time 1-time 2, and so on, so that multiple aggregate bucket results can be obtained. As mentioned above, the number of the aforementioned aggregate indicator results can also be one or more, and each aggregate indicator result contains one or more indicator calculation results. It should also be understood that the aforementioned Nth aggregate name can contain M aggregate indicator names, regardless of whether M is equal to 1 or greater than 1, because the order of extracting each aggregate indicator result is consistent with the order of the M aggregate indicator names, therefore, when associating the M aggregate indicator names in the Nth aggregate name with the M aggregate indicator results, it can also be guaranteed to be one-to-one. The above one or more aggregate bucket results are connected with one or more aggregate indicator results to obtain the aggregate indicator result associated with each aggregate bucket result. For example, one aggregation bucket result is associated with the value of index 1 as 11 and the value of index 2 as 21; another aggregation bucket result is associated with the value of index 1 as 12 and the value of index 2 as 22; another bucket aggregation result is associated with the value of index 1 as 13 and the value of index 2 as 23, etc., which are not exhaustive here. That is, the total aggregation result includes each aggregation bucket result and its associated aggregation index results.

[0069] The aforementioned associating N aggregation names with the total aggregation result to obtain the target query result may mean associating the first N-1 aggregation names among the N aggregation names with the aggregation bucket results in the total aggregation result, associating the Nth aggregation name with the aggregation indicator result, and obtaining the associated result as the target query result.

[0070] It should be understood that the aforementioned association processing can be implemented specifically through a connection operation, and the connection operation can refer to a Cartesian product operation. Alternatively, the aforementioned association processing can be implemented in other ways, and all possible implementation methods are not exhaustively listed here.

[0071] It can be seen that by adopting the above scheme, N aggregation names, aggregation bucket results and aggregation indicator results can be associated through connection operations to ensure that the target query result contains the name information corresponding to each result, and the actual meaning of this query result can be provided more directly and efficiently; further, it can ensure that after the user side obtains the target query result, it can more efficiently and accurately perform subsequent related processing based on the various results contained in the target query result, thereby improving the overall processing efficiency.

[0072] Combine the following Figure 2 and Figure 3 The solution provided in this embodiment is exemplified as follows:

[0073] S201: receiving a query request sent by a user equipment.

[0074] like Figure 3 As shown, Figure 3 The query request in is sent by the user device to the server.

[0075] S202: Determine whether the query request contains N aggregation names. If the query request does not contain N aggregation names, obtain a second query result from the database based on the query content contained in the query request, and return the second query result to the user device to end the processing; otherwise, execute S203.

[0076] Specifically, after determining whether the query request contains N aggregation names, if it is determined that the query request does not contain N aggregation names, it can be determined that the current user has not specified an aggregation query, and the query content is sent to the database for retrieval to obtain a second query result, and the second query result is returned to the user device; otherwise, S203 is executed. The database may be an ElasticSearch database; the query content may include a target index and a query statement, and the specific description of the target index and the query statement is the same as that of the previous embodiment, and will not be repeated.

[0077] Furthermore, the above-mentioned obtaining the second query result from the matched object based on the query statement contained in the query request may also include: obtaining the third query result from the matched object based on the query statement contained in the query request; determining whether the third query result contains original data; if the third query result contains original data, obtaining the original data from the third query result and using the original data as the second query result; if the third query result does not contain original data, using the third query result directly as the second query result. Wherein, determining whether the third query result contains original data may specifically refer to determining whether the third query result contains the "_source (original)" key; further, if the third query result contains the "_source (original)" key, it is determined that the third query result contains original data.

[0078] S203: Based on the query content and the N aggregation names included in the query request, obtain a first query result from the database.

[0079] like Figure 3 As shown, the server obtains the first query result from the database based on the query content and N aggregate names included in the query request.

[0080] S204: Determine whether the first query result contains the aggregated result. If not, end the process; if contained, execute S205.

[0081] It should be understood that when it is determined to end the processing, a prompt message indicating that the query result is empty can also be returned to the user device. Then, the user can readjust the query request based on the prompt message and query again based on the adjusted query request. This is not limited here.

[0082] S205: Determine whether the order of the N aggregation field names included in the aggregation result is consistent with the order of the N aggregation names included in the query request. If not, end the processing; if consistent, execute S206.

[0083] Similarly, when it is determined to end the processing, a prompt message indicating that the query result is empty can be returned to the user device. Then, the user can readjust the query request based on the prompt message and query again based on the adjusted query request. This is not limited here.

[0084] S206: Determine whether the current recursion depth is less than or equal to N-1. If the current recursion depth is less than or equal to N-1, execute S207; otherwise, execute S208.

[0085] S207: Based on the order of the first N-1 aggregation names in the query request, extract the current aggregation name in sequence, extract the current bucket aggregation intermediate result from the previous bucket aggregation intermediate result based on the current aggregation name, increase the current recursion depth by one, and return to execute S206.

[0086] Among them, if this recursive processing is the first recursive processing, the previous bucket aggregation intermediate result is obtained based on the aggregation result, which specifically refers to: the aggregation result is directly used as the previous bucket aggregation intermediate result. If this recursive processing is not the first recursive processing, the previous bucket aggregation intermediate result is obtained based on the aggregation result, which specifically refers to the previous bucket aggregation intermediate result being obtained after executing multiple recursive processing based on the aggregation result.

[0087] S208: When the current recursion depth is greater than N-1, the current bucket aggregation intermediate result is used as the aggregated bucket result, and based on the Nth aggregation name in the query request, the aggregated indicator result is extracted from the aggregated result.

[0088] Combination Figure 3 For example, suppose N is equal to 4, that is, there are 4 aggregation names in the query request; correspondingly, N-1 is equal to 3. For example, the current recursive depth is the initial value 0. When the first recursive processing is executed, the first aggregation name "time 1-time 2" is extracted from the 4 aggregation names. Based on the first aggregation name, all results containing "time 1-time 2" are obtained from the aggregation results as the first bucket aggregation intermediate result, and then the current recursive depth is increased by one; the current recursive depth is 1 (less than N-1), and the second recursive processing is executed to extract the second aggregation name "region" from the 4 aggregation names. Based on the second aggregation name, the first bucket aggregation intermediate result is obtained from the first bucket aggregation intermediate result. All the results containing the "region" are obtained from the results as the intermediate results of the second bucket aggregation, and then the current recursive depth is increased by one; the current recursive depth is 2 (less than N-1), and the third recursive processing is performed. The third aggregation name is "street". Based on the third aggregation name, all the results containing the "street" are obtained from the intermediate results of the second bucket aggregation as the intermediate results of the third bucket aggregation, and then the current recursive depth is increased by one; the current recursive depth is 3 (equal to N-1), and it is determined to use the intermediate results of the third bucket aggregation as the aggregation bucket result. At this time, Figure 3 As shown, the aggregated bucket results may include three aggregated bucket results, namely, bucket 1, bucket 2, and bucket 3. Then, based on the fourth aggregation name in the query request (such as sum and average), three aggregated index results are extracted from the aggregated results, and each aggregated index result includes a total value calculated by summing and an average value calculated by averaging.

[0089] It should be understood that the above is only an exemplary description, and in actual processing, N can take other values, such as 5, 6, or larger or smaller, but preferably N is greater than or equal to 2, and no exhaustive enumeration is performed here.

[0090] S209: taking the aggregated bucket result and the aggregated index result as the result to be fed back, associating the N aggregated names with the result to be fed back, obtaining the target query result, and feeding back the target query result to the user device.

[0091] Combination Figure 3 For example, the aggregated bucket results (i.e., bucket 1, bucket 2, bucket 3) can be finally associated with sum 1, average 1, sum 2, average 2, and sum 3 average 3 respectively; then "time 1-time 2", "region", and "street" are associated with the aggregated bucket results (i.e., bucket 1, bucket 2, bucket 3), and "sum" is associated with the final "sum 1, sum 2, and sum 3", and "average" is associated with "average 1, average 2, average 3" to obtain the final target query result; and the target query result can be fed back to the user device.

[0092] The present disclosure also provides a query device, such as Figure 4 As shown, including:

[0093] A query module 401 is used to obtain a first query result from a database based on a query request;

[0094] An extraction module 402 is used to extract the results to be fed back from the aggregated results based on N aggregated names in the query request when the first query results include the aggregated results; N is an integer greater than or equal to 1;

[0095] The connection module 403 is used to associate the N aggregation names with the results to be fed back to obtain the target query results.

[0096] In one implementation, the extraction module 402 is used to extract the aggregation bucket results and the aggregation index results from the aggregation results based on the order of the N aggregation names in the query request; and use the aggregation bucket results and the aggregation index results as the results to be fed back.

[0097] In one embodiment, the extraction module 402 is used to extract the current aggregation name in sequence based on the order of the first N-1 aggregation names in the query request when the current recursion depth is less than or equal to N-1, extract the current bucket aggregation intermediate result from the previous bucket aggregation intermediate result based on the current aggregation name, and increase the current recursion depth by one; wherein the previous bucket aggregation intermediate result is obtained based on the aggregation result; when the current recursion depth is greater than N-1, use the current bucket aggregation intermediate result as the aggregation bucket result, and extract the aggregation indicator result from the aggregation result based on the Nth aggregation name in the query request.

[0098] In one embodiment, the extraction module 402 is used to extract M aggregation indicator results from the aggregation results in sequence based on the order of M aggregation indicator names contained in the Nth aggregation name in the query request; M is an integer greater than or equal to 1.

[0099] In one embodiment, the connection module 403 is used to associate the aggregation bucket results and the aggregation indicator results included in the feedback results to obtain the associated total aggregation results; associate N aggregation names with the total aggregation results to obtain the target query results.

[0100] By adopting the above scheme, after obtaining the first query result from the database based on the query request, the results to be fed back can be further extracted from the aggregated results of the first query result based on the aggregated name contained in the query result, and finally the target query result of this query can be obtained after associating the aggregated name and the results to be fed back. In this way, the target query result finally obtained can more accurately include the various results obtained by this query and their associated aggregated names, ensuring that the actual meaning of this query result is provided more directly and efficiently; furthermore, it can ensure that after obtaining the target query result, the user side can more efficiently and accurately perform subsequent related processing based on the various results contained in the target query result, thereby improving the overall processing efficiency.

[0101] In the technical solution disclosed herein, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0102] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

[0103] Figure 5A schematic block diagram of an example electronic device 500 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0104] like Figure 5 As shown, the electronic device 500 includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 502 or a computer program loaded from a storage unit 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 can also be stored. The computing unit 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0105] Multiple components in the electronic device 500 are connected to the I / O interface 505, including: an input unit 506, such as a keyboard, a mouse, etc.; an output unit 507, such as various types of displays, speakers, etc.; a storage unit 508, such as a disk, an optical disk, etc.; and a communication unit 509, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 509 allows the electronic device 500 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0106] The computing unit 501 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 501 performs the query method described above. For example, in some embodiments, the query method described above may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 500 via ROM 502 and / or communication unit 509. When the computer program is loaded into RAM 503 and executed by the computing unit 501, one or more steps of the query method described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to perform the query method described above in any other appropriate manner (e.g., by means of firmware).

[0107] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0108] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0109] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0110] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0111] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0112] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.

[0113] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0114] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A query method, comprising: Obtaining a first query result from a database based on a query request, wherein the query request includes query content and N aggregation names; In the case where the first query result includes an aggregation result, based on the order of the N aggregation names in the query request, extracting the aggregation bucket result and the aggregation index result from the aggregation result; using the aggregation bucket result and the aggregation index result as the result to be fed back, where N is an integer greater than or equal to 1; Associating the N aggregate names with the results to be fed back to obtain a target query result; Among them, the extracting of the aggregate bucket result and the aggregate index result from the aggregate result based on the order of the N aggregate names in the query request includes: when the current recursive depth is less than or equal to N-1, based on the order of the first N-1 aggregate names in the query request, extracting the current aggregate name in sequence, extracting the current bucket aggregate intermediate result from the previous bucket aggregate intermediate result based on the current aggregate name, and increasing the current recursive depth by one; wherein the previous bucket aggregate intermediate result is obtained based on the aggregate result; when the current recursive depth is greater than N-1, taking the current bucket aggregate intermediate result as the aggregate bucket result, and extracting the aggregate index result from the aggregate result based on the Nth aggregation name in the query request.

2. The method according to claim 1, wherein: The extracting the aggregation indicator result from the aggregation result based on the Nth aggregation name in the query request includes: Based on the order of the M aggregation indicator names contained in the Nth aggregation name in the query request, M indicator calculation results are extracted from the aggregation result, and the aggregation indicator result is generated based on the M indicator calculation results; M is an integer greater than or equal to 1.

3. The method according to claim 1, wherein: The associating the N aggregate names with the results to be fed back to obtain the target query result includes: The aggregation bucket result and the aggregation index result included in the result to be fed back are associated to obtain the associated total aggregation result; the N aggregation names are associated with the total aggregation result to obtain the target query result.

4. A query device, comprising: A query module, configured to obtain a first query result from a database based on a query request, wherein the query request includes a query content and N aggregation names; An extraction module, configured to extract an aggregate bucket result and an aggregate index result from the aggregate result based on the order of the N aggregate names in the query request when the first query result includes an aggregate result; and use the aggregate bucket result and the aggregate index result as the result to be fed back, where N is an integer greater than or equal to 1; A connection module, used for associating the N aggregate names with the results to be fed back to obtain a target query result; The extraction module is specifically used to extract the current aggregation name in sequence based on the order of the first N-1 aggregation names in the query request when the current recursion depth is less than or equal to N-1, extract the current bucket aggregation intermediate result from the previous bucket aggregation intermediate result based on the current aggregation name, and increase the current recursion depth by one; wherein the previous bucket aggregation intermediate result is obtained based on the aggregation result; when the current recursion depth is greater than N-1, use the current bucket aggregation intermediate result as the aggregation bucket result, and extract the aggregation indicator result from the aggregation result based on the Nth aggregation name in the query request.

5. The device according to claim 4, wherein: The extraction module is used to extract M aggregation indicator results from the aggregation results in sequence based on the order of M aggregation indicator names contained in the Nth aggregation name in the query request; M is an integer greater than or equal to 1.

6. The device according to claim 4, wherein: The connection module is used to associate the aggregation bucket results and the aggregation indicator results contained in the results to be fed back to obtain the associated total aggregation results; and associate the N aggregation names with the total aggregation results to obtain the target query results.

7. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 3.

8. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-3.

9. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Data analysis method and device

    CN110781211A

  • Method and device for generating data query statement, server and storage medium

    CN113468208A