Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete indexed documents instead of the index itself #79

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,18 @@ func Runtime() (context.Context, *runtime.Runtime) {
return context.Background(), rt
}

// reindexes data changes to Elastic
func ReindexElastic(ctx context.Context) {
// ReindexElastic updates elastic indexing
func ReindexElastic(ctx context.Context) (int, int) {
db := getDB()
es := getES()

contactsIndexer := indexers.NewContactIndexer(elasticURL, elasticContactsIndex, 1, 1, 100)
contactsIndexer.Index(db.DB, false, false)

es.Refresh(elasticContactsIndex).Do(ctx)

s := contactsIndexer.Stats()
return int(s.Indexed), int(s.Deleted)
}

// returns an open test database pool
Expand Down Expand Up @@ -203,26 +206,27 @@ func resetStorage() {
must(os.RemoveAll(SessionStorageDir))
}

// clears indexed data in Elastic
func resetElastic(ctx context.Context) {
// reset indexed data in Elastic
func resetElastic(ctx context.Context) (int, int) {
es := getES()

exists, err := es.IndexExists(elasticContactsIndex).Do(ctx)
noError(err)

numDeleted := 0

if exists {
// get any indexes for the contacts alias
ar, err := es.Aliases().Index(elasticContactsIndex).Do(ctx)
_, err = es.Refresh(elasticContactsIndex).Do(ctx)
noError(err)

// and delete them
for _, index := range ar.IndicesByAlias(elasticContactsIndex) {
_, err := es.DeleteIndex(index).Do(ctx)
noError(err)
}
resp, err := es.DeleteByQuery(elasticContactsIndex).Refresh("true").Routing("1", "2").Query(elastic.NewMatchAllQuery()).Do(ctx)
noError(err)

numDeleted = int(resp.Deleted)
}

ReindexElastic(ctx)
numIndexed, _ := ReindexElastic(ctx)
return numIndexed, numDeleted
}

var sqlResetTestData = `
Expand Down