CN114840724A - Query method, query device, electronic equipment and storage medium - Google Patents

Query method, query device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114840724A
CN114840724A CN202210451281.7A CN202210451281A CN114840724A CN 114840724 A CN114840724 A CN 114840724A CN 202210451281 A CN202210451281 A CN 202210451281A CN 114840724 A CN114840724 A CN 114840724A
Authority
CN
China
Prior art keywords
result
aggregation
query
names
index
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210451281.7A
Other languages
Chinese (zh)
Inventor
赵安铭
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and Technology Co Ltd
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 Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN202210451281.7A priority Critical patent/CN114840724A/en
Publication of CN114840724A publication Critical patent/CN114840724A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/90335Query processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/9038Presentation of query results

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The disclosure provides a query method, a query device, electronic equipment and a storage medium, and relates to the field of knowledge graphs, in particular to natural language processing. The specific implementation scheme is as follows: acquiring a first query result from a database based on a query request, and extracting a result to be fed back from an aggregation result based on N aggregation names in the query request under the condition that the first query result contains the aggregation result; n is an integer greater than or equal to 1; and associating the N aggregation names with the result to be fed back to obtain a target query result. According to the technical scheme of the embodiment of the disclosure, the finally obtained target query result can include each result obtained by the query and the associated aggregation name thereof, so that the actual meaning of the query result can be provided more accurately and efficiently.

Description

