From 426d91d991603e4748538beaca56d16cb1e28565 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 4 Apr 2022 13:20:06 -0500 Subject: [PATCH] Add group_ids field to replace groups --- indexers/contacts.go | 3 +++ indexers/contacts.settings.json | 33 ++++++++++++++++++--------------- indexers/contacts_test.go | 3 +++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/indexers/contacts.go b/indexers/contacts.go index c6f2d08..c9ea627 100644 --- a/indexers/contacts.go +++ b/indexers/contacts.go @@ -145,6 +145,9 @@ SELECT org_id, id, modified_on, is_active, row_to_json(t) FROM ( WHERE contact_id = contacts_contact.id AND contacts_contactgroup_contacts.contactgroup_id = contacts_contactgroup.id ) g ) AS groups, + ( + SELECT array_to_json(array_agg(gc.contactgroup_id)) FROM contacts_contactgroup_contacts gc WHERE gc.contact_id = contacts_contact.id + ) AS group_ids, ( SELECT f.uuid FROM flows_flow f WHERE f.id = contacts_contact.current_flow_id ) AS flow, diff --git a/indexers/contacts.settings.json b/indexers/contacts.settings.json index 7a76a84..2dcfdd7 100644 --- a/indexers/contacts.settings.json +++ b/indexers/contacts.settings.json @@ -79,6 +79,23 @@ "required": true }, "properties": { + "uuid": { + "type": "keyword" + }, + "name": { + "type": "text", + "analyzer": "prefix", + "search_analyzer": "name_search", + "fields": { + "keyword": { + "type": "keyword", + "normalizer": "lowercase" + } + } + }, + "status": { + "type": "keyword" + }, "fields": { "type": "nested", "properties": { @@ -144,10 +161,7 @@ "groups": { "type": "keyword" }, - "uuid": { - "type": "keyword" - }, - "status": { + "group_ids": { "type": "keyword" }, "flow": { @@ -177,17 +191,6 @@ }, "last_seen_on": { "type": "date" - }, - "name": { - "type": "text", - "analyzer": "prefix", - "search_analyzer": "name_search", - "fields": { - "keyword": { - "type": "keyword", - "normalizer": "lowercase" - } - } } } } diff --git a/indexers/contacts_test.go b/indexers/contacts_test.go index 071b9af..2491d38 100644 --- a/indexers/contacts_test.go +++ b/indexers/contacts_test.go @@ -183,6 +183,9 @@ var contactQueryTests = []struct { {elastic.NewMatchQuery("groups", "4ea0f313-2f62-4e57-bdf0-232b5191dd57"), []int64{1}}, {elastic.NewMatchQuery("groups", "529bac39-550a-4d6f-817c-1833f3449007"), []int64{1, 2}}, {elastic.NewMatchQuery("groups", "4c016340-468d-4675-a974-15cb7a45a5ab"), []int64{}}, + {elastic.NewMatchQuery("group_ids", 1), []int64{1}}, + {elastic.NewMatchQuery("group_ids", 4), []int64{1, 2}}, + {elastic.NewMatchQuery("group_ids", 2), []int64{}}, } func TestContacts(t *testing.T) {