0
votes

I have found some similary questions here ,but no solid answer.

I see some googler suggest that

You can effectively delete an index by first using index.delete() to remove all of the documents from an index, and then using index.delete_schema() to remove the type mappings from the index 1.

Unfortunately, golang sdk does not have "index.delete_schema()" api. I can only delete document one by one by getting itemId list from index. And We got a surprisely billing status in dashboard:

Resource                       Usage           Billable         Price              Cost
Search API Simple Searches  214,748.49 10K Ops  214,748.39  $0.625 / 10K Ops    $134,217.74 

Can someone tell me how to effectively delete Google App engine Search API index wihout cost so much ?

3

3 Answers

1
votes

Unfortunately there is no simple operation that allows you to delete an entire large search index without incurring substantial cost, short of deleting the entire app (which, actually, could be an effective approach in certain circumstances).

0
votes

The short answer is NO.

There is no pefectly efficient way with GCP to drop full search index in one go. The only efficient way they themselves suggest in thier "Best Practices" is to delete in bactches of 200 documents per index.delete() method call (in Java and Python app engine sdk).

To add to the disappointment, GO SDK even does not support this too and allows only one doc deletion per call. What a miserable support from GCP!

So if your indexes have grown to some good GBs, you are forced to consume your dollars and days or better say cleanup the mess, left by GCP, at your own cost. Mind it, it costs you a lot with giant index>10GB.

Now, how to do it in GO runtime.

Donot do it with GO runtime

Better, write a micro-service in Java or Python under the same projectId and use these runtimes with thier SDKs/Client Libraries to delete index the only efficient way(200 per call), GCP offers. So very very limited and essentially cost bearing solution with app engine. Have to live with it, dear :)

PS. I have created an bug/issue a year back regarding the same. No actions takent yet :)

-1
votes

As you mentioned, deleting an index is only available for Java 8 at the moment.

Since you're using GO, currently there is no possibility to delete an index, but you can remove documents that are part of it to reduce the cost

To delete documents from an index you can follow this example here

func deleteHandler(w http.ResponseWriter, r *http.Request) {
        ctx := appengine.NewContext(r)

        index, err := search.Open("users")
        if err != nil {
                http.Error(w, err.Error(), http.StatusInternalServerError)
                return
        }

        id := "PA6-5000"
        err = index.Delete(ctx, id)
        if err != nil {
                http.Error(w, err.Error(), http.StatusInternalServerError)
                return
        }
        fmt.Fprint(w, "Deleted document: ", id)
}