A method and system for converting expression retrieval into Elasticsearch search statement

By designing expressions and conversion algorithms, expression search is converted into Elasticsearch search statements, which solves the problem of low complex search and parsing capabilities in the existing technology, and realizes efficient complex search and flexible search strategies.

CN114691825BActive Publication Date: 2025-02-14DATAGRAND TECH INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210211874.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-04
Publication Date
2025-02-14
Estimated Expiration
2042-03-04

AI Technical Summary

Technical Problem

The prior art cannot perform complex expression retrieval and parsing capabilities, making it difficult to support complex retrieval strategies.

Method used

By designing expressions and conversion algorithms, expression searches are converted into search statements recognized by Elasticsearch, including converting search expressions to suffix expressions and operating suffix expressions to generate Elasticsearch search statements.

Benefits of technology

It improves the expression parsing ability of the search system, supports complex expression retrieval, cooperates with the formulation and success of search strategies, and improves the flexibility and efficiency of search.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114691825B_ABST
    Figure CN114691825B_ABST
Patent Text Reader

Abstract

The present invention relates to a method for converting expression retrieval into Elasticsearch search statements, wherein the retrieval expression used in the expression retrieval consists of a search term and a logical operator, the retrieval expression is submitted to a retrieval system, the retrieval system parses the retrieval expression into a retrieval command that can be recognized and executed by the search engine, and then submits it to the open source search engine Elasticsearch to obtain the desired retrieval results, the method specifically includes two links: designing an expression and designing a conversion algorithm, in the designing expression link, the fields used are listed, and the priorities of simple retrieval expression symbols, retrieval expression combiners and retrieval expression symbols are defined respectively; in the designing conversion algorithm link, the retrieval expression is converted into a suffix expression operation and the retrieval expression suffix expression is calculated to obtain the converted Elasticsearch search statement. The method of the present invention improves the expression parsing capability of the retrieval system, can support expressions of varying complexity, and cooperates with the formulation and success of retrieval strategies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of search engines, and in particular to a method and system for converting expression retrieval into Elasticsearch search statements. Background Art

[0002] The explosive growth of data has put forward more requirements for search. Among the many requirements, fast search response and accurate results are the most basic and most concerned requirements. In terms of speed, there are many underlying search engines that provide good solutions. Among them, the open source Solr and Elasticsearch have made important contributions to the search field. In most cases, after the requirement of speed is handed over to the open source engine, another focus is how to better use the search engine to obtain more accurate results. On the one hand, combined with machine learning methods, better understand the user's search keywords, learn the correlation between keywords, user habits and documents to be searched; on the other hand, complex Boolean search and expression search are used in special industry text retrieval (research report retrieval, etc.) to make up for the long text retrieval that cannot be fully understood by current machine learning.

[0003] Expression search generally consists of search terms and various logical operators. It uses operators to combine various search expressions specified by the search system to form complex expressions similar to data formulas. Submit it to the search system, which parses the expression into a search command that the search engine can recognize and execute, and then submits it to the search engine to obtain the desired search results. The expression parsing ability and method of the search system determines the complexity of the expressions that can be supported, which directly affects the success or failure of the search strategy. Summary of the invention

[0004] The purpose of the present invention is to overcome the shortcomings of the prior art that it is unable to perform complex retrieval and has low parsing capabilities, and to provide a method for converting expression retrieval into Elasticsearch search statements. The method of the present invention improves the expression parsing capability of the retrieval system, can support complex expressions, and cooperate with the formulation and success of retrieval strategies.

[0005] In order to achieve the above-mentioned object of the invention, the technical solution provided by the present invention is as follows:

[0006] A method for converting expression retrieval into Elasticsearch search statements, characterized in that the retrieval expression used in the expression retrieval consists of a retrieval term and a logical operator, the retrieval expression is submitted to a retrieval system, the retrieval system parses the retrieval expression into a retrieval command that can be recognized and executed by the search engine, and then submits it to the open source search engine Elasticsearch to obtain the desired retrieval results. The method specifically includes two steps: designing an expression and designing a conversion algorithm. In the designing expression step, the fields used are listed, and the priorities of simple retrieval expression symbols, retrieval expression combiners, and retrieval expression symbols are respectively defined;

