From 7fc297ccd358d59b0cf6bb5bc69329f99b8a321d Mon Sep 17 00:00:00 2001 From: Nic Pottier Date: Tue, 1 Sep 2020 10:59:15 -0700 Subject: [PATCH] add status field to index for querying --- indexer.go | 5 ++++- indexer_test.go | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/indexer.go b/indexer.go index e19af69..f73e717 100644 --- a/indexer.go +++ b/indexer.go @@ -383,7 +383,7 @@ func MapIndexAlias(elasticURL string, alias string, newIndex string) error { const contactQuery = ` SELECT org_id, id, modified_on, is_active, row_to_json(t) FROM ( SELECT - id, org_id, uuid, name, language, status = 'S' AS is_stopped, status = 'B' AS is_blocked, is_active, created_on, modified_on, last_seen_on, + id, org_id, uuid, name, language, status, status = 'S' AS is_stopped, status = 'B' AS is_blocked, is_active, created_on, modified_on, last_seen_on, EXTRACT(EPOCH FROM modified_on) * 1000000 as modified_on_mu, ( SELECT array_to_json(array_agg(row_to_json(u))) @@ -591,6 +591,9 @@ const indexSettings = ` "uuid": { "type": "keyword" }, + "status": { + "type": "keyword" + }, "language": { "type": "keyword", "normalizer": "lowercase" diff --git a/indexer_test.go b/indexer_test.go index 6afc549..67a830b 100644 --- a/indexer_test.go +++ b/indexer_test.go @@ -95,6 +95,9 @@ func TestIndexing(t *testing.T) { assertQuery(t, client, physicalName, elastic.NewMatchQuery("is_blocked", "true"), []int64{3}) assertQuery(t, client, physicalName, elastic.NewMatchQuery("is_stopped", "true"), []int64{2}) + assertQuery(t, client, physicalName, elastic.NewMatchQuery("status", "B"), []int64{3}) + assertQuery(t, client, physicalName, elastic.NewMatchQuery("status", "S"), []int64{2}) + assertQuery(t, client, physicalName, elastic.NewMatchQuery("org_id", "1"), []int64{1, 2, 3, 4}) // created_on range query