Consider the following Elasticsearch query that filters documents based on a boolean field is_active. What documents will be returned?
{
"query": {
"bool": {
"filter": [
{ "term": { "is_active": true } }
]
}
}
}Think about what the term filter does with boolean fields.
The term filter matches documents where the field exactly equals the given value. Here, it matches documents where is_active is true.
You index a document with a binary field file_data containing base64 encoded string. What happens when you retrieve this field?
{
"mappings": {
"properties": {
"file_data": { "type": "binary" }
}
}
}Remember how Elasticsearch stores binary fields internally.
Binary fields store data as base64 encoded strings and return the same base64 string when retrieved.
Given this query, why might it return zero documents even though some documents have is_verified set to false?
{
"query": {
"bool": {
"must": [
{ "term": { "is_verified": false } }
]
}
}
}Check the field mapping type and how term queries work with booleans.
If is_verified is mapped as a string, the term query with boolean false won't match any documents because the types differ.
Choose the correct JSON snippet to define a binary field named image_data in an Elasticsearch index mapping.
Recall the exact type name Elasticsearch uses for binary data.
Elasticsearch uses binary as the type for base64 encoded binary data fields.
Assume an index with 100 documents: 60 have is_active true, 40 have is_active false. What is the count of documents returned by this query?
{
"query": {
"bool": {
"must_not": [
{ "term": { "is_active": true } }
]
}
}
}The must_not clause excludes documents matching the condition.
The query excludes documents where is_active is true, so only the 40 documents with is_active false remain.