[0007] The design of the conversion algorithm includes:

[0008] The first step is to convert the search expression into a suffix expression, which includes:

[0009] S11. Start the operation, view the expression, and convert the expression into a list of expression elements;

[0010] S12. Take the next element;

[0011] S13 determines whether it is a simple search expression, if so, add the suffix expression and execute step s17, if not, execute step S14;

[0012] S14 determines whether it is a search formula combination symbol, if not, an error message is output, if so, step S15 is executed;

[0013] S15. Distinguish the characters to see whether it is a left bracket, a right bracket, or other combining characters;

[0014] S16. If it is a right bracket, a detection element is popped out from the symbol stack, and it is determined whether the detection element is a right bracket. If so, the right bracket is discarded and step S17 is executed; if it is a left bracket, it is pushed into the symbol stack and step S17 is executed; if it is other combiners, it is determined whether the symbol stack is empty. If it is empty, other combiners are pushed into the symbol stack and step S17 is executed. If it is not empty, it is determined whether the priority of the current symbol is higher than the top symbol of the stack. If it is not, it is pushed into the symbol stack and step S17 is executed. If it is yes, the top symbol is popped out and added to the suffix expression, and the cycle is repeated again to determine whether the priority of the current symbol is higher than the top symbol of the stack, until all are pushed into the symbol stack and step S17 is executed;

[0015] S17. Determine whether all elements in the expression element list have been read, if so, execute step S18, if not, execute step S12;

[0016] S18. Determine whether the symbol stack is empty. If not, pop the top symbol of the stack and add it to the suffix expression. Determine again whether the symbol stack is empty. If so, the conversion operation ends.

[0017] Step 2. Calculate the search suffix expression, which includes:

[0018] S21. Start the operation and check the suffix expression;

[0019] S22. Take an element from the suffix expression;

[0020] S23. Determine whether the element is a search expression. If so, push the search expression into the stack and execute step S26. Otherwise, execute step S24.

[0021] S24. Determine whether the element is an operator, if not, output an error, if yes, execute step S25;

[0022] S25. Determine whether the symbol is ~. If so, pop one element from the stack, merge it with the operator, push the result onto the stack, and then execute step S26. Otherwise, pop two elements from the stack, merge them with the operator, push the result onto the stack, and then execute step S26.

[0023] S26. Determine whether there are still unprocessed elements in the suffix expression. If so, execute step S22; otherwise, execute step S27;

[0024] S27. Determine whether there is only one element in the stack, if not, output an error, if yes, execute step S28;

[0025] S28. The elements in the stack are popped out, and the Elasticsearch search statement is output. The operation ends.

[0026] In a method of converting expression retrieval into Elasticsearch search statements of the present invention, based on the application scenario of research report retrieval, the fields used in the design expression link include: title, abstract, keywords, author, writing organization, writing time, release time, report page number, number and reference link.

[0027] In a method of converting expression search into Elasticsearch search statement of the present invention, the simple search expression symbols and their meanings are defined as follows:

[0028] (1) For the symbol "=", the search formula example is "title=Elasticsearch", which means "the title must contain the Elasticsearch keyword";

[0029] (2) For the symbol “!=”, the search formula example is “title!=Elasticsearch”, which means “the title cannot contain the Elasticsearch keyword”;

[0030] (3) For the symbol “>” or “>=”, the search formula example is “Release date>=2021-06-11”, which means “Research report release date is greater than or equal to 2021-06-11”;

[0031] (4) For the symbol "< or <=", the search formula example is "writing time <= 2020-01-01", which means "the writing time of the research report is less than or equal to 2021-06-11".

[0032] In a method of converting expression search into Elasticsearch search statement of the present invention, the simple search formula combination symbols and their meanings are defined as follows:

[0033] (1) For the symbol “|”, the search query example is “title=Elasticsearch |title=ES”, which means “the title contains the keyword Elasticsearch or ES”;

