1. Match Query: This is the most basic query in Elasticsearch. It is used to search for matching documents within a collection. For example, to find all documents with the term “Elasticsearch” in the title field, you could use the following query:

{
“query”: {
“match” : {
“title” : “Elasticsearch”
}
}
}

2. Term Query: This query is used to search for exact values within a field. For example, to find all documents with the term “Elasticsearch” in the title field, you could use the following query:

{
“query”: {
“term” : {
“title” : “Elasticsearch”
}
}
}

3. Multi-Match Query: This query is used to search for multiple values within multiple fields. For example, to find all documents with the term “Elasticsearch” in the title or description field, you could use the following query:

{
“query”: {
“multi_match” : {
“query” : “Elasticsearch”,
“fields” : [“title”, “description”]
}
}
}

4. Bool Query: This query is used to combine multiple queries together. For example, to find all documents with the term “Elasticsearch” in the title field and the term “Search” in the description field, you could use the following query:

{
“query”: {
“bool” : {
“must” : [
{
“match” : {
“title” : “Elasticsearch”
}
},
{
“match” : {
“description” : “Search”
}
}
]
}
}
}

5. Range Query: This query is used to find documents within a range of values in a field. For example, to find all documents with a price field greater than 10 and less than 20, you could use the following query:

{
“query”: {
“range” : {
“price” : {
“gte” : 10,
“lte” : 20
}
}
}
}

6. Nested Query: This query is used to search for documents within a nested object. For example, to find all documents with the term “Elasticsearch” in the title field within a nested object, you could use the following query:

{
“query”: {
“nested” : {
“path” : “nested_object”,
“query” : {
“match” : {
“nested_object.title” : “Elasticsearch”
}
}
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *