[learn ES Series]-4.ElasticSearch basic interaction-basic query and Advanced query
Basic query
POST http://127.0.0.1:9200/book/_search
1. Simple query {"query": {"match_all": {}} 2. Conditional query {"query": {"match": {"title": "getting started"}}, "from": 1, "size": 5, "sort": {"publish_date": {"order": "asc"}} 3. Aggregate query {"aggs": {"group_by_word_count": {"terms": {"field": "word_count"}} "group_by_publish_date": {"terms": {"field": "publish_date"} {"aggs": {"total_word_count": {"stats": {"field": "word_count"} } {"aggs": {"max_word_count": {"max": {"field": "word_count"} Advanced query
1. A subconditional query is also known as a leaf conditional query (a specific value referred to by a specific field query)
1.1Query Context
In the process of query, in addition to judging whether the document meets the query conditions, ES will also calculate a _ score to identify the matching degree, in order to determine how good the matching degree is between the target document and the query condition. 1.1.1 full text query: data for text type (text)-1. Fuzzy matching {"query": {"match": {"title": "PHP from entry to mastery"}}
Will match PHP, from entry to proficiency.
-- 2. Idiom match {"query": {"match_phrase": {"title": "PHP from beginner to proficient"}}-3. Multiple fields fuzzy matching query {"query": {"multi_match": {"query": "PHP", "fields": ["title", "author"]}
Query title or author contains the PHP keyword
Syntax query {"query": {"query_string": {"query": "(introduction to PHP AND) OR General Reform"}}
The text field contains both PHP and entry keywords, or the text field contains general modification.
Query multiple fields (specified field query) {"query": {"query_string": {"query": "PHP", "fields": ["title", "author"]}} 1.1.2 Field-level query: for structured data, such as numbers, dates, etc.-- 1. Specify field precision query {"query": {"term": {"author": "general reform"}}-- 2. Range query-2.1Numeric range {"query": {"range": {"word_count": {"gte": "170000" "lte": "200000"}-2.2 date range {"query": {"range": {"publish_date": {"gte": "2018-01-01" "lte": "2019-12-30"} {"query": {"range": {"publish_date": {"gte": "2019-01-01", "lte": "now"}}
1.2Filter Context
In the query process, only judge whether the document meets the conditions, only yes or no.
(query judges yes or no, and the matching degree of _ score)
ES caches query results, so it is faster than Query.
{"query": {"bool": {"filter": {"term": {"author": "universal reform"}
two。 Compound conditional query (sub-query with a certain logical combination)
{"query": {"bool": {"must": {"match": {"title": "PHP from entry to mastery"}} "filter": {"range": {"word_count": {"gt": 170000}}, "from": 1, "size": 1}