Interface Index (2.0.0)

public interface Index

An Index allows synchronous and asynchronous adding and deleting of Documents as well as synchronous and asynchronous searching for Documents for a given Query. The following code fragment shows how to add documents, then search the index for documents matching a query.


  // Get the SearchService for the default namespace
  SearchService searchService = SearchServiceFactory.getSearchService();
  // Get the index. If not yet created, create it.
  Index index = searchService.getIndex(
      IndexSpec.newBuilder().setIndexName("indexName"));

  // Create a document.
  Document document = Document.newBuilder()
      .setId("documentId")
      .addField(Field.newBuilder().setName("subject").setText("my first email"))
      .addField(Field.newBuilder().setName("body")
           .setHTML(some content here")
      .build();

  // Put the document.
  try {
    index.put(document);
  } catch (PutException e) {
    if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) {
      // retry putting document
    }
  }

  // Query the index.
  try {
    Results<ScoredDocument> results =
        index.search(Query.newBuilder().build("subject:first body:here"));

    // Iterate through the search results.
    for (ScoredDocument document : results) {
      // display results
    }
  } catch (SearchException e) {
    if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) {
      // retry
    }
  }
 
 

Methods

delete(Iterable<String> documentIds)

public abstract void delete(Iterable<String> documentIds)
Parameter
Name Description
documentIds Iterable<String>

delete(String[] documentIds)

public abstract void delete(String[] documentIds)

Delete documents for the given document ids from the index if they are in the index.

Parameter
Name Description
documentIds String[]

the ids of documents to delete

deleteAsync(Iterable<String> documentIds)

public abstract Future<Void> deleteAsync(Iterable<String> documentIds)
Parameter
Name Description
documentIds Iterable<String>
Returns
Type Description
Future<Void>

deleteAsync(String[] documentId)

public abstract Future<Void> deleteAsync(String[] documentId)
Parameter
Name Description
documentId String[]
Returns
Type Description
Future<Void>

deleteSchema()

public abstract void deleteSchema()

Delete the schema from the index. To fully delete an index, you must delete both the index's documents and schema. This method deletes the index's schema, which contains field names and field types of previously indexed documents.

deleteSchemaAsync()

public abstract Future<Void> deleteSchemaAsync()

See Also: #deleteSchema()

Returns
Type Description
Future<Void>

get(String documentId)

public abstract Document get(String documentId)

Gets a Document for the given document Id.

Parameter
Name Description
documentId String

the identifier for the document to retrieve

Returns
Type Description
Document

the associated Document. can be null

getName()

public abstract String getName()
Returns
Type Description
String

the name of the index

getNamespace()

public abstract String getNamespace()
Returns
Type Description
String

the namespace of the index name

getRange(GetRequest request)

public abstract GetResponse<Document> getRange(GetRequest request)

Get an index's documents, in document Id order.

Parameter
Name Description
request GetRequest

contains various options restricting which documents are returned.

Returns
Type Description
GetResponse<Document>

a GetResponse containing a list of documents from the index

getRange(GetRequest.Builder builder)

public abstract GetResponse<Document> getRange(GetRequest.Builder builder)
Parameter
Name Description
builder GetRequest.Builder
Returns
Type Description
GetResponse<Document>

getRangeAsync(GetRequest request)

public abstract Future<GetResponse<Document>> getRangeAsync(GetRequest request)
Parameter
Name Description
request GetRequest
Returns
Type Description
Future<GetResponse<Document>>

getRangeAsync(GetRequest.Builder builder)

public abstract Future<GetResponse<Document>> getRangeAsync(GetRequest.Builder builder)
Parameter
Name Description
builder GetRequest.Builder
Returns
Type Description
Future<GetResponse<Document>>

getSchema()

public abstract Schema getSchema()
Returns
Type Description
Schema

the Schema describing supported document field names and Field.FieldTypes supported for those field names. This schema will only be populated if the GetIndexesRequest#isSchemaFetched is set to true on a SearchService#getIndexes request

getStorageLimit()

public abstract long getStorageLimit()
Returns
Type Description
long

the maximum amount of storage space that the application may use in this index, expressed in bytes

getStorageUsage()

public abstract long getStorageUsage()
Returns
Type Description
long

a rough approximation of the amount of storage space currently used by this index, expressed in bytes

put(Document[] documents)

public abstract PutResponse put(Document[] documents)

Put the documents into the index, updating any document that is already present.

Parameter
Name Description
documents Document[]

the documents to put into the index

Returns
Type Description
PutResponse

an PutResponse containing the result of the put operations indicating success or failure as well as the document ids. The search service will allocate document ids for documents which have none provided

put(Document.Builder[] builders)

public abstract PutResponse put(Document.Builder[] builders)
Parameter
Name Description
builders Builder[]
Returns
Type Description
PutResponse

put(Iterable<Document> documents)

public abstract PutResponse put(Iterable<Document> documents)
Parameter
Name Description
documents Iterable<Document>
Returns
Type Description
PutResponse

putAsync(Document[] document)

public abstract Future<PutResponse> putAsync(Document[] document)
Parameter
Name Description
document Document[]
Returns
Type Description
Future<PutResponse>

putAsync(Document.Builder[] document)

public abstract Future<PutResponse> putAsync(Document.Builder[] document)
Parameter
Name Description
document Builder[]
Returns
Type Description
Future<PutResponse>

putAsync(Iterable<Document> documents)

public abstract Future<PutResponse> putAsync(Iterable<Document> documents)
Parameter
Name Description
documents Iterable<Document>
Returns
Type Description
Future<PutResponse>

search(Query query)

public abstract Results<ScoredDocument> search(Query query)

Search the index for documents matching the query. The query must specify a query string, and optionally, how many documents are requested, how the results are to be sorted, scored and which fields are to be returned.

Parameter
Name Description
query Query

the fully specified Query object

Returns
Type Description
Results<ScoredDocument>

a Results containing ScoredDocuments

search(String query)

public abstract Results<ScoredDocument> search(String query)

Search the index for documents matching the query string. See Also: #search(Query)

Parameter
Name Description
query String

the query string

Returns
Type Description
Results<ScoredDocument>

a Results containing ScoredDocuments

searchAsync(Query query)

public abstract Future<Results<ScoredDocument>> searchAsync(Query query)

See Also: #search(Query)

Parameter
Name Description
query Query
Returns
Type Description
Future<Results<ScoredDocument>>

searchAsync(String query)

public abstract Future<Results<ScoredDocument>> searchAsync(String query)

See Also: #search(String)

Parameter
Name Description
query String
Returns
Type Description
Future<Results<ScoredDocument>>