[0034] (2) For the symbol “&”, the search formula example is “title=Elasticsearch & title!=Solr”, which means “the title contains the keyword Elasticsearch but does not contain Solr”;

[0035] (3) For the symbol “~”, the search formula example is “~Title=Elasticsearch”, which means “the title does not contain Elasticsearch, which is equivalent to title!=Elasticsearch”;

[0036] (4) For the symbol “^”, the search formula example is “title=Elasticsearch ^ title!=Solr”, which means “only one of the previous and next search formulas is successful”;

[0037] (5) For the symbol “()”, the search formula example is “~(title=Elasticsearch & title!=Solr)”, which means “mainly to change the priority of the search formula operation, equivalent to title!=Elasticsearch | title=Solr”.

[0038] In a method of converting expression retrieval into Elasticsearch search statements of the present invention, the priority of the retrieval expression symbols is defined as follows:

[0039] Define the operator "()" with a priority of 1 and associativity from left to right;

[0040] Define operators "=, !=, >, >=, <, <=" with a priority of 2 and associativity from left to right;

[0041] Define the operator "~" with a priority of 3 and associativity from right to left;

[0042] Define operators "&, |, ^" with a priority of 4 and associativity from left to right.

[0043] A system for converting expression retrieval into Elasticsearch search statements, the system structure comprises a retrieval expression input module, a suffix expression generator module, an Elasticsearch search statement generator module and an Elasticsearch search statement output module, wherein:

[0044] The search expression input module provides search expression input and Elasticsearch version selection, performs search expression format verification and error correction, and if correct, passes the input and selected content to subsequent modules for processing;

[0045] The suffix expression generator module converts the received search expression into a suffix expression, stores the two expressions, and then passes the suffix expression and the received Elasticsearch version to the Elasticsearch search statement generator module;

[0046] The Elasticsearch search statement generator module converts the suffix expression into an executable search statement of the corresponding version of Elasticsearch according to the received Elasticsearch version and suffix expression and stores the result, and notifies the Elasticsearch search statement output module;

[0047] The Elasticsearch search statement output module retrieves and displays a list of relationship groups among the stored search expression, suffix expression and corresponding Elasticsearch executable search statement according to the received result notification, and provides quick copying of results and comparison between groups as needed.

[0048] Based on the above technical solution, the method of converting expression retrieval into Elasticsearch search statement in the present invention has the following technical advantages compared with the prior art:

[0049] 1. The present invention converts complex and difficult semantic logical relationships into precise, concise and easy-to-understand relationships between operators through expression design, so that non-technical personnel can also smoothly express search intentions, thus laying the foundation for obtaining search results that better match the intentions.

[0050] 2. The present invention dynamically converts expressions that are easy for people to understand into suffix expressions that are easy for machines to process through conversion algorithm design, and further assembles Elasticsearch executable search statements that can actually run, thereby greatly reducing the learning cost of complex searches and the time cost of constructing statements, and improving the flexibility and efficiency of searches. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 It is a schematic diagram of the implementation process of converting a search expression into a suffix expression in a method of converting an expression search into an Elasticsearch search statement of the present invention.

[0052] Figure 2 The present invention is a schematic diagram of the implementation process of calculating the search formula suffix expression in a method of converting expression search into Elasticsearch search statement.

[0053] Figure 3 It is a schematic diagram of the system structure composition of the present invention for converting expression retrieval into Elasticsearch search statements. DETAILED DESCRIPTION

[0054] Below, we further elaborate on the method of converting expression retrieval into Elasticsearch search statements in the present invention in combination with the accompanying drawings and specific embodiments, so as to more clearly understand its structure and working process. However, this shall not limit the protection scope of the present invention.

[0055] like Figure 1 and Figure 2 As shown, the present invention is a method for converting expression retrieval into Elasticsearch search statements, wherein the retrieval expression used for the expression retrieval consists of a retrieval term and a logical operator, and the retrieval expression is submitted to the retrieval system, which parses the retrieval expression into a retrieval command that can be recognized and executed by the search engine, and then submits it to the open source search engine Elasticsearch to obtain the desired retrieval results.

