Skip to main content

Term Query

The Term query returns documents that contain an exact term in the provided field.

In order to use the Term query import the following:

import zio.elasticsearch.query.TermQuery
import zio.elasticsearch.ElasticQuery._

You can create a Term query using the term method this way:

val query: TermQuery = term(field = "stringField", value = "test")

You can create a type-safe Term query using the term method this way:

val query: TermQuery = term(field = Document.name, value = "test")

If you want to change the boost, you can use boost method:

val queryWithBoost: TermQuery = term(field = Document.name, value = "test").boost(2.0)

If you want to change the case_insensitive, you can use caseInsensitive, caseInsensitiveFalse or caseInsensitiveTrue method:

val queryWithCaseInsensitive: TermQuery = term(field = Document.name, value = "test").caseInsensitive(true)
val queryWithCaseInsensitiveFalse: TermQuery = term(field = Document.name, value = "test").caseInsensitiveFalse
val queryWithCaseInsensitiveTrue: TermQuery = term(field = Document.name, value = "test").caseInsensitiveTrue

You can find more information about Term query here.