Skip to content

Commit 426d91d

Browse files
committed
Add group_ids field to replace groups
1 parent fe5e3df commit 426d91d

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

indexers/contacts.go

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ SELECT org_id, id, modified_on, is_active, row_to_json(t) FROM (
145145
WHERE contact_id = contacts_contact.id AND contacts_contactgroup_contacts.contactgroup_id = contacts_contactgroup.id
146146
) g
147147
) AS groups,
148+
(
149+
SELECT array_to_json(array_agg(gc.contactgroup_id)) FROM contacts_contactgroup_contacts gc WHERE gc.contact_id = contacts_contact.id
150+
) AS group_ids,
148151
(
149152
SELECT f.uuid FROM flows_flow f WHERE f.id = contacts_contact.current_flow_id
150153
) AS flow,

indexers/contacts.settings.json

+18-15
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@
7979
"required": true
8080
},
8181
"properties": {
82+
"uuid": {
83+
"type": "keyword"
84+
},
85+
"name": {
86+
"type": "text",
87+
"analyzer": "prefix",
88+
"search_analyzer": "name_search",
89+
"fields": {
90+
"keyword": {
91+
"type": "keyword",
92+
"normalizer": "lowercase"
93+
}
94+
}
95+
},
96+
"status": {
97+
"type": "keyword"
98+
},
8299
"fields": {
83100
"type": "nested",
84101
"properties": {
@@ -144,10 +161,7 @@
144161
"groups": {
145162
"type": "keyword"
146163
},
147-
"uuid": {
148-
"type": "keyword"
149-
},
150-
"status": {
164+
"group_ids": {
151165
"type": "keyword"
152166
},
153167
"flow": {
@@ -177,17 +191,6 @@
177191
},
178192
"last_seen_on": {
179193
"type": "date"
180-
},
181-
"name": {
182-
"type": "text",
183-
"analyzer": "prefix",
184-
"search_analyzer": "name_search",
185-
"fields": {
186-
"keyword": {
187-
"type": "keyword",
188-
"normalizer": "lowercase"
189-
}
190-
}
191194
}
192195
}
193196
}

indexers/contacts_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ var contactQueryTests = []struct {
183183
{elastic.NewMatchQuery("groups", "4ea0f313-2f62-4e57-bdf0-232b5191dd57"), []int64{1}},
184184
{elastic.NewMatchQuery("groups", "529bac39-550a-4d6f-817c-1833f3449007"), []int64{1, 2}},
185185
{elastic.NewMatchQuery("groups", "4c016340-468d-4675-a974-15cb7a45a5ab"), []int64{}},
186+
{elastic.NewMatchQuery("group_ids", 1), []int64{1}},
187+
{elastic.NewMatchQuery("group_ids", 4), []int64{1, 2}},
188+
{elastic.NewMatchQuery("group_ids", 2), []int64{}},
186189
}
187190

188191
func TestContacts(t *testing.T) {

0 commit comments

Comments
 (0)