Method and device for generating Elasticsearch query builder and electronic equipment
Through the Elasticsearch query builder generation method, the custom indicator interface is used to construct query conditions and generate query DSL, which solves the high threshold and error-prone problems in the existing technology, achieves efficient and intuitive query construction and result visualization, and improves the user experience. and query accuracy.
Patent Information
- Application Number
- CN202411258931.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-10
- Publication Date
- 2024-10-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the existing technology, Elasticsearch query construction has a high technical threshold, is error-prone, and lacks an intuitive user interface. It is difficult to quickly build complex queries, and maintenance and debugging costs are high.
Provides an Elasticsearch query builder generation method, which uses custom indicator interfaces including query conditions panel, aggregation panel, sorting and paging panel, chart configuration panel, drag-and-drop and select operations to build query conditions, and convert them into JSON data to generate Elasticsearch queries. DSL, supporting visualization and export of results.
It lowers the technical threshold, improves query accuracy and user experience, supports complex query requirements, and provides result visualization and export functions to facilitate further analysis.
Smart Images

Figure CN118779338A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to an Elasticsearch query builder generation method, device and electronic device. Background Art
[0002] Elasticsearch query refers to the process of sending a request to the Elasticsearch search engine to retrieve the data stored in it. Elasticsearch is a distributed search and analysis engine based on Lucene, which can efficiently store, search and analyze large amounts of data. Elasticsearch query allows users to filter and obtain data by various conditions.
[0003] The main components of an Elasticsearch query include:
[0004] Index: Data in Elasticsearch is organized into indexes, similar to tables in relational databases. An index can contain multiple documents.
[0005] Document: Each item of data in the index is called a document, which is usually a string in JSON format.
[0006] Mapping: A mapping defines the fields in a document and their data types. It is a template that Elasticsearch uses to understand how to index and search data.
[0007] Query DSL (Domain Specific Language): Elasticsearch uses a domain-specific language to describe queries. Query DSL is a set of JSON objects that are used to precisely control search behavior.
[0008] The existing technology has the following problems when processing Elasticsearch queries:
[0009] 1. High technical threshold: Building complex Elasticsearch query statements usually requires certain professional knowledge and skills, and it is difficult for non-technical personnel to quickly get started. This limits the widespread application and popularity of Elasticsearch.
[0010] 2. Error-prone and difficult to maintain: Manually written query statements are prone to errors, especially when faced with complex query requirements, and the maintenance and debugging costs are high. Complex query statements may contain multiple nested Boolean logic and aggregation operations. Once an error occurs, it is very difficult to locate and fix the problem.
[0011] 3. Lack of intuitive user interface: Although some existing query building tools and plug-ins can help users generate Elasticsearch query statements, most of them lack intuitive graphical user interfaces, resulting in poor user experience and complex operations.
[0012] The above problems become technical problems that need to be solved. Summary of the invention
[0013] In view of this, an embodiment of the present invention provides an Elasticsearch query builder generation method, device and electronic device, which at least partially solve the problems existing in the prior art.
[0014] In a first aspect, an embodiment of the present invention provides a method for generating an Elasticsearch query builder, comprising:
[0015] Build a custom indicator interface for the Elasticsearch query builder, which includes a query condition panel, an aggregation panel, a sorting and paging panel, and a chart configuration panel. The query condition panel is used to add, delete, and modify query conditions by dragging and selecting. The aggregation panel is used to add aggregation conditions. The sorting and paging panel is used to set the sorting method and paging parameters of the query results. The chart configuration panel is used to select the chart type for result display and configure the display parameters of the chart.
[0016] Construct query conditions based on the query condition panel, aggregation panel, sorting and paging panel, and chart configuration panel, and assemble the query conditions into JSON data;
[0017] By traversing the query_conditions array, each query condition contained in the JSON data is parsed into a first internal representation BC, by traversing the aggregations array, the aggregation condition contained in the JSON data is parsed into a second internal representation BG, sorting and paging parameters are extracted from the JSON data and converted into a third internal representation BP, chart configuration parameters are extracted from the JSON data and converted into a fourth internal representation BT, and an internal representation set B={BC, BG, BP, BT} is formed through the first internal representation BC, the second internal representation BG, the third internal representation BP and the fourth internal representation BT;
[0018] Generate an Elasticsearch query DSL according to the internal representation set B, wherein the Elasticsearch query DSL includes project query, Boolean query, aggregation query, sorting and paging query;
[0019] Receive the query results corresponding to the Elasticsearch query DSL, visualize the results according to the chart type and parameters configured by the user in the custom indicator interface, and export the query results into a file in a preset format.
[0020] According to a specific implementation of an embodiment of the present disclosure, the step of constructing an Elasticsearch query builder custom indicator interface includes:
[0021] In the query condition panel, add query conditions by dragging and dropping;
[0022] On the aggregation panel, add aggregation conditions to implement statistics and grouping operations.
[0023] According to a specific implementation of the embodiment of the present disclosure, the construction of the Elasticsearch query builder custom indicator interface also includes:
[0024] On the Sorting and Paging panel, set the sorting field and direction, and configure the paging parameters;
[0025] On the Chart Configuration panel, select the chart type, customize the chart colors and label styles, and set the chart's X-axis and Y-axis configurations.
[0026] According to a specific implementation of the embodiment of the present disclosure, the query condition is constructed based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and the query condition is assembled into JSON data, including:
[0027] Collect all query conditions added by the user from the query condition panel, and convert each query condition into a query object in the Elasticsearch query language. If there are multiple query conditions and Boolean logic is used between the multiple query conditions, use the bool query object to integrate the multiple query conditions;
[0028] Collect all aggregation conditions added by the user from the aggregation panel. Each aggregation condition includes the aggregation type, aggregation field, and aggregation parameters. For each aggregation condition, create a corresponding aggregation object and integrate all aggregation conditions into an aggs object.
[0029] According to a specific implementation of the embodiment of the present disclosure, the query condition is constructed based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and the query condition is assembled into JSON data, which also includes:
[0030] Create a sort array to collect the sort fields and sort directions specified by the user to form sort parameters, create from and size fields, collect the paging parameters set by the user, and integrate the sort parameters and paging parameters into the query object;
[0031] Create an assembly diagram object to store the diagram configuration information. The assembly diagram object does not directly participate in the Elasticsearch query, but is used to display the results on the front end. The diagram configuration information is saved in the assembly diagram object for use when displaying the results.
[0032] According to a specific implementation of the embodiment of the present disclosure, the parsing of each query condition included in the JSON data into a first internal representation BC by traversing the query_conditions array includes:
[0033] Traverse each query condition in the query_conditions array, and for each query condition, analyze its query type;
[0034] For query conditions of the term type, directly construct an internal representation object containing the field name, operator, and value as the first internal representation BC;
[0035] For a composite query condition, the subquery condition is processed recursively, and the multiple sub-objects after the recursive processing are combined together to form a first internal representation BC;
[0036] For range query conditions, an internal representation object including the field name, range type and corresponding value is constructed as the first internal representation BC;
[0037] For full-text search conditions, an internal representation object including the field name, search type, and search text is constructed as the first internal representation BC;
[0038] For wildcard query conditions, an internal representation object including the field name and the wildcard expression is constructed as the first internal representation BC.
[0039] According to a specific implementation of the embodiment of the present disclosure, generating the Elasticsearch query DSL according to the internal representation set B includes:
[0040] Parse the query_conditions array and convert each query condition into the corresponding condition in Elasticsearch DSL;
[0041] Parse the aggregations array and convert each aggregation condition into an aggregation in Elasticsearch DSL;
[0042] Extract sort parameters and convert sort fields and order into the sort part in Elasticsearch DSL;
[0043] Apply a chart configuration to query results to generate a specific type of chart or view.
[0044] According to a specific implementation of an embodiment of the present disclosure, receiving the query result corresponding to the Elasticsearch query DSL, visualizing the result according to the chart type and parameters configured by the user in the custom indicator interface, and exporting the query result into a file in a preset format includes:
[0045] Receive query result data from the Elasticsearch client;
[0046] Generate corresponding charts according to the chart type and parameters configured by the user;
[0047] Set up an export button to export the query results to CSV or JSON format.
[0048] In a second aspect, an embodiment of the present invention provides an Elasticsearch query builder generation device, comprising:
[0049] A construction module is used to construct a custom indicator interface for the Elasticsearch query builder. The custom indicator interface includes a query condition panel, an aggregation panel, a sorting and paging panel, and a chart configuration panel. The query condition panel is used to add, delete, and modify query conditions by dragging and selecting operations. The aggregation panel is used to add aggregation conditions. The sorting and paging panel is used to set the sorting method and paging parameters of the query results. The chart configuration panel is used to select the chart type for result display and configure the display parameters of the chart.
[0050] An assembly module, which constructs query conditions based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and assembles the query conditions into JSON data;
[0051] The parsing module parses each query condition contained in the JSON data into a first internal representation BC by traversing the query_conditions array, parses the aggregation condition contained in the JSON data into a second internal representation BG by traversing the aggregations array, extracts sorting and paging parameters from the JSON data, and converts them into a third internal representation BP, extracts chart configuration parameters from the JSON data, and converts them into a fourth internal representation BT, and forms an internal representation set B={BC, BG, BP, BT} through the first internal representation BC, the second internal representation BG, the third internal representation BP and the fourth internal representation BT;
[0052] A generation module generates an Elasticsearch query DSL according to the internal representation set B, wherein the Elasticsearch query DSL includes project query, Boolean query, aggregation query, sorting and paging query;
[0053] The display module receives the query results corresponding to the Elasticsearch query DSL, visualizes the results according to the chart type and parameters configured by the user in the custom indicator interface, and exports the query results into a file in a preset format.
[0054] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:
[0055] at least one processor; and,
[0056] a memory communicatively connected to the at least one processor; wherein,
[0057] 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 execute the Elasticsearch query builder generation method in any of the aforementioned first aspects or any of the implementations of the first aspect.
[0058] In a fourth aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the Elasticsearch query builder generation method in the aforementioned first aspect or any implementation of the first aspect.
[0059] In the fifth aspect, an embodiment of the present invention further provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer executes the Elasticsearch query builder generation method in the aforementioned first aspect or any implementation of the first aspect.
[0060] The Elasticsearch query builder generation scheme in the embodiment of the present invention includes: building an Elasticsearch query builder custom indicator interface, the custom indicator interface includes a query condition panel, an aggregation panel, a sorting and paging panel, and a chart configuration panel, the query condition panel adds, deletes, and modifies query conditions by dragging and selecting operations, the aggregation panel is used to add aggregation conditions, the sorting and paging panel is used to set the sorting method and paging parameters of query results, and the chart configuration panel is used to select the chart type for result display and configure the display parameters of the chart; building query conditions based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and assembling the query conditions into JSON data; parsing each query condition contained in the JSON data into a first internal representation BC by traversing the query_conditions array, and traversing the ag gregations array, parse the aggregation condition contained in the JSON data into a second internal representation BG, extract the sorting and paging parameters from the JSON data, convert them into a third internal representation BP, extract the chart configuration parameters from the JSON data, convert them into a fourth internal representation BT, and form an internal representation set B={BC, BG, BP, BT} through the first internal representation BC, the second internal representation BG, the third internal representation BP and the fourth internal representation BT; generate an Elasticsearch query DSL according to the internal representation set B, and the Elasticsearch query DSL includes project query, Boolean query, aggregation query, sorting and paging query; receive the query result corresponding to the Elasticsearch query DSL, and visualize the result according to the chart type and parameters configured by the user in the custom indicator interface, and export the query result into a file in a preset format.
[0061] The solution of this application has the following beneficial effects:
[0062] Lower technical threshold: Through the graphical user interface, users can build complex queries without having to master the complex Elasticsearch query DSL syntax, which greatly reduces the usage threshold.
[0063] Improve query accuracy: Automatically parse and generate Elasticsearch query DSL, reducing errors in manually written query statements and improving query accuracy and reliability.
[0064] Enhanced user experience: The user experience is enhanced with a friendly graphical interface and intuitive operation. Users can easily build queries by dragging and selecting components.
[0065] Support complex query requirements: Support complex query requirements such as Boolean query, aggregation query, sorting and paging query to meet users' diverse data retrieval and analysis needs.
[0066] Result visualization and export: Supports result display in multiple chart types and provides export function to facilitate users to further analyze and process query results. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0068] Figure 1 A schematic diagram of a flow chart of a method for generating an Elasticsearch query builder provided by an embodiment of the present invention;
[0069] Figure 2 A schematic diagram of another Elasticsearch query builder generation method provided by an embodiment of the present invention;
[0070] Figure 3 A schematic diagram of the structure of an Elasticsearch query builder generating device provided by an embodiment of the present invention;
[0071] Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0072] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0073] The following describes the embodiments of the present disclosure through specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. The present disclosure can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present disclosure. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present disclosure.
[0074] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein may be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present disclosure, it should be understood by those skilled in the art that an aspect described herein may be implemented independently of any other aspect, and two or more of these aspects may be combined in various ways. For example, any number of aspects described herein may be used to implement the device and / or practice the method. In addition, other structures and / or functionalities other than one or more of the aspects described herein may be used to implement this device and / or practice this method.
[0075] It should also be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present disclosure. The drawings only show components related to the present disclosure rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0076] Additionally, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, it will be understood by those skilled in the art that the aspects described may be practiced without these specific details.
[0077] The embodiment of the present disclosure provides a method for generating an Elasticsearch query builder. The method for generating an Elasticsearch query builder provided in this embodiment can be executed by a computing device, which can be implemented as software, or as a combination of software and hardware, and which can be integrated in a server, a terminal device, etc.
[0078] See also Figure 1 and Figure 2 , the embodiment of the present disclosure provides a method for generating an Elasticsearch query builder, comprising:
[0079] S101, build a custom indicator interface for the Elasticsearch query builder, the custom indicator interface includes a query condition panel, an aggregation panel, a sorting and paging panel, and a chart configuration panel, the query condition panel is used to add, delete, and modify query conditions by dragging and selecting operations, the aggregation panel is used to add aggregation conditions, the sorting and paging panel is used to set the sorting method and paging parameters of the query results, and the chart configuration panel is used to select the chart type for result display and configure the display parameters of the chart.
[0080] The Elasticsearch query builder of the present invention mainly includes the following modules:
[0081] User interface module: Provides a graphical user interface (GUI) that allows users to intuitively build queries by dragging components, selecting options, etc.
[0082] Query parsing module: Parses the operations on the user interface into internal query representations.
[0083] Query generation module: converts the internal query representation into a query statement executable by Elasticsearch.
[0084] Result display module: displays query results and supports visualization and export of results.
[0085] The user interface module is a custom dashboard that contains the following subcomponents:
[0086] Query condition panel: Users can add, delete, and modify query conditions, such as matching fields, matching values, Boolean operations (AND, OR, NOT), etc., by dragging and selecting operations.
[0087] Aggregation panel: Users can add aggregation conditions, such as statistics, grouping, and other operations.
[0088] Sorting and Paging Panel: Users can set the sorting method and paging parameters of the query results.
[0089] Chart configuration panel: Users can select the chart type to display the results (such as bar chart, pie chart, line chart, etc.) and configure the display parameters of the chart.
[0090] S102, constructing query conditions based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and assembling the query conditions into JSON data.
[0091] The user constructs query conditions through the above components on the front-end interface. The front-end assembles these conditions into JSON format data and passes it to the server for processing. For example, the JSON data configured by the user is as follows:
[0092] { "query_conditions": [ { "field": "title", "value": "Elasticsearch","operator": "match"} ], "aggregations": [ { "field": "views", "operator": "sum"} ], "sort": { "field": "date", "order": "desc"}, "pagination": { "page": 1, "size": 10}, "chart": { "type": "bar", "x_field": "date", "y_field": "views"}}
[0093] S103, by traversing the query_conditions array, each query condition contained in the JSON data is parsed into a first internal representation BC, by traversing the aggregations array, the aggregation conditions contained in the JSON data are parsed into a second internal representation BG, sorting and paging parameters are extracted from the JSON data and converted into a third internal representation BP, chart configuration parameters are extracted from the JSON data and converted into a fourth internal representation BT, and an internal representation set B={BC, BG, BP, BT} is formed through the first internal representation BC, the second internal representation BG, the third internal representation BP and the fourth internal representation BT.
[0094] After receiving the JSON data passed by the front end, the query parsing module converts it into an internal representation, which includes fields, operators, values and other information:
[0095] 1. Parse query conditions: traverse the query_conditions array and parse each condition into an internal representation. Each condition contains a field, an operator, and a value. For example, parse { "field": "title", "value": "Elasticsearch", "operator": "match"} into an internal condition object.
[0096] 2. Parse the aggregation conditions: Traverse the aggregations array and parse each aggregation condition into an internal representation. Each aggregation condition contains fields and operators. For example, parse { "field": "views", "operator": "sum"} into an internal aggregation object.
[0097] 3. Parse sorting and paging parameters: Extract sorting and paging parameters from JSON data and convert them into internal representation. For example, parse { "field": "date", "order": "desc"} into a sorting object and parse { "page": 1, "size": 10} into a paging object.
[0098] 4. Parse chart configuration: Extract chart configuration parameters from JSON data and convert them into internal representation. For example, parse { "type": "bar", "x_field": "date", "y_field": "views"} into a chart configuration object.
[0099] S104, generating an Elasticsearch query DSL according to the internal representation set B, wherein the Elasticsearch query DSL includes project query, Boolean query, aggregation query, sorting and paging query.
[0100] The query generation module generates the Elasticsearch query DSL based on the internal representation generated by the query parsing module. This module supports various Elasticsearch query types, such as term query, match query, range query, bool query, etc.
[0101] 1. Generate basic query: Generate Elasticsearch query DSL based on internal condition objects. For example, for { "field": "title", "operator": "match", "value": "Elasticsearch"}, the following DSL is generated:
[0102] { "match": { "title": "Elasticsearch"}}
[0103] 2. Generate Boolean query: If there are multiple conditions, generate Boolean query DSL. For example, for two conditions, the internal representation generated is:
[0104] [ { "field": "title", "operator": "match", "value": "Elasticsearch"}, { "field": "author", "operator": "match", "value": "John"} ]
[0105] Generates the following DSL:
[0106] { "bool": { "must": [ { "match": { "title": "Elasticsearch"}}, { "match": { "author": "John"}} ]}}
[0107] 3. Generate aggregation query: Generate Elasticsearch aggregation DSL based on internal aggregation objects. For example, for { "field": "views", "operator": "sum"}, the following DSL is generated:
[0108] { "aggs": { "total_views": { "sum": { "field": "views"}}}}
[0109] 4. Generate sorting and paging queries: Generate DSL based on internal sorting and paging objects. For example, for the sorting object { "field": "date", "order": "desc"} and the paging object { "page": 1, "size": 10}, the following DSL is generated:
[0110] { "sort": [ { "date": { "order": "desc"}} ], "from": 0, "size": 10}
[0111] S105, receiving the query results corresponding to the Elasticsearch query DSL, and visualizing the results according to the chart type and parameters configured by the user in the custom indicator interface, and exporting the query results into a file in a preset format.
[0112] The result display module receives the query results and visualizes the results according to the chart type and parameters configured by the user on the front end. For example, the results can be displayed as a bar chart, pie chart, line chart, etc. The module also supports exporting query results to CSV or JSON format and generating charts for users to download.
[0113] 1. Receive query results: Receive query result data from Elasticsearch.
[0114] 2. Generate a chart based on the chart configuration: Generate a corresponding chart based on the chart type and parameters configured by the user. For example, for a bar chart configuration { "type": "bar", "x_field": "date", "y_field": "views"}, generate a corresponding bar chart display.
[0115] 3. Support result export: Provide export function, users can export query results into CSV or JSON format to facilitate subsequent data processing and analysis.
[0116] The solution of this application has the following beneficial effects:
[0117] Lower technical threshold: Through the graphical user interface, users can build complex queries without having to master the complex Elasticsearch query DSL syntax, which greatly reduces the usage threshold.
[0118] Improve query accuracy: Automatically parse and generate Elasticsearch query DSL, reducing errors in manually written query statements and improving query accuracy and reliability.
[0119] Enhanced user experience: The user experience is enhanced with a friendly graphical interface and intuitive operation. Users can easily build queries by dragging and selecting components.
[0120] Support complex query requirements: Support complex query requirements such as Boolean query, aggregation query, sorting and paging query to meet users' diverse data retrieval and analysis needs.
[0121] Result visualization and export: Supports result display in multiple chart types and provides export function to facilitate users to further analyze and process query results.
[0122] According to a specific implementation of an embodiment of the present disclosure, the step of constructing an Elasticsearch query builder custom indicator interface includes:
[0123] In the query condition panel, add query conditions by dragging and dropping;
[0124] On the aggregation panel, add aggregation conditions to implement statistics and grouping operations.
[0125] According to a specific implementation of the embodiment of the present disclosure, the construction of the Elasticsearch query builder custom indicator interface also includes:
[0126] On the Sorting and Paging panel, set the sorting field and direction, and configure the paging parameters;
[0127] On the Chart Configuration panel, select the chart type, customize the chart colors and label styles, and set the chart's X-axis and Y-axis configurations.
[0128] According to a specific implementation of the embodiment of the present disclosure, the query condition is constructed based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and the query condition is assembled into JSON data, including:
[0129] Collect all query conditions added by the user from the query condition panel, and convert each query condition into a query object in the Elasticsearch query language. If there are multiple query conditions and Boolean logic is used between the multiple query conditions, use the bool query object to integrate the multiple query conditions;
[0130] Collect all aggregation conditions added by the user from the aggregation panel. Each aggregation condition includes the aggregation type, aggregation field, and aggregation parameters. For each aggregation condition, create a corresponding aggregation object and integrate all aggregation conditions into an aggs object.
[0131] According to a specific implementation of the embodiment of the present disclosure, the query condition is constructed based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and the query condition is assembled into JSON data, which also includes:
[0132] Create a sort array to collect the sort fields and sort directions specified by the user to form sort parameters, create from and size fields, collect the paging parameters set by the user, and integrate the sort parameters and paging parameters into the query object;
[0133] Create an assembly diagram object to store the diagram configuration information. The assembly diagram object does not directly participate in the Elasticsearch query, but is used to display the results on the front end. The diagram configuration information is saved in the assembly diagram object for use when displaying the results.
[0134] According to a specific implementation of the embodiment of the present disclosure, the parsing of each query condition included in the JSON data into a first internal representation BC by traversing the query_conditions array includes:
[0135] Traverse each query condition in the query_conditions array, and for each query condition, analyze its query type;
[0136] For query conditions of the term type, directly construct an internal representation object containing the field name, operator, and value as the first internal representation BC;
[0137] For a composite query condition, the subquery condition is processed recursively, and the multiple sub-objects after the recursive processing are combined together to form a first internal representation BC;
[0138] For range query conditions, an internal representation object including the field name, range type and corresponding value is constructed as the first internal representation BC;
[0139] For full-text search conditions, an internal representation object including the field name, search type, and search text is constructed as the first internal representation BC;
[0140] For wildcard query conditions, an internal representation object including the field name and the wildcard expression is constructed as the first internal representation BC.
[0141] According to a specific implementation of the embodiment of the present disclosure, generating the Elasticsearch query DSL according to the internal representation set B includes:
[0142] Parse the query_conditions array and convert each query condition into the corresponding condition in Elasticsearch DSL;
[0143] Parse the aggregations array and convert each aggregation condition into an aggregation in Elasticsearch DSL;
[0144] Extract sort parameters and convert sort fields and order into the sort part in Elasticsearch DSL;
[0145] Apply a chart configuration to query results to generate a specific type of chart or view.
[0146] According to a specific implementation of an embodiment of the present disclosure, receiving the query result corresponding to the Elasticsearch query DSL, visualizing the result according to the chart type and parameters configured by the user in the custom indicator interface, and exporting the query result into a file in a preset format includes:
[0147] Receive query result data from the Elasticsearch client;
[0148] Generate corresponding charts according to the chart type and parameters configured by the user;
[0149] Set up an export button to export the query results to CSV or JSON format.
[0150] Corresponding to the above method embodiment, see Figure 3 The embodiment of the present invention further discloses an Elasticsearch query builder generating device 30, comprising:
[0151] Building module 301, building a custom indicator interface for the Elasticsearch query builder, the custom indicator interface includes a query condition panel, an aggregation panel, a sorting and paging panel, and a chart configuration panel, the query condition panel is used to add, delete, and modify query conditions by dragging and selecting operations, the aggregation panel is used to add aggregation conditions, the sorting and paging panel is used to set the sorting method and paging parameters of the query results, and the chart configuration panel is used to select the chart type for result display and configure the display parameters of the chart;
[0152] An assembly module 302 constructs query conditions based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and assembles the query conditions into JSON data;
[0153] The parsing module 303 parses each query condition included in the JSON data into a first internal representation BC by traversing the query_conditions array, parses the aggregation condition included in the JSON data into a second internal representation BG by traversing the aggregations array, extracts sorting and paging parameters from the JSON data and converts them into a third internal representation BP, extracts chart configuration parameters from the JSON data and converts them into a fourth internal representation BT, and forms an internal representation set B={BC, BG, BP, BT} through the first internal representation BC, the second internal representation BG, the third internal representation BP and the fourth internal representation BT;
[0154] A generation module 304 generates an Elasticsearch query DSL according to the internal representation set B, wherein the Elasticsearch query DSL includes item query, Boolean query, aggregation query, sorting and paging query;
[0155] The display module 305 receives the query results corresponding to the Elasticsearch query DSL, visualizes the results according to the chart type and parameters configured by the user in the custom indicator interface, and exports the query results into a file in a preset format.
[0156] See also Figure 4 The embodiment of the present invention further provides an electronic device 60, the electronic device comprising:
[0157] at least one processor; and,
[0158] a memory communicatively connected to the at least one processor; wherein,
[0159] 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 execute the Elasticsearch query builder generation method in the aforementioned method embodiment.
[0160] An embodiment of the present invention further provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the aforementioned method embodiment.
[0161] An embodiment of the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer executes the Elasticsearch query builder generation method in the aforementioned method embodiment.
[0162] Reference below Figure 4 , which shows a schematic diagram of the structure of an electronic device 60 suitable for implementing the embodiment of the present disclosure. The electronic device in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0163] like Figure 4 As shown, the electronic device 60 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 60 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0164] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, a gage, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 60 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 4 The electronic device 60 is shown with various devices, but it should be understood that it is not required to implement or have all the devices shown. More or fewer devices may be implemented or have instead.
[0165] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0166] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A method for generating an Elasticsearch query builder, characterized in that: include: Build a custom indicator interface for the Elasticsearch query builder, which includes a query condition panel, an aggregation panel, a sorting and paging panel, and a chart configuration panel. The query condition panel is used to add, delete, and modify query conditions by dragging and selecting. The aggregation panel is used to add aggregation conditions. The sorting and paging panel is used to set the sorting method and paging parameters of the query results. The chart configuration panel is used to select the chart type for result display and configure the display parameters of the chart. Construct query conditions based on the query condition panel, aggregation panel, sorting and paging panel, and chart configuration panel, and assemble the query conditions into JSON data; By traversing the query_conditions array, each query condition contained in the JSON data is parsed into a first internal representation BC, by traversing the aggregations array, the aggregation condition contained in the JSON data is parsed into a second internal representation BG, sorting and paging parameters are extracted from the JSON data and converted into a third internal representation BP, chart configuration parameters are extracted from the JSON data and converted into a fourth internal representation BT, and an internal representation set B={BC, BG, BP, BT} is formed through the first internal representation BC, the second internal representation BG, the third internal representation BP and the fourth internal representation BT; Generate an Elasticsearch query DSL according to the internal representation set B, wherein the Elasticsearch query DSL includes project query, Boolean query, aggregation query, sorting and paging query; Receive the query results corresponding to the Elasticsearch query DSL, visualize the results according to the chart type and parameters configured by the user in the custom indicator interface, and export the query results into a file in a preset format.
2. The method according to claim 1, characterized in that The construction of the Elasticsearch query builder custom indicator interface includes: In the query condition panel, add query conditions by dragging and dropping; On the aggregation panel, add aggregation conditions to implement statistics and grouping operations.
3. The method according to claim 2, characterized in that The construction of the Elasticsearch query builder custom indicator interface also includes: On the Sorting and Paging panel, set the sorting field and direction, and configure the paging parameters; On the Chart Configuration panel, select the chart type, customize the chart colors and label styles, and set the chart's X-axis and Y-axis configurations.
4. The method according to claim 3, characterized in that The query conditions are constructed based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and the query conditions are assembled into JSON data, including: Collect all query conditions added by the user from the query condition panel, and convert each query condition into a query object in the Elasticsearch query language. If there are multiple query conditions and Boolean logic is used between the multiple query conditions, use the bool query object to integrate the multiple query conditions; Collect all aggregation conditions added by the user from the aggregation panel. Each aggregation condition includes the aggregation type, aggregation field, and aggregation parameters. For each aggregation condition, create a corresponding aggregation object and integrate all aggregation conditions into an aggs object.
5. The method according to claim 4, characterized in that The step of constructing query conditions based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and assembling the query conditions into JSON data, further includes: Create a sort array to collect the sort fields and sort directions specified by the user to form sort parameters, create from and size fields, collect the paging parameters set by the user, and integrate the sort parameters and paging parameters into the query object; Create an assembly diagram object to store the diagram configuration information. The assembly diagram object does not directly participate in the Elasticsearch query, but is used to display the results on the front end. The diagram configuration information is saved in the assembly diagram object for use when displaying the results.
6. The method according to claim 5, characterized in that By traversing the query_conditions array, each query condition contained in the JSON data is parsed into a first internal representation BC, including: Traverse each query condition in the query_conditions array, and for each query condition, analyze its query type; For query conditions of the term type, directly construct an internal representation object containing the field name, operator, and value as the first internal representation BC; For a composite query condition, the subquery condition is processed recursively, and the multiple sub-objects after the recursive processing are combined together to form a first internal representation BC; For range query conditions, an internal representation object including the field name, range type and corresponding value is constructed as the first internal representation BC; For full-text search conditions, an internal representation object including the field name, search type, and search text is constructed as the first internal representation BC; For wildcard query conditions, an internal representation object including the field name and the wildcard expression is constructed as the first internal representation BC.
7. The method according to claim 6, characterized in that The generating of the Elasticsearch query DSL according to the internal representation set B includes: Parse the query_conditions array and convert each query condition into the corresponding condition in Elasticsearch DSL; Parse the aggregations array and convert each aggregation condition into an aggregation in Elasticsearch DSL; Extract sort parameters and convert sort fields and order into the sort part in Elasticsearch DSL; Apply a chart configuration to query results to generate a specific type of chart or view.
8. The method according to claim 7, characterized in that The receiving of the query result corresponding to the Elasticsearch query DSL, visualizing the result according to the chart type and parameters configured by the user in the custom indicator interface, and exporting the query result into a file in a preset format include: Receive query result data from the Elasticsearch client; Generate corresponding charts according to the chart type and parameters configured by the user; Set up an export button to export the query results to CSV or JSON format.
9. An Elasticsearch query builder generating device, characterized in that: include: A construction module is used to construct a custom indicator interface for the Elasticsearch query builder. The custom indicator interface includes a query condition panel, an aggregation panel, a sorting and paging panel, and a chart configuration panel. The query condition panel is used to add, delete, and modify query conditions by dragging and selecting operations. The aggregation panel is used to add aggregation conditions. The sorting and paging panel is used to set the sorting method and paging parameters of the query results. The chart configuration panel is used to select the chart type for result display and configure the display parameters of the chart. An assembly module, which constructs query conditions based on the query condition panel, the aggregation panel, the sorting and paging panel, and the chart configuration panel, and assembles the query conditions into JSON data; The parsing module parses each query condition contained in the JSON data into a first internal representation BC by traversing the query_conditions array, parses the aggregation condition contained in the JSON data into a second internal representation BG by traversing the aggregations array, extracts sorting and paging parameters from the JSON data, and converts them into a third internal representation BP, extracts chart configuration parameters from the JSON data, and converts them into a fourth internal representation BT, and forms an internal representation set B={BC, BG, BP, BT} through the first internal representation BC, the second internal representation BG, the third internal representation BP and the fourth internal representation BT; A generation module generates an Elasticsearch query DSL according to the internal representation set B, wherein the Elasticsearch query DSL includes project query, Boolean query, aggregation query, sorting and paging query; The display module receives the query results corresponding to the Elasticsearch query DSL, visualizes the results according to the chart type and parameters configured by the user in the custom indicator interface, and exports the query results into a file in a preset format.
10. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, 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 execute the Elasticsearch query builder generation method described in any one of claims 1 to 8.
Citation Information
Patent Citations
Method and device for realizing complex query of mass data based on Elasticsearch and medium
CN110543517A
DSL-based view processing method, system and equipment and storage medium
CN115827670A
Online self-defined report query and export method and system
CN116340398A
Data query management method and device, equipment and storage medium
CN117033387A
Generating SQL queries from declarative queries for semi-structured data
US20200012644A1
Cited By
Switch port flow anomaly analysis method, device and equipment and storage medium
CN120896716A
