# Problem sorting companies with search function

**URL:** <https://community.hubspot.com/t/problem-sorting-companies-with-search-function/100612>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [February 21, 2024, 6:47am UTC](https://community.hubspot.com/t/problem-sorting-companies-with-search-function/100612 "2024-02-21T06:47:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JGarcia5\_1](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@JGarcia5\_1](https://community.hubspot.com/u/JGarcia5_1)\
**Post date:** [February 21, 2024, 6:47am UTC](https://community.hubspot.com/t/problem-sorting-companies-with-search-function/100612/1 "2024-02-21T06:47:12Z")

</div>

Hi guys!  
During the last week I am having problems with the API when I try to get the companies.  
I have built an incremental pipeline with python API, searching only the companies with the lastmodifieddate greater than my current one storaged in my database.Once a week we make a total load and the last Sunday we realized that we have much less records. Testing the code and reviewing the outputs we saw that the filters are not working well for companies.We have a search by lastmodifieddate order by lastmodifieddate and the results are usually ordered but in some outputs we have a recent value with the current date and after that record, everything continues normal.Example:Record1 → 2022-01-01 15:40  
Record2 → 2022-01-01 18:40  
Record3 → 2022-01-01 21:40  
Record4 → 2024-02-21 10:40  
Record5 → 2022-01-01 23:40  
Record6 → 2022-01-02 00:40It is only happening with Companies. With other objects like Tickets, contacts or Deals it works perfectly.It is a function code example:

```lia-code-sample
public_object_search_request = (
 self.hubspot_crm_mod.PublicObjectSearchRequest(
 properties=self.properties,
 limit=self.page_size,
 filter_groups=filter_groups,
 sorts=[
 {
 "propertyName": self.internal_id,
 "direction": "ASCENDING",
 }
 ],
 )
 )

```

It looks like sort function is not working properly to companies.  
Someone has idea if there is a new bug or something?  
Thanks for your attention!

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [February 22, 2024, 6:38pm UTC](https://community.hubspot.com/t/problem-sorting-companies-with-search-function/100612/2 "2024-02-22T18:38:49Z")

</div>

Hey, [@JGarcía5](https://community.hubspot.com/t5/user/viewprofilepage/user-id/713836) 👋 Thanks for flagging this. Can you confirm the issue is still occurring? If so, we can try to set up a quick test on my end and then get this to my internal resources.

Talk soon! — Jaycee

---

<div class="post-metadata">

**Author:** ![JGarcia5\_1](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@JGarcia5\_1](https://community.hubspot.com/u/JGarcia5_1)\
**Post date:** [February 23, 2024, 6:44am UTC](https://community.hubspot.com/t/problem-sorting-companies-with-search-function/100612/3 "2024-02-23T06:44:31Z")

</div>

Hi [@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074)! Thanks for your attention.  
Yes, we still have the issue. When we search and sort, there are some records not correctly sorted.  
Regards!

---

<div class="post-metadata">

**Author:** ![Getint](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@Getint](https://community.hubspot.com/u/Getint)\
**Post date:** [August 12, 2024, 2:46pm UTC](https://community.hubspot.com/t/problem-sorting-companies-with-search-function/100612/4 "2024-08-12T14:46:38Z")

</div>

Hi

Any solution for this ? We are also affected ?

---

<div class="post-metadata">

**Author:** ![Syncari](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/syncari/32/98942_2.png) [@Syncari](https://community.hubspot.com/u/Syncari)\
**Post date:** [January 30, 2025, 1:49am UTC](https://community.hubspot.com/t/problem-sorting-companies-with-search-function/100612/5 "2025-01-30T01:49:39Z")

</div>

It appears that the search API goes off of a secondary index, and the lastmodified timestamps are often not correctly refreshed. So you will see such out of order records when searching not just companies, but pretty much any object. We have the same problem with Contacts.

We are trying to workaround the issue by applying some statistical measures to outliers, and excluding them from pagination logic.
