Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the DSL query methods of elasticsearch

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what are the DSL query methods of elasticsearch". In the daily operation, I believe that many people have doubts about the DSL query methods of elasticsearch. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what are the DSL query methods of elasticsearch?" Next, please follow the editor to study!

Query1. Term

Query, exact match, that is, no word splitter analysis

{"query": {"term": {"": "}} 2. Match

Query, fuzzy matching, word splitter analysis according to your given field, including only part of the keywords

{"query": {"match": {"": "}} 3. Match_all

Query all documents under the specified index

{"query": {"match_all": {}

Filter out all fields through match_all, and then filter out fields containing preview and fields excluding title,price through partial

{"query": {"match_all": {}}, "partial_fields": {"partial": {"include": ["preview"], "exclude": ["title,price"]}} 4. Match_phrase

Phrase query. Slop defines how many unknown words are separated by keywords.

{"query": {"match_phrase": {"query": "aaa,bbb", "slop": 2}} 5. Multi_match

Query, you can specify multiple fields

Query documents for which both filed1 and filed2 fields contain the value keyword

{"query": {"multi_match": {"query": "," fileds ": [", "]}} 6. Bool

Boolean query

Must: the condition must be met, which is equivalent to the and of the sql statement

Should: the condition can be satisfied or not, which is equivalent to the or of the sql statement.

Must_not: the condition does not need to be satisfied, which is equivalent to the not of the sql statement

{"query": {"bool": {"should": [{"term": {":"}}, {"term": {""}}], "must": [{"term": ""} {"term": {"": ""}}], "must_not": [{"term": {":"}}, {"term": {":"}}],}} 7. Filter

At the same time, the desired data is filtered out through filter conditions without affecting the scoring.

{"query": {"filtered": {"query": {"match_all": {},}, "filter": {"term": {":"}

Bool filtering query of filter

Must: the condition must be met, which is equivalent to the and of the sql statement

Should: the condition can be satisfied or not, which is equivalent to the or of the sql statement.

Must_not: the condition does not need to be satisfied, which is equivalent to the not of the sql statement

{"query": {"filtered": {"query": {"match_all": {},}, "filter": {"bool": {"should": [{"term": "} {"term": {"": ""}], "must": [{"term": {":"}}, {"term": {":"}}] "must_not": [{"term": {"": "}}, {" term ": {": "}}],}

Without bool, you can also use and, or and not directly.

{"query": {"filtered": {"query": {"match_all": {},}, "filter": {"and": [{"term": "} {"term": {"": ""}], "or": [{"term": {":"}}, {"term": {":"}}] "not": [{"term": {"": "}}, {" term ": {": "}}],}

Range range query of filter

Gt: greater than

Lt: less than

Gte: greater than or equal to

Lte: less than or equal to

{"query": {"filtered": {"query": {"match_all": {},}, "filter": {"range": {"gt": "" "gte": "," lt ":", "lte": ",} 8. Boost

Fixed score query every document we query has a _ score parameter, which is a match score.

Constant_score: fixed score query keyword (it supports filter, not match)

Boost: specify a fixed score field

{"query": {"constant_score": {"filter": {"match": {":"}}, "boost": 1} agg

Polymerization analysis

1. Terms

Group, corresponding to the group by in the sql statement

{"aggs": {"terms": {"field": ""} 2. Cardinality

Deduplicates, corresponding to the distinct in the sql statement

{"aggs": {"cardinality": {"field": ""} 3. Avg

Find the average value

{"aggs": {"avg": {"field": ""} 4. Max

Find the average value

{"aggs": {"max": {"field": ""} 5. Min

Find the average value

{"aggs": {"min": {"field": ""} 6. Sum

Find the average value

{"aggs": {"sum": {"field": ""} 7. Range

Group according to the specified interval

{"aggs": {"field": "," range ": [{" from ": 0," to ": 20}, {" from ": 20," to ": 40}, {" from ": 40 "to": 60}]}} 8. Date_histogram

Statistics by time

Min_doc_count: forces all buckets to be returned, even if buckets may be empty

Extended_bounds: return only the buckets between the minimum and maximum values in your data

{"aggs": {"date_histogram": {":", "interval": "month", "format": "yyyy-MM-dd", "min_doc_count": 0, "extended_bounds": {"min": "2014-01-01" "max": "2014-12-31"}} after collapse uses the collapse field The [fields] field appears in [hits] in the query result, which contains aggregates released after the deduplicated version of user_idES5.3 & folding is valid only for keyword types. At this point, the study of "what are the DSL query methods of elasticsearch" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report