Skip to main content

Terms Set Query

The TermsSet query returns documents that contain the minimum amount of exact terms in a provided field. The Terms set query is the same as [[zio.elasticsearch.query.TermsQuery]], except you can define the number of matching terms required to return a document.

In order to use the TermsSet query import the following:

import zio.elasticsearch.query.TermsSetQuery
import zio.elasticsearch.ElasticQuery.termsSetQuery

You can create a TermsSet query with defined minimumShouldMatchField using the termsSet method this way:

val query: TermsSetQuery = termsSet(field = "stringField", minimumShouldMatchField = "intField", terms = "a", "b", "c")

You can create a type-safe TermsSet query with defined minimumShouldMatchField using the termsSet method this way:

val query: TermsSetQuery = termsSet(field = Document.name, minimumShouldMatchField = Document.intField, terms = "a", "b", "c")

You can create a TermsSet query with defined minimumShouldMatchScript using the termsSetScript method this way:

import zio.elasticsearch.script.Script

val query: TermsSetQuery = termsSetScript(field = "stringField", minimumShouldMatchScript = Script("doc['intField'].value"), terms = "a", "b", "c")

You can create a type-safe TermsSet query with defined minimumShouldMatchScript using the termsSetScript method this way:

import zio.elasticsearch.script.Script

val query: TermsSetQuery = termsSetScript(field = Document.name, minimumShouldMatchScript = Script("doc['intField'].value"), terms = "a", "b", "c")

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

val queryWithBoostAndMinimumShouldMatchField: TermsSetQuery = termsSet(field = "booleanField", minimumShouldMatchField = "intField", terms = true, false).boost(2.0)
val queryWithBoostAndMinimumShouldMatchScript: TermsSetQuery = termsSetScript(field = "booleanField", minimumShouldMatchScript = Script("doc['intField'].value"), terms = true, false).boost(2.0)

You can find more information about TermsSet query here.