Stay organized with collections
Save and categorize content based on your preferences.
publicinterfaceIndex
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 namespaceSearchServicesearchService=SearchServiceFactory.getSearchService();// Get the index. If not yet created, create it.Indexindex=searchService.getIndex(IndexSpec.newBuilder().setIndexName("indexName"));// Create a document.Documentdocument=Document.newBuilder().setId("documentId").addField(Field.newBuilder().setName("subject").setText("my first email")).addField(Field.newBuilder().setName("body").setHTML(somecontenthere") .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:firstbody:here")); // Iterate through the search results. for (ScoredDocument document : results) { // display results } } catch (SearchException e) { if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) { // retry } }
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.
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
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-19 UTC."],[],[]]