google-cloud-java icon indicating copy to clipboard operation
google-cloud-java copied to clipboard

[v1-google-cloud-discoveryengine]: Still receiving as gRpc struct even use HttpJsonTransportProvider

Open birbbie96 opened this issue 1 year ago • 2 comments

First of all, I'm very new with this service google-cloud-discoveryengine. I trying to call https://discoveryengine.googleapis.com/v1 for vertex search with client lib from google cloud and i want the result as json, btw i always receive struct which is not json response. So i go to read this documentation https://cloud.google.com/java/docs/reference/google-cloud-discoveryengine/latest/com.google.cloud.discoveryengine.v1.SearchServiceClient, they said that use
SearchServiceSettings searchServiceSettings = SearchServiceSettings.newHttpJsonBuilder().build(); but i still get struct response.

can u help me solve this problem? or tell me what i did wrong
this is my code

    SearchServiceSettings searchServiceSettings = SearchServiceSettings.newHttpJsonBuilder().build();
    try (SearchServiceClient searchServiceClient = SearchServiceClient.create(searchServiceSettings)) {
        SearchRequest request =
                SearchRequest.newBuilder()
                        .setServingConfig(
                                ServingConfigName.formatProjectLocationCollectionDataStoreServingConfigName(
                                        projectId, location, collectionId, dataStoreId, servingConfigId))
                        .setSpellCorrectionSpec(
                                SearchRequest.SpellCorrectionSpec.newBuilder()
                                        .setMode(SearchRequest.SpellCorrectionSpec.Mode.AUTO).build()
                        )
                        .setQueryExpansionSpec(
                                SearchRequest.QueryExpansionSpec.newBuilder()
                                        .setCondition(SearchRequest.QueryExpansionSpec.Condition.AUTO).build()
                        )
                        .setQuery(searchQuery)
                        .setPageSize(1)
                        .build();
        SearchServiceClient.SearchPagedResponse a =  searchServiceClient.search(request);
        SearchResponse response = a.getPage().getResponse();
        List<SearchResponse.SearchResult> results = response.getResultsList();
        SearchResponse.SearchResult res = results.getFirst();

this is some part of my response

results {
  id: "1250"
  document {
    name: "projects/272270411648/locations/global/collections/default_collection/dataStores/mordee-doctor-info-test/branches/0/documents/1250"
    id: "1250"
    struct_data {
      fields {
        key: "availableChannels"
        value {
          list_value {
            values {
              string_value: "Video"
            }
            values {
              string_value: "Voice"
            }
          }
        }
      }
      fields {
        key: "availableLanguages"
        value {
          list_value {
            values {
              string_value: "th-TH"
            }
          }
        }
      }
      fields {
        key: "certificate"
        value {
          struct_value {
            fields {
              key: "en"
              value {
                string_value: "Bachelor of Science Program in Food Technology and Nutrition, Mahasarakham University "
              }
            }
            fields {
              key: "th"
              value {
                string_value: "Master of Science Program in Food Technology, Khonkaen University "
              }
            }
          }
        }
      }

note* i try v1, v1beta, and v1alpha already

Java Version: java 22.0.1 Quarkus Version: 3.11.1

Thanks!

birbbie96 avatar Jun 15 '24 10:06 birbbie96