Skip to content

Commit

Permalink
Merge pull request #44 from nyaruka/group_ids
Browse files Browse the repository at this point in the history
Add `group_ids` field to replace `groups`
  • Loading branch information
rowanseymour authored Apr 4, 2022
2 parents fe5e3df + 426d91d commit ee13951
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
3 changes: 3 additions & 0 deletions indexers/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 18 additions & 15 deletions indexers/contacts.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -144,10 +161,7 @@
"groups": {
"type": "keyword"
},
"uuid": {
"type": "keyword"
},
"status": {
"group_ids": {
"type": "keyword"
},
"flow": {
Expand Down Expand Up @@ -177,17 +191,6 @@
},
"last_seen_on": {
"type": "date"
},
"name": {
"type": "text",
"analyzer": "prefix",
"search_analyzer": "name_search",
"fields": {
"keyword": {
"type": "keyword",
"normalizer": "lowercase"
}
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions indexers/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ee13951

Please sign in to comment.