# Segment filter missing contacts

**URL:** <https://forum.mautic.org/t/segment-filter-missing-contacts/22438>\
**Category:** Product Support\
**Created:** [January 23, 2022, 3:32am UTC](https://forum.mautic.org/t/segment-filter-missing-contacts/22438 "2022-01-23T03:32:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![donbowman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/donbowman/32/5702_2.png) [@donbowman](https://forum.mautic.org/u/donbowman)\
**Post date:** [January 23, 2022, 3:32am UTC](https://forum.mautic.org/t/segment-filter-missing-contacts/22438/1 "2022-01-23T03:32:29Z")

</div>

**Your software**  
My Mautic version is: 4.1.1  
My PHP version is: 7.4  
My Database type and version is: tidb

**Your problem**

I have a custom field ‘industries’ on companies. It is a “select multiple” type and contains values like “Consumer Goods”, “Government”, “Utilities” etc.

If I run this sql query:

```auto
select leads.id,copper_id, email,industries from leads,companies where leads.company = companies.companyname and (industries like '%Govern%' or industries like '%Utilit%') and email is not null;

```

I get 4000 leads.

If i create a segment with a filter:

“Company industries including Government, Utiltiies” i get ~500 contacts.  
If i create a segment with a filter:  
“Company industries including Government OR Company industries including Utilities” I get ~1600 contacts.

In all cases I am missing most.

When i run

```auto
/app/bin/mautic mautic:segments:update -i 210096 -vvv -b 4000

```

i don’t see any debug or trace or verbosity.

So.  
a) how do i debug this?  
b) what is wrong?  
c) how can i work around it?

 ![2022-01-22_22-30-screenshot](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/a/a0b16a71a545a9de6137ef082ad43eff9d088402.png)

 ![2022-01-22_22-31-screenshot](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/6/656e84066ac73599296f44f63315d719a4573f6d.png)

---

<div class="post-metadata">

**Author:** ![donbowman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/donbowman/32/5702_2.png) [@donbowman](https://forum.mautic.org/u/donbowman)\
**Post date:** [January 23, 2022, 5:56pm UTC](https://forum.mautic.org/t/segment-filter-missing-contacts/22438/2 "2022-01-23T17:56:51Z")

</div>

I’ve done some more diagnostics.

It appears that, for some leads, even tho the company name is correct, they are not associated.

When i Open companies/view/####, I see ‘0 contacts’.  
When I compare the lead, i see ‘company’ field == ‘companyname’ of #####.

How is this association made? My sql query works showing the join is correct, but there must be some xref table managed by a cron?

---

<div class="post-metadata">

**Author:** ![donbowman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/donbowman/32/5702_2.png) [@donbowman](https://forum.mautic.org/u/donbowman)\
**Post date:** [January 23, 2022, 6:57pm UTC](https://forum.mautic.org/t/segment-filter-missing-contacts/22438/3 "2022-01-23T18:57:55Z")

</div>

ok i think i see the issue.

the API has a add-contact-to-company (and remove).  
when you ‘create’ a contact, if the company name matches, it gets added.  
if you update the company name, it doesn’t get added.

there is no API call to see which companies you are part of , meaning we cannot reconcile via API properly.

so i think there are a couple of flaws here:

- update contact, change company name → doesn’t associate
- no means of finding which companies a contact is associated with (can’t reconcile manually)

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 23, 2022, 6:57pm UTC](https://forum.mautic.org/t/segment-filter-missing-contacts/22438/4 "2022-01-23T18:57:58Z")

</div>

Hi, when you uploaded the original list - did you use company name as a key?  
The person who has company name as primary company will be connected to the company with THAT name. And this company should have the rest of the info.

---

<div class="post-metadata">

**Author:** ![donbowman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/donbowman/32/5702_2.png) [@donbowman](https://forum.mautic.org/u/donbowman)\
**Post date:** [January 23, 2022, 7:15pm UTC](https://forum.mautic.org/t/segment-filter-missing-contacts/22438/5 "2022-01-23T19:15:05Z")

</div>

a ‘fix’:  
begin;  
delete from companies\_leads;  
insert into companies\_leads select companies.id as company\_id, leads.id as lead\_id, now() as date\_added, 1 as is\_primary from leads, companies where leads.company = companies.companyname;  
commit;

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 24, 2022, 10:21am UTC](https://forum.mautic.org/t/segment-filter-missing-contacts/22438/6 "2022-01-24T10:21:15Z")

</div>

Can you explain why this solves the sutiation?  
Thank you.

---

<div class="post-metadata">

**Author:** ![donbowman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/donbowman/32/5702_2.png) [@donbowman](https://forum.mautic.org/u/donbowman)\
**Post date:** [January 24, 2022, 3:28pm UTC](https://forum.mautic.org/t/segment-filter-missing-contacts/22438/7 "2022-01-24T15:28:56Z")

</div>

I am bidirectionally syncing my CRM (copper).

When i ‘create’ a user in mautic, i post something like:  
companies: companyname, email\_domain  
leads:  
First,Last,email,company

this associates the user to the company.

Later, my team correct ‘Company’ in Copper. Maybe the name was mispelled.  
The sync will now update mautic company, and then update the lead, posting it with the corrected company name. This does not associate the user to the company.

Alternatively, i might create the user and then create the company. This does not associate the user.

it seems the user is associated only once, on create, if the company exists w/ match.

Failing that, once must manually associate.  
But the api seems to give no way to see who is associated.

the above SQL is a cheat-mode, it takes the company field from the lead, assocaites as the sole company.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 24, 2022, 4:10pm UTC](https://forum.mautic.org/t/segment-filter-missing-contacts/22438/8 "2022-01-24T16:10:42Z")

</div>

Okay cool thank you! One more question: did you push the contact in via API or another method?

---

<div class="post-metadata">

**Author:** ![donbowman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/donbowman/32/5702_2.png) [@donbowman](https://forum.mautic.org/u/donbowman)\
**Post date:** [January 24, 2022, 6:15pm UTC](https://forum.mautic.org/t/segment-filter-missing-contacts/22438/9 "2022-01-24T18:15:30Z")

</div>

its all via api
