Elastic Search Results Object has unexpected side effects #4628

Open
opened 2026-02-20 16:20:53 -05:00 by deekerman · 0 comments
Owner

Originally created by @JimMackin on GitHub (Oct 7, 2021).

Issue

lib/Search/SearchResults.php:getHitsAsBeans() loops around the results of the Global Search and converts the results to beans. If it finds a hit that isn't a valid bean however it attempts to reindex Elastic search. There's a few issues with this:

  • SearchResults is, presumably, a generic results object - we shouldn't assume Elastic Search here. At the least we should use some kind of dependency injection and/or subclasses.
  • This reindex can take a long time. This means that if a bean is removed and the logic hook to update the index doesn't trigger then searches that include this bean will be slow or timeout - especially with larger datasets.
  • The reindex doesn't actually update the index to remove the missing bean so this doesn't even fix the problem. The code then throws an exception anyway. Actually no longer sure if this is correct. If the reindex is successful it should remove the record in the index provided it's been modified recently.

Expected Behavior

Searching should be quick and free from side effects.

Actual Behavior

Searching may trigger a reindex which often means the search doesn't finish

Possible Fix

Adding a continue statement for missing beans is probably a good, quick fix, it's not it's responsibility to maintain the index. If it is felt that searches should alter the index then a more appropriate class should send a request to elastic search marking that bean as removed.

Steps to Reproduce

  1. On an instance with Elastic Search ensure that the DB is at least partially indexed
  2. Remove a bean from the DB
  3. Perform a search that would include that bean
  4. The search will timeout or fail

Context

Trying to search a DB of ~4 million contacts fails on live.

Your Environment

  • SuiteCRM Version used: 7.11.22
  • Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): Firefox 93
  • Environment name and version (e.g. MySQL, PHP 7): MySQL, PHP 7.4
  • Operating System and version (e.g Ubuntu 16.04): Ubuntu 18.04
Originally created by @JimMackin on GitHub (Oct 7, 2021). <!--- Provide a general summary of the issue in the **Title** above --> <!--- Before you open an issue, please check if a similar issue already exists or has been closed before. ---> <!--- If you have discovered a security risk please report it by emailing security@suitecrm.com. This will be delivered to the product team who handle security issues. Please don't disclose security bugs publicly until they have been handled by the security team. ---> #### Issue <!--- Provide a more detailed introduction to the issue itself, and why you consider it to be a bug --> <!--- Ensure that all code ``` is surrounded ``` by triple back quotes. This can also be done over multiple lines --> `lib/Search/SearchResults.php:getHitsAsBeans()` loops around the results of the Global Search and converts the results to beans. If it finds a hit that isn't a valid bean however it attempts to reindex Elastic search. There's a few issues with this: - SearchResults is, presumably, a generic results object - we shouldn't assume Elastic Search here. At the least we should use some kind of dependency injection and/or subclasses. - This reindex can take a long time. This means that if a bean is removed and the logic hook to update the index doesn't trigger then searches that include this bean will be slow or timeout - especially with larger datasets. - ~The reindex doesn't actually update the index to remove the missing bean so this doesn't even fix the problem. The code then throws an exception anyway.~ Actually no longer sure if this is correct. If the reindex is successful it should remove the record in the index provided it's been modified recently. #### Expected Behavior <!--- Tell us what should happen --> Searching should be quick and free from side effects. #### Actual Behavior <!--- Tell us what happens instead --> <!--- Also please check relevant logs (suitecrm.log, php error.log etc.) --> Searching may trigger a reindex which often means the search doesn't finish #### Possible Fix <!--- Not obligatory, but suggest a fix or reason for the bug --> Adding a continue statement for missing beans is probably a good, quick fix, it's not it's responsibility to maintain the index. If it is felt that searches should alter the index then a more appropriate class should send a request to elastic search marking that bean as removed. #### Steps to Reproduce <!--- Provide a link to a live example, or an unambiguous set of steps to --> <!--- reproduce this bug include code to reproduce, if relevant --> 1. On an instance with Elastic Search ensure that the DB is at least partially indexed 2. Remove a bean from the DB 3. Perform a search that would include that bean 4. The search will timeout or fail #### Context <!--- How has this bug affected you? What were you trying to accomplish? --> <!--- If you feel this should be a low/medium/high priority then please state so --> Trying to search a DB of ~4 million contacts fails on live. #### Your Environment <!--- Include as many relevant details about the environment you experienced the bug in --> * SuiteCRM Version used: 7.11.22 * Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): Firefox 93 * Environment name and version (e.g. MySQL, PHP 7): MySQL, PHP 7.4 * Operating System and version (e.g Ubuntu 16.04): Ubuntu 18.04
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#4628
No description provided.