Distinct class

更新时间:
复制 MD 格式

The Distinct class controls how OpenSearch deduplicates search results by field value. Use it to cap the number of results returned per unique value of an attribute field—for example, limiting each seller to at most two products in a search result list.

Constructors

ConstructorSignatureDescription
No-argumentDistinct()Creates a Distinct instance with no initial configuration.
Field-initializedDistinct(String key)Creates a Distinct instance and sets the deduplication field.

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe attribute field used for deduplication. Must be an attribute field.

Methods

setKey

Distinct setKey(String key)

Sets the attribute field used for deduplication.

ParameterTypeRequiredDefaultDescription
keyStringYesThe attribute field used for deduplication. Must be an attribute field.

getKey

String getKey()

Returns the attribute field currently set for deduplication.

setDistCount

Distinct setDistCount(int distCount)

Sets the number of documents to extract each time.

ParameterTypeRequiredDefaultDescription
distCountintNo1The number of documents extracted each time.

getDistCount

int getDistCount()

Returns the current distCount value.

setDistTimes

Distinct setDistTimes(int distTimes)

Sets the number of extraction passes to run.

ParameterTypeRequiredDefaultDescription
distTimesintNo1Number of times distinct extraction is applied.

getDistTimes

int getDistTimes()

Returns the current distTimes value.

setReserved

Distinct setReserved(boolean reserved)

Controls whether documents that exceed the distCount limit are kept or discarded from the result set.

ParameterTypeRequiredDefaultDescription
reservedBooleanNotruetrue: keep excess documents in the result set. false: discard them.
When reserved is false, the discarded documents are removed from the result set. Whether their count is subtracted from totalHits depends on the updateTotalHit setting.

setUpdateTotalHit

Distinct setUpdateTotalHit(boolean updateTotalHit)

Controls whether the count of discarded documents is subtracted from totalHits. Takes effect only when reserved is false.

ParameterTypeRequiredDefaultDescription
updateTotalHitBooleanNofalsetrue: subtract discarded document count from totalHits. false: leave totalHits unchanged.
Warning

Setting updateTotalHit to true makes totalHits reflect the adjusted count, but the result may be inaccurate.

setDistFilter

Distinct setDistFilter(String distFilter)

Sets a filter condition to restrict which documents are eligible for distinct extraction.

ParameterTypeRequiredDefaultDescription
distFilterStringNoAll documents selectedA filter expression. Documents that do not match are excluded from extraction but are still sorted alongside the first group of extracted results.
Excluded documents are not extracted, but they remain in the result set and are sorted together with the first extraction group.

getDistFilter

String getDistFilter()

Returns the current filter condition.

setGrade

Distinct setGrade(double grade)

Sets the grade threshold for distinct extraction.

ParameterTypeRequiredDefaultDescription
gradedoubleNoThe threshold value for distinct extraction.

getGrade

String getGrade()

Returns the current grade threshold as a String.