In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to analyze the DSL query in elasticsearch. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
ES provides a complete query DSL based on JSON, which consists of two kinds of clauses
# # 1. Query category 1 > basic query
Common query commands: match, term, range.
2 > compound query
A composite query consists of a basic query or multiple basic queries that are combined logically (bool or dis_max) or the behavior of changing query conditions (constant_score).
3 > ES also allows an expensive query. If you don't need it for the time being, you won't record it here. Check the official website for details.
# # 2. Query and filter context
We use _ search API to retrieve relevant content
As can be seen from the figure: took indicates the time spent in this query, time_out indicates whether the query timed out, and the content of the query is found in the hits node.
Common query parameters are as follows:
Query, specifying query criteria
Match, fuzzy query, eg: query "Zhang", will query Xiao Zhang, Zhang San, etc.
Term, precise search, eg: age=33
Bool, multi-conditional joint query
Must, for bool conditions, eg: name= "zhang san" and age= "33"
Should, for bool conditions, eg:name= "zhang san" or age= "33"
Filter, filtering search results
Range, interval query, eg:price > 8000
The following is an example of the common query instructions above
PUT / user/_doc/1 {"id": 1001, "name": "Zhang San", "age": 30, "sex": "0", "add_time": "2020-09-22"}
PUT / user/_doc/2 {"id": 1002, "name": "Zhang Qi", "age": 35, "sex": "0", "add_time": "2020-09-24"}
Term means a perfect match, that is, an accurate query, and no word segmentation will be performed on the search words before retrieval. In the data above, let's retrieve "Zhang San"
It is found that no data was retrieved. Why? According to the official website of es, term belongs to exact matching and can only retrieve individual words. Eg: we search "three".
It was retrieved when it was found. Then our hope is to find "Zhang San" accurately. What should we do? At this point, we use the compound query, as follows
Bool represents the composite query flag, and the conditions within the must representation must be met at the same time.
Why is it necessary to use a composite query to retrieve the data? This is because the word name is segmented when it is stored. I use the default word splitter for word segmentation here, and we can see how the default word splitter handles it.
All right, now that term understands, let's take a look at match.
We still search "Zhang San" and the results are as follows
Why, how did "Zhang Qi" be retrieved? This is because when match carries on the retrieval, it will first split the key words, and then retrieve them according to a single word, so the search result above is that all the words including "Zhang" and "three" will be retrieved.
To expand, if you want to query the sentence containing "Zhang San", that is, "Zhang San" will appear next to each other, use match_phrase
The above is the editor for you to share how to parse the DSL query in elasticsearch, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.