Leaf Query Performs basic Operation. Example of leaf query is Terms query or match query
Compound Query Wrap Leaf query or other compound query.
bool
queries are used to add boolean logic to your queriesGET /recipe/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"ingredients.name": "parmesan"
}
}
],
"must_not": [
{
"match": {
"ingredients.name": "tuna"
}
}
],
"filter": [
{
"range": {
"preparation_time_minutes": {
"gte": 10,
"lte": 15
}
}
}
]
}
}
}
should
will used to boost the relevant score of the search results in the query contextGET /recipe/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"ingredients.name": "parmesan"
}
}
],
"must_not": [
{
"match": {
"ingredients.name": "tuna"
}
}
],
"should": [
{
"match": {
"ingredients.name": "parsley"
}
}
],
"filter": [
{
"range": {
"preparation_time_minutes": {
"gte": 10,
"lte": 15
}
}
}
]
}
}
}
GET /recipe/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"ingredients.name": {
"query": "parmesan",
"_name": "parmesan_must"
}
}
}
],
"must_not": [
{
"match": {
"ingredients.name": {
"query": "tuna",
"_name": "tuna_must_not"
}
}
}
],
"should": [
{
"match": {
"ingredients.name": {
"query": "parsley",
"_name": "parsley_should"
}
}
}
],
"filter": [
{
"range": {
"preparation_time_minutes": {
"gte": 10,
"lte": 15,
"_name": "prep_time_filter"
}
}
}
]
}
}
}
When you use the match
query, it analyzes the search query and converts match query to term queries during analysis process. When the boolean operator is set to and
it will translate to must
whereas when set to or
it translates to should
query during analysis phase.
GET /recipe/_search
{
"query": {
"match": {
"title": "pasta Carbonara"
}
}
}
GET /recipe/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"title": "pasta"
}
}
,
{
"term": {
"title": "carbonara"
}
}
]
}
}
}