Class ValuesSource.Bytes.WithOrdinals
- Direct Known Subclasses:
ValuesSource.Bytes.WithOrdinals.FieldData
- Enclosing class:
- ValuesSource.Bytes
BytesRef
value.-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.search.aggregations.support.ValuesSource.Bytes
ValuesSource.Bytes.Script, ValuesSource.Bytes.WithOrdinals, ValuesSource.Bytes.WithScript
Nested classes/interfaces inherited from class org.elasticsearch.search.aggregations.support.ValuesSource
ValuesSource.Bytes, ValuesSource.GeoPoint, ValuesSource.Numeric, ValuesSource.Range
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondocsWithValue
(org.apache.lucene.index.LeafReaderContext context) Get a "has any values" view into the values.long
globalMaxOrd
(org.apache.lucene.search.IndexSearcher indexSearcher) Get the maximum global ordinal.abstract LongUnaryOperator
globalOrdinalsMapping
(org.apache.lucene.index.LeafReaderContext context) Returns a mapping from segment ordinals to global ordinals.abstract org.apache.lucene.index.SortedSetDocValues
globalOrdinalsValues
(org.apache.lucene.index.LeafReaderContext context) Get a "global" view into the leaf's ordinals.boolean
Check if this values source supports using global and segment ordinals.abstract org.apache.lucene.index.SortedSetDocValues
ordinalsValues
(org.apache.lucene.index.LeafReaderContext context) Get a view into the leaf's ordinals and theirBytesRef
values.boolean
Whether 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
roundingPreparer
Methods inherited from class org.elasticsearch.search.aggregations.support.ValuesSource
bytesValues, needsScores
-
Field Details
-
EMPTY
-
-
Constructor Details
-
WithOrdinals
public WithOrdinals()
-
-
Method Details
-
docsWithValue
public DocValueBits docsWithValue(org.apache.lucene.index.LeafReaderContext context) throws IOException Description copied from class:ValuesSource
Get a "has any values" view into the values. It'll try to pick the "most native" way to check if there are any values, but it builds its own view into the values so if you need any of the actual values its best to use something likeValuesSource.bytesValues(org.apache.lucene.index.LeafReaderContext)
orValuesSource.Numeric.doubleValues(org.apache.lucene.index.LeafReaderContext)
but if you just need to know if there are any values then use this.- Overrides:
docsWithValue
in classValuesSource.Bytes
- Throws:
IOException
-
ordinalsValues
public abstract org.apache.lucene.index.SortedSetDocValues ordinalsValues(org.apache.lucene.index.LeafReaderContext context) throws IOException Get a view into the leaf's ordinals and theirBytesRef
values.Use
DocValuesIterator.advanceExact(int)
,SortedSetDocValues.getValueCount()
, andSortedSetDocValues.nextOrd()
to fetch the ordinals. UseSortedSetDocValues.lookupOrd(long)
to convert form the ordinal number into theBytesRef
value. Make sure tocopy
the 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 ordinal0
in the first leaf and doesn't exist in the second leaf."b"
has the ordinal1
in the first leaf and0
in the second leaf."c"
doesn't exist in the first leaf and has the ordinal1
in the second leaf. And"d"
gets the ordinal2
in both leaves.If you have to compare the ordinals of values from different segments then you'd need to somehow merge them.
globalOrdinalsValues(org.apache.lucene.index.LeafReaderContext)
provides such a merging at the cost of longer startup times when the index has been modified.- Throws:
IOException
-
globalOrdinalsValues
public abstract org.apache.lucene.index.SortedSetDocValues globalOrdinalsValues(org.apache.lucene.index.LeafReaderContext context) throws IOException Get a "global" view into the leaf's ordinals. This can require construction of fairly large set of lookups in memory so preferordinalsValues(org.apache.lucene.index.LeafReaderContext)
unless you need the global view.This functions just like
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
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.
- Throws:
IOException
-
supportsGlobalOrdinalsMapping
public boolean supportsGlobalOrdinalsMapping()Whether this values source is able to provide a mapping between global and segment ordinals, by returning the underlyingOrdinalMap
. If this method returns false, then callingglobalOrdinalsMapping(org.apache.lucene.index.LeafReaderContext)
will result in anUnsupportedOperationException
. -
hasOrdinals
public boolean hasOrdinals()Description copied from class:ValuesSource
Check if this values source supports using global and segment ordinals.If this returns
true
then it is safe to cast it toValuesSource.Bytes.WithOrdinals
.- Overrides:
hasOrdinals
in classValuesSource
-
globalOrdinalsMapping
public abstract LongUnaryOperator globalOrdinalsMapping(org.apache.lucene.index.LeafReaderContext context) throws IOException Returns 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.
- Throws:
IOException
-
globalMaxOrd
Get the maximum global ordinal. RequiresglobalOrdinalsValues(org.apache.lucene.index.LeafReaderContext)
so see the note about its performance.- Throws:
IOException
-