Elastic search - Query DSL - elasticsearch - elasticsearch tutorial - elastic search
Elasticsearch Query DSL
- In Elastic search, searching is carried out by using query based on JSON. Query is made up of two clauses −
- Leaf Query Clauses − These clauses are match, term or range, which look for a specific value in specific field.
- Compound Query Clauses − These queries are a combination of leaf query clauses and other compound queries to extract the desired information.
- Elastic search supports a large number of queries.
- A query starts with a query key word and then has conditions and filters inside in the form of JSON object.
learn elasticsearch tutorials - query documents Example
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node
The different types of queries have been described below:
Match All Query:
- This is the most basic query; it returns all the content and with the score of 1.0 for every object. For example,
Request Body:
Response:
Full Text Queries:
- These queries are used to search a full body of text like a chapter or a news article.
- This query works according to the analyzer associated with that particular index or document. In this section,
- we will discuss the different types of full text queries.
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node
Match query:
- This query matches a text or phrase with the values of one or more fields. For example,
Request Body:
Response:
Multi_match query:
- This query matches a text or phrase with more than one field. For example,
Request Body:
Response:
Query String Query:
- This query uses query parser and query_string keyword. For example,
Request Body:
Response:
Term Level Queries:
- These queries mainly deal with structured data like numbers, dates and emuns. For example,
Request Body:
Response:
Range Query:
- This query is used to find the objects having values between the ranges of values. For this, we need to use operators like
- gte − greater than equal to
- gt − greater-than
- lte − less-than equal to
- lt − less-than
- For example,
Request Body:
Response:
- Other types of term level queries are −
- Exists query − If a certain field has non null value.
- Missing query − This is completely opposite to exists query, this query searches for objects without specific fields or fields having null value.
- Wildcard or regexp query − This query uses regular expressions to find patterns in the objects.
- Type query − documents with specific type. For example,
Request Body:
Response:
- All the school JSON objects present in the specified indices.
Compound Queries:
- These queries are a collection of different queries merged with each other by using Boolean operators like and, or, not or for different indices or having function calls etc. For example,
Request Body:
Response:
Joining Queries:
- These queries are used where more than one mapping or document is included. There are two types of joining queries:
Nested Query:
- These queries deal with nested mapping (you will read more about it in the next chapter).
has_child and has_parent queries
- These queries are used to retrieve child or parent of the document, which got match in the query. For example,
Request Body
Response:
Geo Queries:
- These queries deal with geo locations and geo points.
- These queries help to find out schools or any other geographical object near to any location.
- You need to use geo point data type.
- For example,
Request Body:
Response:
Note − If you get an exception while performing the above example, please add the following mapping to your index.