A dynamic combination query method based on ES search engine

CN111797111BActive Publication Date: 2024-09-20BEIJING CSSCA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010416164.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-05-17
Publication Date
2024-09-20
Estimated Expiration
2040-05-17

AI Technical Summary

Technical Problem

但是这种拼接的查询模板并不能很好的满足用户想要自定义组装查询条件的场景,比如说我们期望在原有的查询条件上增加几个条件做到拼接进行查询,或者查询需求很多时,这就导致一个需求就要写一个ES的java api查询方法

Benefits of technology

[0033] The present invention satisfies the scenario of user-defined multi-condition query information by dynamically splicing and assembling ES query statements at the front end and backend. In addition, using ES service query solves the problem of slow big data retrieval efficiency, and ES can store information in near real-time. , Retrieve data; it has good scalability and can be extended to hundreds of servers to process PB-level data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111797111B
    Figure CN111797111B
Patent Text Reader

Abstract

The present invention discloses a dynamic combined query method based on an ES search engine. The method includes configuring basic information of an ES cluster on a server, creating a client for accessing the server, and writing a js program on the server front end to implement the value taking of the query condition information customized by the client and splicing it into a specified expression query statement. The server back end specifies the expression query statement to parse and assemble the query query statement of ES, and uses bool to implement the combined query, and then accesses ES for data interaction. The present invention satisfies the scenario of user-defined multi-condition query information by dynamically splicing and assembling ES query statements on the front end and the back end. In addition, the use of ES service query solves the problem of slow big data retrieval efficiency, and ES can store and retrieve data in near real time; it has good scalability and can be expanded to hundreds of servers to process PB-level data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer technology, and in particular relates to a dynamic combination query method based on an ES search engine. Background Art

[0002] Elasticsearch (ES) is a highly scalable, highly available, open source search and analysis engine based on Apache Lucene. It allows you to easily dig deep into your data, and you can zoom in and out on the search and analysis range at any time, all in real time. ES provides traditional queries ('find all items X that meet condition Y') for filtering, highlights search fragments, and provides context for each result. It can also provide users with search keyword suggestions, and provides powerful aggregation (i.e. facet in ES) capabilities.

[0003] ES can provide users with fixed query templates. Users can only perform specific queries through existing multi-condition query templates. In daily development, we may need to frequently use some similar queries. In order to reduce repetitive work, we can write these similar queries into templates. In the future, we only need to pass different parameters to call the template to obtain results. In ES, the use of combined condition queries is a powerful feature of its search engine to retrieve data. ES's query syntax provides basic add, delete, modify and query functions. Its combined condition syntax is called bool. By splicing ES-specific syntax in bool, complex condition splicing queries can be performed in most scenarios, also called compound queries. However, this spliced ​​query template cannot well meet the scenarios where users want to customize the assembled query conditions. For example, we expect to add several conditions to the original query conditions to perform splicing queries, or when there are many query requirements, this will lead to writing an ES java api query method for one requirement. Therefore, it is necessary to make improvements. Summary of the invention

[0004] The technical problem solved by the present invention is to provide a dynamic combination query method based on ES search engine.

[0005] Technical solution: In order to solve the above technical problems, the technical solution adopted by the present invention is as follows:

[0006] A dynamic combination query method based on ES search engine, comprising the following steps:

[0007] Step 1: Configure basic information of the ES cluster on the server;

[0008] Step 2: Create a client for accessing the server, where the client is used to add custom query condition information;

[0009] Step 3: Write a js program on the server front end to obtain the values ​​of the query condition information added by the client and splice it into a specified expression query statement;

[0010] Step 4: The server backend receives and parses the specified expression query statement sent by the frontend, assembles the ES query statement according to the expression, and uses bool to implement the combined query;

[0011] Step 5: Access the ES service through the assembled ES query statement to interact with data.

[0012] Furthermore, the specified expression format is: field>value&(field=value|field<=value), where | is equivalent to or, and & is equivalent to and.

[0013] Furthermore, the server front end takes values ​​of the custom added query condition information and splices it into a specified expression query statement, including the following steps:

[0014] Step 3.1: Loop through the child node labels of the parent label, obtain the value of each child node label and save it in the array in the form of an object. The object attributes should be field, condition, value, and child node object;

[0015] Step 3.2: Process the hierarchical relationship in the array and flatten the hierarchical relationship of the objects in the array through (): traverse the array to determine whether there is a child node object in the object. If so, there is a next level, use () to indicate the relationship, and continue to loop until the end.

[0016] Furthermore, the step 4 specifically includes:

[0017] Step 4.1: The server backend receives the incoming specified expression query statement;

[0018] Step 4.2: When the specified expression query statement encounters (, start splitting to split the specified expression query statement into objects;

[0019] Step 4.3: Store the query conditions in the object's attributes, and store the fields, conditions, and values ​​in the attributes;

[0020] Step 4.4: Construct the query interface by identifying the object attribute conditions that match the ES Java API's QueryBuilders and by identifying & and | that match the ES's bool conditions.

[0021] Furthermore, the object attribute conditions include >, <, =, >= and <=.

[0022] Furthermore, the step 1 specifically includes:

[0023] Step 1.1: Deploy JDK and configure environment variables;

[0024] Step 1.2: Install ES and configure the elasticsearch.yml file content;

[0025] Step 1.3: Perform jvm tuning;

[0026] Step 1.4: Deploy the HEAD plug-in, modify the ES configuration file, allow head to access ES across domain names, and restart ES;

[0027] Step 1.5: Start the head plug-in service and access the head plug-in.

[0028] Furthermore, the step 2 specifically includes:

[0029] Step 2.1: Create a new Maven project, modify the pom file, and add ES dependencies;

[0030] Step 2.2: Add local and ES configuration file information;

[0031] Step 2.3: Write a Java program to access ES.

[0032] Beneficial effects: Compared with the prior art, the present invention has the following advantages:

[0033] The present invention satisfies the scenario of user-defined multi-condition query information by dynamically splicing and assembling ES query statements through the front-end and back-end. In addition, the use of ES service query solves the problem of slow big data retrieval efficiency, and ES can store and retrieve data in near real time; it has good scalability and can be expanded to hundreds of servers and process PB-level data. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 This is a flow chart of the dynamic combination query method based on the ES search engine;

[0035] Figure 2 This is a flowchart of the method for configuring basic information of the ES cluster;

[0036] Figure 3 is a flow chart of a method for creating a client to access a server;

[0037] Figure 4 It is a method flow chart for taking values ​​of custom added query condition information and splicing them into a specified expression query statement;

[0038] Figure 5 It is a flowchart of the method of specifying expression query statement parsing and assembling ES query statement;

[0039] Figure 6 This is a schematic diagram of the access interface after the ES cluster has been configured with basic information;

[0040] Figure 7 This is a schematic diagram of the display interface of the client after creation. DETAILED DESCRIPTION

[0041] The present invention is further illustrated below in conjunction with specific examples. The examples are implemented based on the technical solutions of the present invention. It should be understood that these examples are only used to illustrate the present invention and are not used to limit the scope of the present invention.

[0042] like Figures 1 to 7 As shown, the embodiment of the present invention provides a dynamic combination query method based on the ES search engine, comprising the following steps:

[0043] Step 1: Configure basic information of the ES cluster on the server. The specific configuration method is the same as the existing one, such as Figure 2 As shown, the details are as follows:

[0044] Step 1.1: Deploy JDK (Java Development Kit) and configure environment variables.

[0045] Step 1.2: Install ES and configure the elasticsearch.yml file content.

[0046] Step 1.3: Perform JVM (Java Virtual Machine) tuning. Generally, it is best to set it to half of the physical memory. You can choose to adjust it according to the server memory.

[0047] Step 1.4: Deploy the head plug-in, modify the ES configuration file, allow head to access ES across domain names, and restart ES.

[0048] Step 1.5: Start the head plug-in service and access the head plug-in.

[0049] After the configuration is complete, access the head plugin interface as follows Figure 6 shown.

[0050] Step 2: Create a client to access the server. The client is used to customize the query condition information. The specific method of creating the client is the same as that of other existing clients, such as Figure 3 As shown, the details are as follows:

[0051] Step 2.1: Create a new Maven project, modify the pom file, and add ES dependencies.

[0052] Step 2.2: Add local and ES configuration file information.

[0053] Step 2.3: Write a Java program to access ES.

[0054] The interface of the created client is as follows Figure 7 shown.

[0055] Step 3: Write a js (JavaScript) program on the server front end to obtain the query condition information added by the client and splice it into a specified expression query statement. Each time the query condition is different, enter different query conditions directly on the client, encapsulate and save them by adding new conditions. The server front end converts the query condition into a specified expression query statement, where the specified expression query statement is a query statement that can connect to the front and back ends of the server and can be recognized by both the front and back ends. The specified expression query statement is a statement description of the String type, and the format of the specified expression query statement is: field>value& (field=value|field<=value), where | is equivalent to or and & is equivalent to and.

[0056] like Figure 4 As shown, similarly, taking the specified expression query statement as a String type statement as an example, the server front end takes the value of the custom added query condition information and splices it into the specified expression query statement, including the following steps:

[0057] Step 3.1: Loop through the child node labels of the parent label, obtain the value of each child node label and save it in the array in the form of an object. The object attributes should be field, condition, value, and child node object;

[0058] Step 3.2: Process the hierarchical relationship in the array and flatten the hierarchical relationship of the objects in the array through (): traverse the array to determine whether there is a child node object in the object. If so, there is a next level, use () to indicate the relationship, and continue to loop until the end.

[0059] Step 4: The server backend receives and parses the specified expression statement sent by the frontend, assembles the ES query statement based on the expression, and uses bool to implement the combined query. The main function of this step is to convert the specified expression statement into a query statement that ES can recognize, such as Figure 5 As shown, the specific steps include:

[0060] Step 4.1: The server backend receives the incoming specified expression query statement data;

[0061] Step 4.2: When the specified expression query statement encounters (, start splitting to split the specified expression query statement into objects;

[0062] Step 4.3: Store the query conditions in the object's attributes, and store the fields, conditions, and values ​​in the attributes;

[0063] Step 4.4: Construct the query interface by identifying object attribute conditions that match ES's Java API QueryBuilders (QueryBuilders.rangeQuery(field).gt(value) matches >, etc.), and by identifying & and | that match ES's bool conditions (bool.must(sql), bool.should(sql), etc.). Object attribute conditions include > (greater than), < (less than), = (equal to), >= (greater than or equal to), and <= (less than or equal to).

[0064] Step 5: Access the ES service through the assembled ES query statement to interact with data. ES can feedback the corresponding query results by receiving the query statement.

[0065] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A dynamic combination query method based on ES search engine, It is characterized in that The following steps are involved: Step 1: Configure basic information of the ES cluster on the server; Step 2: Create a client for accessing the server, where the client is used to add custom query condition information; Step 3: Write a js program on the server front end to obtain the values ​​of the query condition information added by the client and splice it into a specified expression query statement; Step 4: The server backend receives and parses the specified expression query statement sent by the frontend, assembles the ES query statement according to the expression, and uses bool to implement the combined query; Step 5: Access ES services through the assembled ES query statements to interact with data; The specified expression format is: field>value&(field=value|field<=value), where | is equivalent to or, and & is equivalent to and; The server front end obtains the values ​​of the custom added query condition information and splices it into a specified expression query statement, including the following steps: Step 3.1: Loop through the child node labels of the parent label, obtain the value of each child node label and save it in the array in the form of an object. The object attributes should be field, condition, value, and child node object; Step 3.2: Process the hierarchical relationship in the array and flatten the hierarchical relationship of the objects in the array through (): traverse the array to determine whether there is a child node object in the object. If so, there is a next level, use () to indicate the relationship, and continue to loop until the end; The step 4 specifically includes: Step 4.1: The server backend receives the incoming specified expression query statement; Step 4.2: When the specified expression query statement encounters (, start splitting to split the specified expression query statement into objects; Step 4.3: Store the query conditions in the object's attributes, and store the fields, conditions, and values ​​in the attributes; Step 4.4: Construct the query interface by identifying the object attribute conditions that match the ES Java API's QueryBuilders and by identifying & and | that match the ES's bool conditions.

2. The dynamic combination query method based on ES search engine according to claim 1, It is characterized in that The object attribute conditions include >, <, =, >= and <=.

3. The dynamic combination query method based on ES search engine according to claim 1, It is characterized in that The step 1 specifically includes: Step 1.1: Deploy JDK and configure environment variables; Step 1.2: Install ES and configure the elasticsearch.yml file content; Step 1.3: Perform jvm tuning; Step 1.4: Deploy the head plug-in, modify the ES configuration file, allow head to access ES across domain names, and restart ES; Step 1.5: Start the head plug-in service and access the head plug-in.

4. The dynamic combination query method based on ES search engine according to claim 1, It is characterized in that The step 2 specifically includes: Step 2.1: Create a new Maven project, modify the pom file, and add ES dependencies; Step 2.2: Add local and ES configuration file information; Step 2.3: Write a Java program to access ES.