Stay organized with collections
Save and categorize content based on your preferences.
publicinterfaceSearchService
The SearchService is used to get available indexes, which can be
queried about their metadata or have index/delete/search operations
performed on them. For example:
Gets the indexes specified. The following code fragment shows how
to get the schemas of each available Index.
// Get the SearchService for the default namespaceSearchServicesearchService=SearchServiceFactory.newSearchService();// Get the first page of indexes available and retrieve schemasGetResponse<Index>response=searchService.getIndexes(GetIndexesRequest.newBuilder().setSchemaFetched(true).build());// List out elements of Schemafor(Indexindex:response){Stringname=index.getName();Schemaschema=index.getSchema();for(StringfieldName:schema.getFieldNames()){List<FieldType>typesForField=schema.getFieldTypes(fieldName);}}
a Future that will allow getting a
GetResponse<Index> containing a list of existing indexes
getNamespace()
publicabstractStringgetNamespace()
Returns the namespace associated with this search service. Each
service instance is assigned one namespace and all operations,
such as listing documents, indexes inherit it. Also, when you
get an index, the namespace of this service is passed to the
returned index.
[[["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 2025-09-03 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eSearchService\u003c/code\u003e interface allows users to retrieve available indexes, query their metadata, and perform index/delete/search operations.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eSearchService\u003c/code\u003e can also be used to create new indexes by specifying the index details using \u003ccode\u003eIndexSpec\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetIndexes\u003c/code\u003e methods, available in both synchronous and asynchronous forms, retrieve a list of existing indexes based on a \u003ccode\u003eGetIndexesRequest\u003c/code\u003e or a \u003ccode\u003eGetIndexesRequest.Builder\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eEach instance of \u003ccode\u003eSearchService\u003c/code\u003e is linked to a specific namespace, which applies to all its operations and any indexes it provides.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetIndex\u003c/code\u003e methods, available with either \u003ccode\u003eIndexSpec\u003c/code\u003e or \u003ccode\u003eIndexSpec.Builder\u003c/code\u003e, are used to retrieve an \u003ccode\u003eIndex\u003c/code\u003e instance matching the provided specification.\u003c/p\u003e\n"]]],[],null,["# Interface SearchService (2.0.0)\n\n public interface SearchService\n\nThe SearchService is used to get available indexes, which can be\nqueried about their metadata or have index/delete/search operations\nperformed on them. For example: \n\n\n SearchService searchService = SearchServiceFactory.getSearchService();\n GetResponse\u003cIndex\u003e response = searchService.getIndexes(\n GetIndexesRequest.newBuilder());\n for (Index index : response) {\n index.getName();\n index.getNamespace();\n index.search(\"query\");\n }\n \nSearchService is also responsible for creating new indexes. For\nexample: \n\n\n SearchService searchService = SearchServiceFactory.getSearchService();\n Index index = searchService.getIndex(IndexSpec.newBuilder().setName(\"myindex\"));\n \nMethods\n-------\n\n### getIndex(IndexSpec spec)\n\n public abstract Index getIndex(IndexSpec spec)\n\nReturns an instance of [Index](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Index) corresponding to the provided\nspecification.\n\n### getIndex(IndexSpec.Builder builder)\n\n public abstract Index getIndex(IndexSpec.Builder builder)\n\nReturns an instance of [Index](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Index) corresponding to the\nspecification built from the given `builder`.\n\n### getIndexes(GetIndexesRequest request)\n\n public abstract GetResponse\u003cIndex\u003e getIndexes(GetIndexesRequest request)\n\nGets the indexes specified. The following code fragment shows how\nto get the schemas of each available [Index](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Index). \n\n\n // Get the SearchService for the default namespace\n SearchService searchService = SearchServiceFactory.newSearchService();\n\n // Get the first page of indexes available and retrieve schemas\n GetResponse\u003cIndex\u003e response = searchService.getIndexes(\n GetIndexesRequest.newBuilder().setSchemaFetched(true).build());\n\n // List out elements of Schema\n for (Index index : response) {\n String name = index.getName();\n Schema schema = index.getSchema();\n for (String fieldName : schema.getFieldNames()) {\n List\u003cFieldType\u003e typesForField = schema.getFieldTypes(fieldName);\n }\n }\n \n### getIndexes(GetIndexesRequest.Builder builder)\n\n public abstract GetResponse\u003cIndex\u003e getIndexes(GetIndexesRequest.Builder builder)\n\nGets the indexes specified in the request built from the `builder`.\n\n### getIndexesAsync(GetIndexesRequest request)\n\n public abstract Future\u003cGetResponse\u003cIndex\u003e\u003e getIndexesAsync(GetIndexesRequest request)\n\nGets the indexes requested asynchronously.\n\n### getIndexesAsync(GetIndexesRequest.Builder builder)\n\n public abstract Future\u003cGetResponse\u003cIndex\u003e\u003e getIndexesAsync(GetIndexesRequest.Builder builder)\n\nGets the indexes asynchronously for those specified in the request built from\nthe `builder`.\n\n### getNamespace()\n\n public abstract String getNamespace()\n\nReturns the namespace associated with this search service. Each\nservice instance is assigned one namespace and all operations,\nsuch as listing documents, indexes inherit it. Also, when you\nget an index, the namespace of this service is passed to the\nreturned index."]]