Query method, query device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of artificial intelligence techniques such as knowledge-graph and natural language processing.
Background
In the related art, in the process of performing data query on a database, a query result is usually directly obtained from the database based on a query request obtained from a user equipment, and the query result is finally fed back to the user equipment. However, how to more directly and efficiently provide the actual meaning of the query result obtained this time becomes a problem to be solved.
Disclosure of Invention
The disclosure provides a query method, a query device, an electronic device and a storage medium.
According to a first aspect of the present disclosure, there is provided a query method, including:
acquiring a first query result from a database based on the query request;
under the condition that the first query result contains the aggregation result, extracting a result to be fed back from the aggregation result based on N aggregation names in the query request; n is an integer greater than or equal to 1;
and associating the N aggregation names with the result to be fed back to obtain a target query result.
According to a second aspect of the present disclosure, there is provided a query apparatus, including:
the query module is used for acquiring a first query result from the database based on the query request;
the extracting module is used for extracting a result to be fed back from the aggregation result based on the N aggregation names in the query request under the condition that the first query result contains the aggregation result; n is an integer greater than or equal to 1;
and the connection module is used for associating the N aggregation names with the result to be fed back to obtain a target query result.
According to a third aspect of the present disclosure, there is provided an electronic device comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method described above.
According to a fourth aspect of the present disclosure, there is provided a non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the aforementioned method.
According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the aforementioned method.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
According to the scheme provided by the embodiment, the finally obtained target query result can comprise each result obtained by the query and the associated aggregation name thereof, so that the actual meaning of the query result can be provided more accurately and efficiently; and then, after the user side obtains the target query result, the follow-up related processing can be more efficiently and accurately carried out on each result contained in the target query result, and the overall processing efficiency is improved.
Drawings
The drawings are included to provide a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
FIG. 1 is a flow diagram of a query method according to an embodiment of the present disclosure;
FIG. 2 is another flow diagram of a query method according to an embodiment of the present disclosure;
FIG. 3 is a schematic diagram of a scenario of a query method according to an embodiment of the present disclosure;
FIG. 4 is a schematic diagram of an exemplary configuration of a query device, according to an embodiment of the present disclosure;
FIG. 5 is a block diagram of an electronic device used to implement the query method of an embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of the embodiments of the disclosure are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
An embodiment of a first aspect of the present disclosure provides a query method, as shown in fig. 1, including:
s101: acquiring a first query result from a database based on the query request;
s102: under the condition that the first query result contains the aggregation result, extracting a result to be fed back from the aggregation result based on N aggregation names in the query request; n is an integer greater than or equal to 1;
s103: and associating the N aggregation names with the result to be fed back to obtain a target query result.
The query method provided by the embodiment can be applied to electronic equipment, and the electronic equipment can be a server.
The database may be an elastic search database. It should be understood that the database may be other types of databases besides the aforementioned elastic search database, which is not exhaustive here.
The query request may be sent by other devices, where the other devices may be user devices used by users, for example, any one of smartphones, tablet computers, notebook computers, personal computers, and the like, which is not limited herein.
After obtaining the target query result, the method may further include: and feeding back the target query result to the user equipment.
Therefore, by adopting the scheme, after the first query result is obtained from the database based on the query request, the result to be fed back is further extracted from the aggregated result of the first query result based on the aggregated name contained in the query result, and finally, the aggregated name and the result to be fed back are associated to obtain the target query result of the query. Therefore, the finally obtained target query result can contain each result obtained by the query and the associated aggregation name thereof, so that the actual meaning of the query result can be provided more accurately and efficiently; and then, after the user side obtains the target query result, the follow-up related processing can be more efficiently and accurately carried out on each result contained in the target query result, and the overall processing efficiency is improved.
In particular, the query content may be included in any one received query request. The query content at least comprises a target index and a query statement; wherein, the number of the target indexes can be one or more; the query statement may specifically be a query expression (or referred to as query DSL (Domain Specific Language)); the query expression may include description information of the content to be queried this time, for example, it may implement full-text accurate or fuzzy query through a "match" parameter, implement query on a document or data with a specified range value included in a specified field through a "range" parameter, and the like, and various types of parameters that may be included in the query expression are not exhaustive in this embodiment.
Further, based on the actual requirement of the user side, the query request received at any time can contain N aggregation names in addition to the query content; 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 performing aggregation query. It should be understood that N is merely an example, and does not represent that the number of aggregation names included in different query requests needs to be the same, and is only used to represent that one or more aggregation names may be included in different query requests. The embodiment is particularly suitable for scenes with N greater than or equal to 2.
In one embodiment, obtaining the first query result from the database based on the query request may include: and under the condition that the query request contains N aggregation names, acquiring a first query result from the database based on the query content contained in the query request and the N aggregation names.
The obtaining of the first query result from the database based on the query content and the N aggregation names included in the query request may specifically include: acquiring initial query results from a database based on query contents contained in the query request, and aggregating the initial query results based on N aggregation names contained in the query request to obtain N aggregation results; and taking the initial query result and the N aggregation results as a first query result. For example, the matched object is extracted from the database based on the target index contained in the query request; extracting an initial query result from the matched object based on a query statement contained in the query request; further, acquiring aggregation results corresponding to the aggregation names from the initial query result in sequence based on the N aggregation names contained in the query request; and finally, taking the initial query result and N aggregation results corresponding to the N aggregation names as a first query result.
In addition, the method can also comprise the following steps: and under the condition that the query request does not contain the N aggregation names, obtaining a second query result from the database based on the query content contained in the query request. That is, if the query request does not include N aggregation names, it may be determined that aggregation is not required; therefore, only the matched object needs to be extracted from the database based on the target index included in the query request, and then the second query result is obtained from the matched object based on the query statement included in the query request. Further, the second query result may be fed back directly to the user device.
The obtaining a second query result from the matched object based on the query statement included in the query request may further include: acquiring a third query result from the matched object based on the query statement contained in the query request; judging whether the third query result contains original data or not; under the condition that the third query result contains the original data, acquiring the original data from the third query result, and taking the original data as a second query result; and in the case that the third query result does not contain the original data, directly taking the third query result as the second query result. Judging whether the third query result contains original data, specifically, judging whether the third query result contains a 'source' key; further, if the third query result includes a "_ source" key, it is determined that the third query result includes the original data.
In one embodiment, after obtaining the first query result from the database based on the query request, the method may further include: judging whether the first query result contains an aggregation result; under the condition that the first query result contains the aggregation result, extracting N results to be fed back from the aggregation result based on N aggregation names in the query request; n is an integer greater than or equal to 1; if the first query result does not include the aggregated result, the process ends.
Here, the determining whether the first query result includes an aggregation result may specifically refer to determining whether the first query result includes an "aggregation" result field. If the query request contains N aggregation names, a first query result containing an aggregation result can be obtained after the query is performed from the database based on the query request; if the first query result does not include the aggregated result, the aggregated result may not be obtained because the document or data meeting the condition of the query content does not exist in the database of the current server, and the process may be ended. In addition, when the end of the processing is determined, a prompt message indicating that the current query result is empty may be returned to the user equipment, and further, 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 herein.
In an embodiment, in the case that the first query result includes the aggregated result, extracting the result to be fed back from the aggregated result based on the N aggregation names in the query request includes: under the condition that the first query result contains the aggregation result, judging whether the sequence of the N aggregation field names contained in the aggregation result is consistent with the sequence of the N aggregation names contained in the query request or not; and if the N aggregation names are consistent with the N aggregation names in the query request, extracting the result to be fed back from the aggregation result.
In addition, the method can also comprise the following steps: if not, the process ends. It should be understood that, in the case of determining to end the processing, a prompt message indicating that the result of the query is empty may be returned to the user equipment, and further, 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 herein.
In one embodiment, extracting the result to be fed back from the aggregated result based on N aggregated names in the query request includes: extracting a polymerization bucket result and a polymerization index result from the polymerization result based on the sequence of the N polymerization names in the query request; and taking the result of the polymerization barrel and the result of the polymerization index as a result to be fed back.
The foregoing embodiments have explained that N is an integer of 1 or more, and in a preferred example, N is an integer of 2 or more.
That is to say, the N aggregation names in the query request, that is, the aggregation name specified by the user, may sequentially extract the aggregation result and the aggregation indicator result from the aggregation result based on the N aggregation names, and then use the aggregation result and the aggregation indicator result as the result to be fed back. In this way, the corresponding aggregation bucket results and aggregation index results can be sequentially extracted from the aggregation results in combination with the order of the aggregation names in the query request, so that the consistency of the order between each result and the aggregation name in the finally obtained target query result is ensured.
In one embodiment, extracting the aggregation bucket result and the aggregation index result from the aggregation result based on the order of the N aggregation names in the query request may include:
under the condition that the current recursion depth is less than or equal to N-1, sequentially extracting current aggregation names based on the sequence of the first N-1 aggregation names in the query request, extracting current bucket aggregation intermediate results from the previous bucket aggregation intermediate results based on the current aggregation names, and adding one to the current recursion depth; wherein the last bucket polymerization intermediate result is obtained based on the polymerization result;
and under the condition that the current recursion depth is larger than N-1, taking the current bucket aggregation intermediate result as an aggregation bucket result, and extracting an aggregation index result from the aggregation result on the basis of the Nth aggregation name in the query request.
The initial value of the aforementioned current recursion depth may be 0. The aforementioned extracting, in the case that the current recursion depth is less than or equal to N-1, the current aggregation name in sequence 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 adding one to the current recursion depth may specifically include: judging 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 execute the recursion processing, extracting the current aggregation name based on the sequence 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 adding one to the current recursion depth.
That is, when each recursion process is executed, it is determined whether the current recursion depth is less than or equal to N-1, because when the query request includes 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 default to the index aggregation name, so that the recursion processes are executed N-1 times to extract the result of the aggregation buckets.
When the current recursion process is the first recursion process, the previous bucket aggregation intermediate result is obtained based on the aggregation result, which may specifically be: and directly taking the polymerization result as the middle result of the last barrel polymerization. In a case where the current recursion processing is not the first recursion processing, the previous bucket aggregation intermediate result is obtained based on the aggregation result, which may specifically refer to the previous bucket aggregation intermediate result obtained after performing multiple recursion processing based on the aggregation result.
Further, under the condition that each time the recursion processing is completed, the current recursion depth is added with 1 to obtain the updated current recursion depth; and judging whether the current recursion depth is less than or equal to N-1 again, and if the current recursion depth is less than or equal to N-1, determining to execute the next recursion processing.
And in the case that the current recursion depth is greater than N-1, taking the current bucket aggregation intermediate result as an aggregation bucket result, namely taking the bucket aggregation intermediate result obtained by performing the last recursion processing as the aggregation bucket result. And in the case that the current recursion depth is determined to be larger than N-1, the Nth aggregation name in the query result can be determined to be remained, and at the moment, the aggregation index result is extracted from the aggregation result based on the Nth aggregation name in the query request. That is, the nth aggregation name (i.e., the last aggregation name) is taken as an index aggregation name based on which the aggregation index result is extracted from the aggregation results.
It should be noted that the number of the aggregation bucket results may be one or more, and the number of the aggregation indicator results may also be one or more.
By adopting the scheme, the aggregation bucket result and the aggregation index result can be sequentially extracted from the aggregation result based on the sequence of the N aggregation names contained in the query request. Therefore, the sequence of the final extracted aggregation bucket result and the aggregation index result can be matched with the sequence of the N aggregation names, and the accuracy of the final obtained target query result is ensured.
In one embodiment, extracting the aggregation index result from the aggregation result based on the nth aggregation name in the query request includes:
extracting M index calculation results from the aggregation results based on the sequence of the M aggregation index names contained in the Nth aggregation name in the query request, and generating an aggregation index result based on the M index calculation results; m is an integer of 1 or more.
In one example, M is equal to 1, that is, only one aggregation indicator name is included in the nth aggregation name, based on which the corresponding indicator calculation result can be directly extracted from the aggregation result as the aggregation indicator result.
It should be noted that, in the case that the aggregation index name is 1, one or more index calculation results corresponding to the aggregation index name may be extracted from the aggregation result, that is, one or more aggregation index results may be obtained. The number of the polymerization indicator results and the number of the polymerization bucket results may be the same. For example, if the aforementioned N aggregation names are 4, they are respectively: city, area, street, sum. Accordingly, the first three aggregate names are used to extract the aggregate bucket results, and the number of the final extracted aggregate bucket results may be one or more, for example, the 1 st aggregate bucket result of city 1, area 1 and street 1, the 2 nd aggregate bucket result of city 1, area 2 and street 2, the 3 rd aggregate bucket result of city 2, area 3 and street 3, the 4 th aggregate bucket result of city 2, area 3 and street 4, and so on may be included. In addition, if the last aggregation name is the index aggregation name "sum", one or more aggregation index results are extracted from all aggregation results, and if there are 4 aggregation bucket results corresponding to the above, the corresponding aggregation index results may also be 4 groups (or 4), for example, a sum result 1, a sum result 2, a sum result 3, and a sum result 4 may be extracted. For another example, if the aforementioned N aggregation names are 4, they are respectively: city 1, area 1, street, averaging; accordingly, the first three aggregate names are used to extract the aggregate bucket results, and the number of the final extracted aggregate bucket results may be one or more, for example, the 1 st aggregate bucket result of city 1, area 1 and street 11, and the 2 nd aggregate bucket result of city 1, area 1 and street 12 may be included. In addition, if the last aggregation name is the index aggregation name "averaging", one or more aggregation index results are extracted from all the aggregation results; corresponding to the above, if there are 2 aggregation bucket results, the corresponding aggregation indicator results may also be 2 groups (or 2), for example, the average calculation result 1 and the average calculation result 2 may be extracted.
In another example, M is greater than 1, that is, the nth aggregation name includes M aggregation index names, and the M aggregation index names may be in an array form, and other possible forms of the M aggregation index names are not limited herein.
The aforementioned extracting, based on the order of the M aggregation index names included in the nth aggregation name in the query request, M index calculation results from the aggregation result, and generating the aggregation index result based on the M index calculation results may specifically include: and sequentially extracting M index calculation results from the aggregation results based on the sequence of the M aggregation index names contained in the Nth aggregation name in the query request, and taking the M index calculation results obtained by extraction each time as an aggregation index result. That is, the above process of extracting M index calculation results based on M aggregation index names may be a traversal operation, that is, after the aggregation result is traversed, one or more aggregation index results may be obtained, and each aggregation index result may include M index calculation results. It should be understood that the index calculation result included in each of the aforementioned aggregation index results may be a numerical value in particular.
It should be noted that, in the case that the aggregation index names are 2 or more, 2 or more aggregation index names may be used as one aggregation index name group, and based on one aggregation index name group, one or more different index calculation results may be extracted from the aggregation result each time as one aggregation index result, and finally one or more aggregation index results may be obtained. The number of the polymerization indicator results and the number of the polymerization bucket results may be the same. For example, if the aforementioned N aggregation names are 4, they are respectively: city, area, street, (sum, average). Accordingly, the first three aggregate names are used to extract the aggregate bucket results, and the number of the final extracted aggregate bucket results may be one or more, for example, the 1 st aggregate bucket result of city 1, area 1 and street 1, the 2 nd aggregate bucket result of city 1, area 2 and street 2, the 3 rd aggregate bucket result of city 2, area 3 and street 3, the 4 th aggregate bucket result of city 2, area 3 and street 4, and so on may be included. In addition, if the last aggregation name is the index aggregation name "sum and average", the sum result and the average calculation result are sequentially extracted from all the aggregation results as one aggregation index result, and if there are 4 aggregation bucket results, the corresponding aggregation index results may 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) may be extracted.
Therefore, by adopting the above scheme, when the nth aggregation name includes one or more aggregation index names, the aggregation index results can be sequentially extracted from the aggregation results based on the order of the aggregation index names. Therefore, the sequence of the aggregation index results is consistent with the sequence of the aggregation index names, and the accuracy of the finally obtained target query result is further ensured.
In one embodiment, associating the N aggregation names with a result to be fed back to obtain a target query result, includes: correlating the result of the polymerization barrel and the result of the polymerization index contained in the result to be fed back to obtain a total polymerization result after correlation; and associating the N aggregation names with the total aggregation result to obtain a target query result.
Specifically, the number of aggregated bucket results is one or more; each of the one or more aggregation bucket results is a result extracted based on the aforementioned N-1 aggregation names. For example, N-1 aggregate names are "time 1-time 2", "city" and "street", respectively, and accordingly, based on these 3 aggregate names, one aggregate bucket result under street a1 in city a from time 1-time 2 can be obtained, and based on time 1-time 2, another aggregate bucket result under street B1 in city B can be obtained, and so on, so that a plurality of aggregate bucket results can be obtained. As described above, the number of the above-mentioned aggregate index results may be one or more, and each aggregate index result may include one or more index calculation results. It should also be understood that, the aforementioned nth aggregation name may include M aggregation index names, and no matter M is equal to or greater than 1, since the order of extracting the respective aggregation index results is consistent with the order of the M aggregation index names, when the M aggregation index names in the nth aggregation name are associated with the M aggregation index results, a one-to-one correspondence may also be ensured. And connecting the one or more polymerization bucket results with one or more polymerization index results to obtain a polymerization index result associated with each polymerization bucket result. For example, a polymerization bucket result is associated with a value 11 of index 1 and a value 21 of index 2; the other polymerization barrel result is associated with the value 12 of the index 1 and the value 22 of the index 2; the value of the index 1, the value of the index 2, and the like are associated with another bucket of aggregation results, and are not exhaustive here. That is, the total aggregation result includes each aggregation bucket result and its associated aggregation indicator result.
The associating the N aggregation names with the total aggregation result to obtain the target query result may refer to associating the first N-1 aggregation names of the N aggregation names with the aggregation bucket result in the total aggregation result, associating the nth aggregation name with the aggregation index result, and taking the associated result as the target query result.
It should be understood that the foregoing associated processing may be specifically realized by a join operation, which may refer to an operation of performing a cartesian product. Alternatively, the specific processes associated with the foregoing may be implemented in other ways, and not all possible implementations thereof are exhaustive.
Therefore, by adopting the scheme, the N aggregation names, the aggregation bucket results and the aggregation index results can be associated through connection operation, the target query result is ensured to contain name information corresponding to each result, and the actual meaning of the query result can be provided more directly and efficiently; and then, after the user side obtains the target query result, the follow-up related processing can be more efficiently and accurately carried out on each result contained in the target query result, and the overall processing efficiency is improved.
The scheme provided by the present embodiment is exemplarily described below with reference to fig. 2 and 3:
s201: and receiving a query request sent by user equipment.
As shown in fig. 3, the query request in fig. 3 is sent by the user equipment to the server.
S202: judging whether the query request contains N aggregation names or not, if the query request does not contain the N aggregation names, obtaining a second query result from the database based on query contents contained in the query request, returning the second query result to the user equipment, and ending the processing; otherwise, S203 is executed.
Specifically, after judging whether the query request contains N aggregation names, if it is determined that the query request does not contain N aggregation names, it may be determined that the current user does not specify to perform aggregation query, the query content is sent to the database to be retrieved, a second query result is obtained, and the second query result is returned to the user equipment; otherwise, S203 is executed. Wherein, the database can 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 foregoing embodiment, and will not be repeated.
Further, the obtaining a second query result from the matched object based on the query statement included in the query request may further include: acquiring a third query result from the matched object based on the query statement contained in the query request; judging whether the third query result contains original data or not; under the condition that the third query result contains the original data, acquiring the original data from the third query result, and taking the original data as a second query result; and in the case that the third query result does not contain the original data, directly taking the third query result as the second query result. Judging whether the third query result contains original data, specifically, judging whether the third query result contains a 'source' key; further, if the third query result includes a "_ source" key, it is determined that the third query result includes the original data.
S203: and acquiring a first query result from the database based on the query content and the N aggregation names contained in the query request.
As shown in fig. 3, the server obtains the first query result from the database based on the query content and the N aggregation names included in the query request.
S204: judging whether the first query result contains the aggregation result or not, and if not, ending the processing; if so, go to step S205.
It should be understood that, in the case of determining to end the processing, a prompt message indicating that the result of the query is empty may be returned to the user equipment, and further, 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 herein.
S205: judging whether the sequence of the N aggregation field names contained in the aggregation result is consistent with the sequence of the N aggregation names contained in the query request, if not, ending the processing; if yes, go to step S206.
Similarly, when the end of the processing is determined, a prompt message indicating that the query result is empty may be returned to the user equipment, and further, 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 herein.
S206: judging whether the current recursion depth is less than or equal to N-1, if so, executing S207; otherwise, S208 is performed.
S207: and sequentially extracting the current aggregation names based on the sequence of the first N-1 aggregation names in the query request, extracting the current bucket aggregation intermediate result from the last bucket aggregation intermediate result based on the current aggregation names, adding one to the current recursion depth, and returning to execute S206.
When the current recursion processing is the first recursion processing, the previous bucket aggregation intermediate result is obtained based on the aggregation result, which may specifically be: and directly taking the polymerization result as the middle result of the last barrel polymerization. In a case where the current recursion processing is not the first recursion processing, the previous bucket aggregation intermediate result is obtained based on the aggregation result, which may specifically refer to the previous bucket aggregation intermediate result obtained after performing multiple recursion processing based on the aggregation result.
S208: and under the condition that the current recursion depth is larger than N-1, taking the current bucket aggregation intermediate result as an aggregation bucket result, and extracting an aggregation index result from the aggregation result on the basis of the Nth aggregation name in the query request.
For example, in connection with FIG. 3, assume that N equals 4, i.e., there are 4 aggregation names in the query request; accordingly, N-1 equals 3. For example, the current recursion depth is an initial value 0, when performing the first recursion process, the 1 st aggregation name "time 1-time 2" is extracted from the 4 aggregation names, based on the 1 st aggregation name, all results including the "time 1-time 2" are obtained from the aggregation result as the 1 st bucket aggregation intermediate result, and then the current recursion depth is increased by one; the current recursion depth is 1 (less than N-1), executing second recursion processing, extracting a 2 nd aggregation name 'region' from 4 aggregation names, acquiring all results containing the 'region' from the 1 st bucket aggregation intermediate result as a 2 nd bucket aggregation intermediate result based on the 2 nd aggregation name, and then adding one to the current recursion depth; the current recursion depth is 2 (less than N-1), third recursion processing is executed, the 3 rd aggregation name is 'street', all results containing the 'street' are obtained from the 2 nd bucket aggregation intermediate result as a 3 rd bucket aggregation intermediate result based on the 3 rd aggregation name, and then the current recursion depth is increased by one; the current recursion depth is 3 (equal to N-1), and the 3 rd bucket aggregation intermediate result is determined as the aggregation bucket result, and now as shown in fig. 3, the aggregation bucket result may include 3 aggregation bucket results of bucket 1, bucket 2, and bucket 3. Then, based on the 4 th aggregation name in the query request (for example, summing and averaging), 3 aggregation index results are extracted from the aggregation results, where each aggregation index result includes a total value obtained by summing calculation and an average value obtained by averaging calculation.
It should be understood that the above is only an exemplary illustration, and N may be other values in the actual process, such as 5, 6 or more or less, but N is preferably greater than or equal to 2, which is not exhaustive.
S209: and taking the aggregation bucket result and the aggregation index result as a result to be fed back, associating the N aggregation names with the result to be fed back to obtain a target query result, and feeding back the target query result to the user equipment.
Referring to fig. 3, the aggregated bucket results (i.e., bucket 1, bucket 2, bucket 3) may be finally correlated to sum 1, average 1, sum 2, average 2, sum 3, and average 3, respectively; then, associating the 'time 1-time 2', 'region' and 'street' with the aggregated barrel result (namely barrel 1, barrel 2 and barrel 3), associating the 'summation' with the final 'sum 1, sum 2 and sum 3', and associating the 'averaging' with the 'average 1, average 2 and average 3' to obtain the final target query result; the target query result may then be fed back to the user device.
An embodiment of the present disclosure further provides an inquiry apparatus, as shown in fig. 4, including:
a query module 401, configured to obtain a first query result from a database based on a query request;
an extracting module 402, configured to, when the first query result includes the aggregated result, extract a result to be fed back from the aggregated result based on the N aggregation names in the query request; n is an integer greater than or equal to 1;
the connection module 403 is configured to associate the N aggregation names with the result to be fed back, so as to obtain a target query result.
In one embodiment, the extracting module 402 is configured to extract an aggregation bucket result and an aggregation index result from the aggregation results based on an order of the N aggregation names in the query request; and taking the result of the polymerization barrel and the result of the polymerization index as a result to be fed back.
In an embodiment, the extracting module 402 is configured to, in a case that a current recursion depth is less than or equal to N-1, sequentially extract a current aggregation name based on an order of first N-1 aggregation names in the query request, extract a current bucket aggregation intermediate result from a last bucket aggregation intermediate result based on the current aggregation name, and add one to the current recursion depth; wherein the last bucket polymerization intermediate result is obtained based on the polymerization result; and under the condition that the current recursion depth is larger than N-1, taking the current bucket aggregation intermediate result as an aggregation bucket result, and extracting an aggregation index result from the aggregation result on the basis of the Nth aggregation name in the query request.
In an embodiment, the extracting module 402 is configured to sequentially extract M aggregation indicator results from the aggregation results based on an order of M aggregation indicator names included in an nth aggregation name in the query request; m is an integer of 1 or more.
In an embodiment, the connection module 403 is configured to associate an aggregation bucket result and an aggregation index result included in the result to be fed back, so as to obtain an associated total aggregation result; and associating the N aggregation names with the total aggregation result to obtain a target query result.
By adopting the scheme, after the first query result is obtained from the database based on the query request, the result to be fed back is further extracted from the aggregation result of the first query result based on the aggregation name contained in the query result, and finally the target query result of the query is obtained after the aggregation name and the result to be fed back are associated. Therefore, the finally obtained target query result can more accurately contain each result obtained by the query and the associated aggregation name thereof, and the actual meaning of the query result can be provided more directly and efficiently; and then, after the user side obtains the target query result, the follow-up related processing can be more efficiently and accurately carried out on each result contained in the target query result, and the overall processing efficiency is improved.
In the technical scheme of the disclosure, the acquisition, storage, application and the like of the personal information of the related user all accord with the regulations of related laws and regulations, and do not violate the good customs of the public order.
The present disclosure also provides an electronic device, a readable storage medium, and a computer program product according to embodiments of the present disclosure.
FIG. 5 illustrates a schematic block diagram of an example electronic device 500 that can be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may 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 meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 5, 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 apparatus 500 can also be stored. The calculation unit 501, the ROM 502, and the RAM 503 are connected to each other by a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
A number of 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, or the like; an output unit 507 such as various types of displays, speakers, and the like; a storage unit 508, such as a magnetic disk, optical disk, or the like; and a communication unit 509 such as a network card, modem, 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.
The computing unit 501 may be a variety of general-purpose and/or special-purpose processing components having 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, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and so forth. The computing unit 501 performs the query method described above. For example, in some embodiments, the query methods described above may be implemented as a computer software program tangibly embodied in a machine-readable medium, such as storage unit 508. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 500 via the ROM 502 and/or the communication unit 509. When the computer program is loaded into the 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 above-described query method by any other suitable means (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for implementing the methods 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, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The 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, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here 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 a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, 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, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), and the Internet.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server may be a cloud server, a server of a distributed system, or a server with a combined blockchain.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present disclosure may be executed in parallel or sequentially or in different orders, and are not limited herein as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved.
The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.

