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
NameDescription
documentIdsIterable<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
NameDescription
documentIdsString[]

the ids of documents to delete

deleteAsync(Iterable<String> documentIds)

public abstract Future<Void> deleteAsync(Iterable<String> documentIds)
Parameter
NameDescription
documentIdsIterable<String>
Returns
TypeDescription
Future<Void>

deleteAsync(String[] documentId)

public abstract Future<Void> deleteAsync(String[] documentId)
Parameter
NameDescription
documentIdString[]
Returns
TypeDescription
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
TypeDescription
Future<Void>

get(String documentId)

public abstract Document get(String documentId)

Gets a Document for the given document Id.

Parameter
NameDescription
documentIdString

the identifier for the document to retrieve

Returns
TypeDescription
Document

the associated Document. can be null

getName()

public abstract String getName()
Returns
TypeDescription
String

the name of the index

getNamespace()

public abstract String getNamespace()
Returns
TypeDescription
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
NameDescription
requestGetRequest

contains various options restricting which documents are returned.

Returns
TypeDescription
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
NameDescription
builderGetRequest.Builder
Returns
TypeDescription
GetResponse<Document>

getRangeAsync(GetRequest request)

public abstract Future<GetResponse<Document>> getRangeAsync(GetRequest request)
Parameter
NameDescription
requestGetRequest
Returns
TypeDescription
Future<GetResponse<Document>>

getRangeAsync(GetRequest.Builder builder)

public abstract Future<GetResponse<Document>> getRangeAsync(GetRequest.Builder builder)
Parameter
NameDescription
builderGetRequest.Builder
Returns
TypeDescription
Future<GetResponse<Document>>

getSchema()

public abstract Schema getSchema()
Returns
TypeDescription
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
TypeDescription
long

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

getStorageUsage()

public abstract long getStorageUsage()
Returns
TypeDescription
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
NameDescription
documentsDocument[]

the documents to put into the index

Returns
TypeDescription
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
NameDescription
buildersBuilder[]
Returns
TypeDescription
PutResponse

put(Iterable<Document> documents)

public abstract PutResponse put(Iterable<Document> documents)
Parameter
NameDescription
documentsIterable<Document>
Returns
TypeDescription
PutResponse

putAsync(Document[] document)

public abstract Future<PutResponse> putAsync(Document[] document)
Parameter
NameDescription
documentDocument[]
Returns
TypeDescription
Future<PutResponse>

putAsync(Document.Builder[] document)

public abstract Future<PutResponse> putAsync(Document.Builder[] document)
Parameter
NameDescription
documentBuilder[]
Returns
TypeDescription
Future<PutResponse>

putAsync(Iterable<Document> documents)

public abstract Future<PutResponse> putAsync(Iterable<Document> documents)
Parameter
NameDescription
documentsIterable<Document>
Returns
TypeDescription
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
NameDescription
queryQuery

the fully specified Query object

Returns
TypeDescription
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
NameDescription
queryString

the query string

Returns
TypeDescription
Results<ScoredDocument>

a Results containing ScoredDocuments

searchAsync(Query query)

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

See Also: #search(Query)

Parameter
NameDescription
queryQuery
Returns
TypeDescription
Future<Results<ScoredDocument>>

searchAsync(String query)

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

See Also: #search(String)

Parameter
NameDescription
queryString
Returns
TypeDescription
Future<Results<ScoredDocument>>