Class ValuesSource.Bytes.WithOrdinals.FieldData
- Enclosing class:
- ValuesSource.Bytes.WithOrdinals
-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals
ValuesSource.Bytes.WithOrdinals.FieldDataNested classes/interfaces inherited from class org.elasticsearch.search.aggregations.support.ValuesSource.Bytes
ValuesSource.Bytes.Script, ValuesSource.Bytes.WithOrdinals, ValuesSource.Bytes.WithScriptNested classes/interfaces inherited from class org.elasticsearch.search.aggregations.support.ValuesSource
ValuesSource.Bytes, ValuesSource.GeoPoint, ValuesSource.Numeric, ValuesSource.Range -
Field Summary
FieldsFields inherited from class org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals
EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbytesValues(org.apache.lucene.index.LeafReaderContext context)Get a byte array like view into the values.globalOrdinalsMapping(org.apache.lucene.index.LeafReaderContext context)Returns a mapping from segment ordinals to global ordinals.org.apache.lucene.index.SortedSetDocValuesglobalOrdinalsValues(org.apache.lucene.index.LeafReaderContext context)Get a "global" view into the leaf's ordinals.org.apache.lucene.index.SortedSetDocValuesordinalsValues(org.apache.lucene.index.LeafReaderContext context)Get a view into the leaf's ordinals and theirBytesRefvalues.booleanWhether this values source is able to provide a mapping between global and segment ordinals, by returning the underlyingOrdinalMap.Methods inherited from class org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals
docsWithValue, globalMaxOrd, hasOrdinalsMethods inherited from class org.elasticsearch.search.aggregations.support.ValuesSource.Bytes
roundingPreparerMethods inherited from class org.elasticsearch.search.aggregations.support.ValuesSource
needsScores
-
Field Details
-
indexFieldData
-
-
Constructor Details
-
FieldData
-
-
Method Details
-
bytesValues
Description copied from class:ValuesSourceGet a byte array like view into the values. This is the "native" way to accessValuesSource.Bytes-style values.- Specified by:
bytesValuesin classValuesSource
-
ordinalsValues
public org.apache.lucene.index.SortedSetDocValues ordinalsValues(org.apache.lucene.index.LeafReaderContext context)Description copied from class:ValuesSource.Bytes.WithOrdinalsGet a view into the leaf's ordinals and theirBytesRefvalues.Use
DocValuesIterator.advanceExact(int),SortedSetDocValues.getValueCount(), andSortedSetDocValues.nextOrd()to fetch the ordinals. UseSortedSetDocValues.lookupOrd(long)to convert form the ordinal number into theBytesRefvalue. Make sure tocopythe result if you need to keep it.Each leaf may have a different ordinal for the same byte array. Imagine, for example, an index where one leaf has the values
"a", "b", "d"and another leaf has the values"b", "c", "d"."a"has the ordinal0in the first leaf and doesn't exist in the second leaf."b"has the ordinal1in the first leaf and0in the second leaf."c"doesn't exist in the first leaf and has the ordinal1in the second leaf. And"d"gets the ordinal2in both leaves.If you have to compare the ordinals of values from different segments then you'd need to somehow merge them.
ValuesSource.Bytes.WithOrdinals.globalOrdinalsValues(org.apache.lucene.index.LeafReaderContext)provides such a merging at the cost of longer startup times when the index has been modified.- Specified by:
ordinalsValuesin classValuesSource.Bytes.WithOrdinals
-
globalOrdinalsValues
public org.apache.lucene.index.SortedSetDocValues globalOrdinalsValues(org.apache.lucene.index.LeafReaderContext context)Description copied from class:ValuesSource.Bytes.WithOrdinalsGet a "global" view into the leaf's ordinals. This can require construction of fairly large set of lookups in memory so preferValuesSource.Bytes.WithOrdinals.ordinalsValues(org.apache.lucene.index.LeafReaderContext)unless you need the global view.This functions just like
ValuesSource.Bytes.WithOrdinals.ordinalsValues(org.apache.lucene.index.LeafReaderContext)except that the ordinals thatSortedSetDocValues.nextOrd()andSortedSetDocValues.lookupOrd(long)operate on are "global" to all segments in the shard. They are ordinals into a lookup table containing all values on the shard.Compare this to the example in the docs for
ValuesSource.Bytes.WithOrdinals.ordinalsValues(org.apache.lucene.index.LeafReaderContext). Imagine, again, an index where one leaf has the values"a", "b", "d"and another leaf has the values"b", "c", "d". The global ordinal for"a"is0. The global ordinal for"b"is1. The global ordinal for"c"is2. And the global ordinal for"d"is, you guessed it,3.This makes comparing the values from different segments much simpler. But it comes with a fairly high memory cost and a substantial performance hit when this method is first called after modifying the index. If the global ordinals lookup hasn't been built then this method's runtime is roughly proportional to the number of distinct values on the field. If there are very few distinct values then the runtime'll be dominated by factors related to the number of segments. But in that case it'll be fast enough that you won't usually care.
- Specified by:
globalOrdinalsValuesin classValuesSource.Bytes.WithOrdinals
-
supportsGlobalOrdinalsMapping
public boolean supportsGlobalOrdinalsMapping()Description copied from class:ValuesSource.Bytes.WithOrdinalsWhether this values source is able to provide a mapping between global and segment ordinals, by returning the underlyingOrdinalMap. If this method returns false, then callingValuesSource.Bytes.WithOrdinals.globalOrdinalsMapping(org.apache.lucene.index.LeafReaderContext)will result in anUnsupportedOperationException.- Overrides:
supportsGlobalOrdinalsMappingin classValuesSource.Bytes.WithOrdinals
-
globalOrdinalsMapping
public LongUnaryOperator globalOrdinalsMapping(org.apache.lucene.index.LeafReaderContext context) throws IOExceptionDescription copied from class:ValuesSource.Bytes.WithOrdinalsReturns a mapping from segment ordinals to global ordinals. This allows you to post process segment ordinals into global ordinals which could save you a few lookups. Also, operating on segment ordinals is likely to produce a more "dense" list of, say, counts.Anyone looking to use this strategy rather than looking up on the fly should benchmark well and update this documentation with what they learn.
- Specified by:
globalOrdinalsMappingin classValuesSource.Bytes.WithOrdinals- Throws:
IOException
-