Claims (13)

1. A method of querying, comprising:
acquiring a first query result from a database based on the query request;
under the condition that the first query result comprises the aggregation result, extracting a result to be fed back from the aggregation result based on N aggregation names in the query request; n is an integer greater than or equal to 1;
and associating the N aggregation names with the result to be fed back to obtain a target query result.
2. The method of claim 1, wherein the extracting the result to be fed back from the aggregated result based on the N aggregated names in the query request comprises:
extracting a polymerization bucket result and a polymerization index result from the polymerization result based on the sequence of the N polymerization names in the query request;
and taking the result of the polymerization barrel and the result of the polymerization index as the result to be fed back.
3. The method of claim 2, wherein the extracting from the aggregated results an aggregated bucket result and an aggregated index result based on the order of the N aggregated names in the query request comprises:
under the condition that the current recursion depth is smaller than or equal to N-1, sequentially extracting current aggregation names based on the sequence of the first N-1 aggregation names in the query request, extracting current bucket aggregation intermediate results from the previous bucket aggregation intermediate results based on the current aggregation names, and adding one to the current recursion depth; wherein the last bucket aggregation intermediate result is obtained based on the aggregation result;
and under the condition that the current recursion depth is larger than N-1, taking the current barrel aggregation intermediate result as the aggregation barrel result, and extracting the aggregation index result from the aggregation result on the basis of the Nth aggregation name in the query request.
4. The method of claim 3, wherein the extracting the aggregate indicator result from the aggregate result based on the Nth aggregate name in the query request comprises:
extracting M index calculation results from the aggregation results based on the sequence of M aggregation index names contained in the Nth aggregation name in the query request, and generating the aggregation index result based on the M index calculation results; m is an integer of 1 or more.
5. The method according to claim 2, wherein the associating the N aggregation names with the result to be fed back to obtain a target query result includes:
correlating the polymerization barrel result and the polymerization index result contained in the result to be fed back to obtain a correlated total polymerization result; and associating the N aggregation names with the total aggregation result to obtain the target query result.
6. An inquiry apparatus comprising:
the query module is used for acquiring a first query result from the database based on the query request;
the extracting module is used for extracting a result to be fed back from the aggregation result based on N aggregation names in the query request under the condition that the first query result contains the aggregation result; n is an integer greater than or equal to 1;
and the connection module is used for associating the N aggregation names with the result to be fed back to obtain a target query result.
7. The apparatus of claim 6, wherein the extracting module is configured to extract an aggregate bucket result and an aggregate index result from the aggregate results based on an order of the N aggregate names in the query request; and taking the result of the polymerization barrel and the result of the polymerization index as the result to be fed back.
8. The apparatus of claim 7, wherein the extracting module is configured to, in a case that a current recursion depth is less than or equal to N-1, sequentially extract a current aggregation name based on an order of first N-1 aggregation names in the query request, extract a current bucket aggregation intermediate result from a last bucket aggregation intermediate result based on the current aggregation name, and increase the current recursion depth by one; wherein the last bucket aggregation intermediate result is obtained based on the aggregation result; and under the condition that the current recursion depth is larger than N-1, taking the current barrel aggregation intermediate result as the aggregation barrel result, and extracting the aggregation index result from the aggregation result on the basis of the Nth aggregation name in the query request.
9. The apparatus according to claim 8, wherein the extracting module is configured to sequentially extract M aggregation indicator results from the aggregation results based on an order of M aggregation indicator names included in an nth aggregation name in the query request; m is an integer of 1 or more.
10. The device of claim 7, wherein the connection module is configured to associate the aggregation bucket result and the aggregation indicator result included in the result to be fed back, so as to obtain an associated total aggregation result; and associating the N aggregation names with the total aggregation result to obtain the target query result.
11. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-5.
12. A non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method of any one of claims 1-5.
13. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-5.
CN202210451281.7A 2022-04-26 2022-04-26 Query method, query device, electronic equipment and storage medium Pending CN114840724A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210451281.7A CN114840724A (en) 2022-04-26 2022-04-26 Query method, query device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210451281.7A CN114840724A (en) 2022-04-26 2022-04-26 Query method, query device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114840724A true CN114840724A (en) 2022-08-02

