org.apache.ignite.cache.query

## Class IndexQuery<K,V>

- java.lang.Object
- - org.apache.ignite.cache.query.Query<javax.cache.Cache.Entry<K,V>>
  - - org.apache.ignite.cache.query.IndexQuery<K,V>

- All Implemented Interfaces:
    Serializable

      public final class IndexQuery<K,V>
      extends Query<javax.cache.Cache.Entry<K,V>>

  Index queries work over distributed indexes and retrieve cache entries that match the specified criteria. `QueryCursor` delivers sorted cache entries by the order defined for queried index. `IndexQuery` has to be initialized with cache value class or type. The algorithm of discovering index is as follows: 1. If `idxName` is set, then use it. 2. If `idxName` is not set, then find an index that matches criteria fields. 3. If neither `idxName`, nor `setCriteria(List)` is used, then perform index scan over PK index for specified Value type. Conjuction of items in `criteria` has to represent a valid range to traverse the index tree.
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class org.apache.ignite.cache.query.Query

      `DFLT_PAGE_SIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `IndexQuery(Class<?> valCls)` Specify index with cache value class.
    `IndexQuery(Class<?> valCls, @Nullable String idxName)` Specify index with cache value class and index name.
    `IndexQuery(String valType)` Specify index with cache value type.
    `IndexQuery(String valType, @Nullable String idxName)` Specify index with cache value type and index name.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<IndexQueryCriterion>` | `getCriteria()` Index query criteria.
    `IgniteBiPredicate<K,V>` | `getFilter()` Gets remote cache entries filter.
    `String` | `getIndexName()` Index name.
    `int` | `getLimit()` Gets limit to response records count.
    `@Nullable Integer` | `getPartition()` Gets partition number over which this query should iterate.
    `String` | `getValueType()` Cache Value type.
    `IndexQuery<K,V>` | `setCriteria(IndexQueryCriterion... criteria)` Sets conjunction (AND) criteria for index query.
    `IndexQuery<K,V>` | `setCriteria(List<IndexQueryCriterion> criteria)` Sets conjunction (AND) criteria for index query.
    `IndexQuery<K,V>` | `setFilter(IgniteBiPredicate<K,V> filter)` Sets remote cache entries filter.
    `IndexQuery<K,V>` | `setLimit(int limit)` Sets limit to response records count.
    `IndexQuery<K,V>` | `setPartition(@Nullable Integer part)` Sets partition number over which this query should iterate.

    - ### Methods inherited from class org.apache.ignite.cache.query.Query

      `getPageSize, isLocal, prepare, setLocal, setPageSize, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### IndexQuery

          public IndexQuery(Class<?> valCls)

      Specify index with cache value class.
      Parameters:
        `valCls` - Cache value class.

    - #### IndexQuery

          public IndexQuery(String valType)

      Specify index with cache value type.
      Parameters:
        `valType` - Cache value type.

    - #### IndexQuery

          public IndexQuery(Class<?> valCls,
                            @Nullable
                            @Nullable String idxName)

      Specify index with cache value class and index name.
      Parameters:
        `valCls` - Cache value class.
        `idxName` - Index name.

    - #### IndexQuery

          public IndexQuery(String valType,
                            @Nullable
                            @Nullable String idxName)

      Specify index with cache value type and index name.
      Parameters:
        `valType` - Cache value type.
        `idxName` - Index name.

  - ### Method Detail

    - #### setCriteria

          public IndexQuery<K,V> setCriteria(IndexQueryCriterion... criteria)

      Sets conjunction (AND) criteria for index query.
      Parameters:
        `criteria` - Criteria to set.
      Returns:
        `this` for chaining.

    - #### setCriteria

          public IndexQuery<K,V> setCriteria(List<IndexQueryCriterion> criteria)

      Sets conjunction (AND) criteria for index query.
      Parameters:
        `criteria` - Criteria to set.
      Returns:
        `this` for chaining.

    - #### getCriteria

          public List<IndexQueryCriterion> getCriteria()

      Index query criteria.
      Returns:
        List of criteria for this index query.

    - #### getValueType

          public String getValueType()

      Cache Value type.
      Returns:
        Cache Value type.

    - #### getIndexName

          public String getIndexName()

      Index name.
      Returns:
        Index name.

    - #### getLimit

          public int getLimit()

      Gets limit to response records count.
      Returns:
        Limit value.

    - #### setLimit

          public IndexQuery<K,V> setLimit(int limit)

      Sets limit to response records count.
      Parameters:
        `limit` - POsitive limit to set.
      Returns:
        `this` For chaining.

    - #### setFilter

          public IndexQuery<K,V> setFilter(IgniteBiPredicate<K,V> filter)

      Sets remote cache entries filter.
      Parameters:
        `filter` - Predicate for remote filtering of query result cursor.
      Returns:
        `this` for chaining.

    - #### getFilter

          public IgniteBiPredicate<K,V> getFilter()

      Gets remote cache entries filter.
      Returns:
        Filter.

    - #### setPartition

          public IndexQuery<K,V> setPartition(@Nullable
                                              @Nullable Integer part)

      Sets partition number over which this query should iterate. If `null`, query will iterate over all partitions in the cache. Must be in the range [0, N) where N is partition number in the cache.
      Parameters:
        `part` - Partition number over which this query should iterate.
      Returns:
        `this` for chaining.

    - #### getPartition

          @Nullable
          public @Nullable Integer getPartition()

      Gets partition number over which this query should iterate. Will return `null` if partition was not set. In this case query will iterate over all partitions in the cache.
      Returns:
        Partition number or `null`.

${current.year} Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.16.0
Release Date | : December 15 2023