[0056] The method of the present invention specifically includes two steps of designing an expression and designing a conversion algorithm. In the step of designing an expression, the fields used are listed, and the priorities of simple search expression symbols, search expression combiners and search expression symbols are defined respectively;

[0057] like Figure 1 As shown in the figure, the conversion algorithm design includes:

[0058] The first step is to convert the search expression into a suffix expression, which includes:

[0059] S11. Start the operation, view the expression, and convert the expression into a list of expression elements;

[0060] S12. Take the next element;

[0061] S13 determines whether it is a simple search expression, if so, add the suffix expression and execute step s17, if not, execute step S14;

[0062] S14 determines whether it is a search formula combination symbol, if not, an error message is output, if so, step S15 is executed;

[0063] S15. Distinguish the characters to see whether it is a left bracket, a right bracket, or other combining characters;

[0064] S16. If it is a right bracket, a detection element is popped out from the symbol stack, and it is determined whether the detection element is a right bracket. If so, the right bracket is discarded and step S17 is executed; if it is a left bracket, it is pushed into the symbol stack and step S17 is executed; if it is other combiners, it is determined whether the symbol stack is empty. If it is empty, other combiners are pushed into the symbol stack and step S17 is executed. If it is not empty, it is determined whether the priority of the current symbol is higher than the top symbol of the stack. If it is not, it is pushed into the symbol stack and step S17 is executed. If it is yes, the top symbol is popped out and added to the suffix expression, and the cycle is repeated again to determine whether the priority of the current symbol is higher than the top symbol of the stack, until all are pushed into the symbol stack and step S17 is executed;

[0065] S17. Determine whether all elements in the expression element list have been read, if so, execute step S18, if not, execute step S12;

[0066] S18. Determine whether the symbol stack is empty. If not, pop the top symbol of the stack and add it to the suffix expression. Determine again whether the symbol stack is empty. If so, the conversion operation ends.

[0067] like Figure 2 As shown, there is also a second step. Calculate the search formula suffix expression, and the implementation process includes:

[0068] S21. Start the operation and check the suffix expression;

[0069] S22. Take an element from the suffix expression;

[0070] S23. Determine whether the element is a search expression. If so, push the search expression into the stack and execute step S26. Otherwise, execute step S24.

[0071] S24. Determine whether the element is an operator, if not, output an error, if yes, execute step S25;

[0072] S25. Determine whether the symbol is ~. If so, pop one element from the stack, merge it with the operator, push the result onto the stack, and then execute step S26. Otherwise, pop two elements from the stack, merge them with the operator, push the result onto the stack, and then execute step S26.

[0073] S26. Determine whether there are still unprocessed elements in the suffix expression. If so, execute step S22; otherwise, execute step S27;

[0074] S27. Determine whether there is only one element in the stack, if not, output an error, if yes, execute step S28;

[0075] S28. The elements in the stack are popped out, and the Elasticsearch search statement is output. The operation ends. Example 1

[0076] This embodiment takes the research report scenario expression retrieval as an example, and combines it with the open source search engine Elasticsearch to propose a method for converting expression retrieval into Elasticsearch search statements. Through expression design, referring to the common needs of the research report retrieval scenario, the expression is combined with the four arithmetic rules of the reference standard, which not only facilitates understanding and use, but also gives the expression unlimited ability to expand. In the application scenario of research report retrieval, the fields used in the design expression link include: title, abstract, keywords, author, writing organization, writing time, release time, report page number, number and reference link.

[0077] The simple search symbols and their meanings are defined as follows:

[0078]

[0079] The simple search formula combination symbols and their meanings are defined as follows:

[0080]

[0081] The defined search expression symbol priority is:

[0082]

[0083] When converting a search expression to a postfix expression:

[0084] Original expression: Title = Elasticsearch & ((Abstract = Elasticsearch & Application Time>2021-06-11) | (Abstract = ES & Authorization Time<2020-06-11))

[0085] Suffix expression: Abstract = Elasticsearch Abstract = Elasticsearch Application Time > 2021-06-11 & Abstract = ES Authorization Time < 2020-06-11 & | & .