Family

ID=82568422

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210451281.7A Pending CN114840724A (en) 2022-04-26 2022-04-26 Query method, query device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114840724A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101500012A (en) * 2009-02-27 2009-08-05 中国人民解放军信息工程大学 Packet classification method and system
US20150288691A1 (en) * 2014-04-07 2015-10-08 International Business Machines Corporation Multi stage aggregation using digest order after a first stage of aggregation
EP3462339A1 (en) * 2017-09-28 2019-04-03 Siemens Aktiengesellschaft Method and message handler for processing a query
CN110781211A (en) * 2018-07-31 2020-02-11 网宿科技股份有限公司 Data analysis method and device
CN113190578A (en) * 2021-03-26 2021-07-30 有半岛(北京)信息科技有限公司 Multi-source data query system, method, device, equipment and storage medium
CN113468208A (en) * 2021-07-19 2021-10-01 网易(杭州)网络有限公司 Method and device for generating data query statement, server and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101500012A (en) * 2009-02-27 2009-08-05 中国人民解放军信息工程大学 Packet classification method and system
US20150288691A1 (en) * 2014-04-07 2015-10-08 International Business Machines Corporation Multi stage aggregation using digest order after a first stage of aggregation
EP3462339A1 (en) * 2017-09-28 2019-04-03 Siemens Aktiengesellschaft Method and message handler for processing a query
CN110781211A (en) * 2018-07-31 2020-02-11 网宿科技股份有限公司 Data analysis method and device
CN113190578A (en) * 2021-03-26 2021-07-30 有半岛(北京)信息科技有限公司 Multi-source data query system, method, device, equipment and storage medium
CN113468208A (en) * 2021-07-19 2021-10-01 网易(杭州)网络有限公司 Method and device for generating data query statement, server and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
韩贝: "SQLite数据库研究与应用", 信息科技, 15 February 2020 (2020-02-15) *

