Elasticsearch query statement basic grammar and examples

Elasticsearch query statement basic grammar and examples Elasticsearch is a distributed search engine that uses a simple JSON format to store, search and analyze data.It provides a wealth of query grammar, and the user can flexibly find data in the index. Basic grammar: Elasticsearch query statements are usually composed of two main parts: query conditions and query content. Query condition: It is used to specify the fields or attributes we want to search.It can be a combination of one or more conditions.Common query conditions are: 1. MATCH: Search according to the specified entry or phrase. 2. Term: Search for precise matching entries in specific fields. 3. Range: Search for the value of the specified range condition in a specific field. 4. BOOL: Allow multiple query conditions, such as Must (and logic), Should (or logic) and Must_not (non -logic). Query content: Used to specify the content you want to search.It can be a combination of one or more conditions.Common query contents are: 1. MATCH: Specify the entry or phrases to be searched. 2. Term: Specify the entry to search. 3. Range: Specify the range of search to search. Example: 1. Simple MATCH query: GET /index_name/_search { "query": { "match": { "field_name": "search_term" } } } This query will search for the contents of the `Field_name` field of the index` index_name`. 2. Complex query example: GET /index_name/_search { "query": { "bool": { "must": [ { "match": { "field1": "value1" } }, { "match": { "field2": "value2" } } ], "filter": { "range": { "field3": { "gte": "value3" } } } } } } This query will perform a composite query in the `Index_name` index.The query condition is `Field1` is equal to` value1` and `fired2` is equal to` value2`, and at the same time meets the range of `Field3` greater than equal to `value3`. The above are some basic elasticsearch query sentence examples.According to actual needs, you can use different query combinations and operators to build more complex and advanced query.In order to use Elasticsearch for query, you need to first install and configure Elasticsearch, and create indexes suitable for your data structure.