[0086] like Figure 3 As shown, the present invention also relates to a system for converting expression retrieval into Elasticsearch search statements, the system structure comprises a retrieval expression input module 1, a suffix expression generator module 2, an Elasticsearch search statement generator module 3 and an Elasticsearch search statement output module 4, wherein:

[0087] The search expression input module 1 provides the input of the search expression and the selection of the Elasticsearch version, performs search expression format verification and error correction, and if correct, passes the input and selected content to the subsequent suffix expression generator module 2 for processing;

[0088] The suffix expression generator module 2 converts the received search expression into a suffix expression, stores the two expressions, and then passes the suffix expression and the received Elasticsearch version to the Elasticsearch search statement generator module 3;

[0089] The Elasticsearch search statement generator module 3 converts the suffix expression into an executable search statement of the corresponding version of Elasticsearch according to the received Elasticsearch version and suffix expression and stores the result, and notifies the Elasticsearch search statement output module 4;

[0090] The Elasticsearch search statement output module 4 retrieves and displays the relationship group list of the stored retrieval expression, suffix expression and corresponding Elasticsearch executable search statement according to the received result notification, and provides quick result copying and mutual comparison between groups as needed.

[0091] In the system for converting the above expression search into an Elasticsearch search statement, when calculating the search expression suffix expression, the suffix expression is scanned from left to right, and when a search expression is encountered, the search expression is pushed into the stack; when an operator is encountered, the search expression on the top of the stack is popped out, the two search expressions are parsed and merged according to the operator, and the result is pushed into the stack, and the above process is repeated until the rightmost end of the expression, and the final result is the converted Elasticsearch search statement.

[0092] Undoubtedly, the above are only specific embodiments of the present invention, and other feasible composition designs and operation processes are also included. In short, the protection scope of the present invention also includes other obvious changes and substitutions for those skilled in the art.

Claims

1. A method for converting expression retrieval into Elasticsearch search statements, characterized in that: The search expression used in the expression search consists of search terms and logical operators. The search expression is submitted to the search system, and the search system parses the search expression into a search command that can be recognized and executed by the search engine, and then submits it to the open source search engine Elasticsearch to obtain the desired search results. The method specifically includes two steps: designing expressions and designing conversion algorithms. In the step of designing expressions, the fields used are listed, and the priorities of simple search expression symbols, search expression combiners, and search expression symbols are defined respectively; The design of the conversion algorithm includes: The first step is to convert the search expression into a suffix expression, which includes: S11. Start the operation, view the expression, and convert the expression into a list of expression elements; S12. Take the next element; S13 determines whether it is a simple search expression, if so, add the suffix expression and execute step s17, if not, execute step S14; S14 determines whether it is a search formula combination symbol, if not, an error message is output, if so, step S15 is executed; S15. Distinguish the characters to see whether it is a left bracket, a right bracket, or other combining characters; S16. If it is a right bracket, a detection element is popped out from the symbol stack, and it is determined whether the detection element is a right bracket. If so, the right bracket is discarded and step S17 is executed; if it is a left bracket, it is pushed into the symbol stack and step S17 is executed; if it is other combiners, it is determined whether the symbol stack is empty. If it is empty, other combiners are pushed into the symbol stack and step S17 is executed. If it is not empty, it is determined whether the priority of the current symbol is higher than the top symbol of the stack. If it is not, it is pushed into the symbol stack and step S17 is executed. If it is yes, the top symbol is popped out and added to the suffix expression, and the cycle is repeated again to determine whether the priority of the current symbol is higher than the top symbol of the stack, until all are pushed into the symbol stack and step S17 is executed; S17. Determine whether all elements in the expression element list have been read, if so, execute step S18, if not, execute step S12; S18. Determine whether the symbol stack is empty. If not, pop the top symbol of the stack and add it to the suffix expression. Determine again whether the symbol stack is empty. If so, the conversion operation ends. Step 2. Calculate the search suffix expression, which includes: S21. Start the operation and check the suffix expression; S22. Take an element from the suffix expression; S23. Determine whether the element is a search expression. If so, push the search expression into the stack and execute step S26. Otherwise, execute step S24. S24. Determine whether the element is an operator, if not, output an error, if yes, execute step S25; S25. Determine whether the symbol is ~. If so, pop one element from the stack, merge it with the operator, push the result onto the stack, and then execute step S26. Otherwise, pop two elements from the stack, merge them with the operator, push the result onto the stack, and then execute step S26. S26. Determine whether there are still unprocessed elements in the suffix expression. If so, execute step S22; otherwise, execute step S27; S27. Determine whether there is only one element in the stack, if not, output an error, if yes, execute step S28; S28. The elements in the stack are popped out, and the Elasticsearch search statement is output. The operation ends.