Similar Documents

Publication Publication Date Title
CN113836314B (en) Knowledge graph construction method, device, equipment and storage medium
CN112507098B (en) Question processing method, question processing device, electronic equipment, storage medium and program product
CN111611241A (en) Dictionary data operation method and device, readable storage medium and terminal equipment
CN114817651B (en) Data storage method, data query method, device and equipment
CN115222444A (en) Method, apparatus, device, medium and product for outputting model information
CN113904943B (en) Account detection method and device, electronic equipment and storage medium
CN114064925A (en) Knowledge graph construction method, data query method, device, equipment and medium
CN112989170A (en) Keyword matching method applied to information search, information search method and device
CN116955856A (en) Information display method, device, electronic equipment and storage medium
CN113761565A (en) Data desensitization method and apparatus
CN114840724A (en) Query method, query device, electronic equipment and storage medium
CN115563310A (en) Method, device, equipment and medium for determining key service node
CN114995719A (en) List rendering method, device, equipment and storage medium
CN113900731A (en) Request processing method, device, equipment and storage medium
CN114969444A (en) Data processing method and device, electronic equipment and storage medium
CN113961797A (en) Resource recommendation method and device, electronic equipment and readable storage medium
CN114329164A (en) Method, apparatus, device, medium and product for processing data
CN114115908A (en) Instruction set generation method, program analysis method, device and storage medium
CN112817990B (en) Data processing method, device, electronic equipment and readable storage medium
CN115458103B (en) Medical data processing method, medical data processing device, electronic equipment and readable storage medium
CN115511014B (en) Information matching method, device, equipment and storage medium
CN113239296B (en) Method, device, equipment and medium for displaying small program
CN115033823A (en) Method, apparatus, device, medium and product for processing data
CN116204559A (en) Data storage and data query method and device, electronic equipment and medium
CN115167855A (en) Front-end page generation method, device and equipment applied to matching transaction system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination