Package 

Class AsyncIndexRepository


  • 
    public final class AsyncIndexRepository<T extends Object>
    
                        

    Repository abstraction that allows you to work with indices asynchronously via co-routines.

    You should create a Repository for each index you work with. You need to specify a ModelReaderAndWriter for serialization and deserialization.

    • Constructor Detail

      • AsyncIndexRepository

        AsyncIndexRepository(String indexName, RestHighLevelClient client, ModelReaderAndWriter<T> modelReaderAndWriter, Boolean refreshAllowed, String type, String indexWriteAlias, String indexReadAlias, FetchSourceContext fetchSourceContext, RequestOptions defaultRequestOptions)
        Parameters:
        indexName - name of the index
        modelReaderAndWriter - serialization of your model class.
        refreshAllowed - if false, the refresh will throw an exception.
        type - the type of the documents in the index; defaults to null.
        indexWriteAlias - Alias used for write operations.
        indexReadAlias - Alias used for read operations.
        fetchSourceContext - if not null, will be passed to Get and Search requests.
        defaultRequestOptions - passed on all API calls.
    • Method Detail

      • createIndex

         final Unit createIndex(RequestOptions requestOptions, ActiveShardCount waitForActiveShards, SuspendFunction1<CreateIndexRequest, Unit> block)

        Create the index.

        Parameters:
        block - customize the CreateIndexRequest
        {
          source(settings, XContentType.JSON)
        }
      • deleteIndex

         final Boolean deleteIndex(RequestOptions requestOptions)

        Delete the index associated with the repository. Returns true if successful or false if the index did not exist

      • currentAliases

         final Set<AliasMetadata> currentAliases(RequestOptions requestOptions)

        Returns a set of the current AliasMetaData associated with the indexName.

      • index

         final Unit index(String id, T obj, Boolean create, Long seqNo, Long primaryTerm, RequestOptions requestOptions)

        Index a document with a given id. Set create to false for upserts. Otherwise it fails on creating documents that already exist.

        You can optionally specify seqNo and primaryTerm to implement optimistic locking. However, you should use update which does this for you.

      • update

         final Unit update(String id, Integer maxUpdateTries, RequestOptions requestOptions, SuspendFunction1<T, T> transformFunction)

        Updates document identified by id by fetching the current version with get and then applying the transformFunction to produce the updated version.

        if maxUpdateTries 0, it will deal with version conflicts (e.g. due to concurrent updates) by retrying with the latest version.

      • delete

         final Unit delete(String id, RequestOptions requestOptions)

        Deletes the object object identified by id.

      • get

         final T get(String id)

        Returns the deserialized T for the document identified by id.

      • getWithGetResponse

         final Pair<T, GetResponse> getWithGetResponse(String id, RequestOptions requestOptions)

        Returns a Pair of the deserialized T and the GetResponse with all the relevant metadata.

      • refresh

         final Unit refresh()

        Call the refresh API on elasticsearch. You should not use this other than in tests. E.g. when testing search queries, you often want to refresh after indexing before calling search

        Throws UnsupportedOperationException if you do not explicitly opt in to this by setting the refreshAllowed to true when creating the repository.

      • search

         final AsyncSearchResults<T> search(Boolean scrolling, Long scrollTtlInMinutes, RequestOptions requestOptions, Function1<SearchRequest, Unit> block)

        Perform an asynchronous search against your index. Works similar to the synchronous version, except it returns AsyncSearchResults with a flow of responses that get mapped to T.

        Similar to the synchronous version, it supports scrolling.

      • count

         final Long count(RequestOptions requestOptions, Function1<CountRequest, Unit> block)
      • getClient

         final RestHighLevelClient getClient()