2. The method for converting expression retrieval into Elasticsearch search statement according to claim 1, characterized in that: In the application scenario of research report retrieval, the fields used in the design expression link include: title, abstract, keywords, author, writing organization, writing time, publication time, report page number, number and reference link.

3. The method for converting expression retrieval into Elasticsearch search statement according to claim 2, characterized in that: The simple search symbols and their meanings are defined as follows: (1) For the symbol "=", the search formula example is "title=Elasticsearch", which means "the title must contain the Elasticsearch keyword"; (2) For the symbol "!=", the search formula example is "title!=Elasticsearch", which means "the title cannot contain the Elasticsearch keyword"; (3) For the symbol "> or >=", the search formula example is "Release date>=2021-06-11", which means "Research report release date is greater than or equal to 2021-06-11"; (4) For the symbol "< or <=", the search formula example is "writing time <= 2020-01-01", which means "the writing time of the research report is less than or equal to 2021-06-11".

4. The method for converting expression retrieval into Elasticsearch search statement according to claim 2 or 3, characterized in that: The defined simple search formula combination symbols and their meanings are: (1) For the symbol "|", the search formula example is "title=Elasticsearch | title=ES", which means "the title contains the keyword Elasticsearch or ES"; (2) For the symbol "&", the search formula example is "title=Elasticsearch & title!=Solr", which means "the title contains the keyword Elasticsearch but does not contain Solr"; (3) For the symbol "~", the search formula example is "~Title=Elasticsearch", which means "The title does not contain Elasticsearch, which is equivalent to title!=Elasticsearch"; (4) For the symbol "^", the search formula example is "title=Elasticsearch ^ title!=Solr", which means "only one of the previous and next search formulas is successful"; (5) For the symbol "()", the search formula example is "~(title=Elasticsearch & title!=Solr)", which means "In order to change the priority of the search formula operation, it is equivalent to title!=Elasticsearch | title=Solr".

5. The method for converting expression retrieval into Elasticsearch search statement according to claim 4, characterized in that: The defined search expression symbol priority is: Define the operator "()" with a priority of 1 and associativity from left to right; Define operators "=, !=, >, >=, <, <=" with a priority of 2 and associativity from left to right; Define the operator "~" with a priority of 3 and associativity from right to left; Define operators "&, |, ^" with a priority of 4 and associativity from left to right.

6. A system for converting expression retrieval into Elasticsearch search statements, characterized in that: The system structure comprises a search expression input module (1), a suffix expression generator module (2), an Elasticsearch search statement generator module (3) and an Elasticsearch search statement output module (4), wherein: The search expression input module (1) provides the input of the search expression and the selection of the Elasticsearch version, performs search expression format verification and error correction, and if correct, passes the input and selected content to subsequent modules for processing; The suffix expression generator module (2) converts the received search expression into a suffix expression, stores the two expressions, and then transmits the suffix expression and the received Elasticsearch version to the Elasticsearch search statement generator module; The Elasticsearch search statement generator module (3) converts the suffix expression into an executable search statement of the corresponding version of Elasticsearch according to the received Elasticsearch version and suffix expression, stores the converted statement, and notifies the Elasticsearch search statement output module of the result; The Elasticsearch search statement output module (4) retrieves and displays the stored search expression, suffix expression and corresponding Elasticsearch executable search statement according to the received result notification.

Citation Information

Patent Citations

  • Query expression in vertical search engine

    CN103177038A

  • Data query method and device, computer equipment and storage medium

    CN114117242A