Home › Forums › Calendar Products › Events Calendar PRO › Looking at ElasticSearch / ElasticPress to fix slow queries/timeouts/502s
- This topic has 4 replies, 4 voices, and was last updated 9 years, 2 months ago by
Jen Russo.
-
AuthorPosts
-
January 13, 2017 at 3:26 pm #1218430
Jen Russo
ParticipantWe’ve long had problem with large number of recurring events bringing things to a crawl and I (Jon Brown, not Jen) am again trying to find a scalable solution…
Has anyone setup ElasticSearch w/ ElasticPress to handle The Event Calendars’ ugly queries against EventStart and EventEnd?
Setting up ElasticSearch / ElasticPress is trivial, done that several times… integrating with TEC is the question here.
I’m specifically concerned by TEC’s Tribe__Events__Query class which is a beast and getting it to use ElasticPress for all it’s queries? ElasticPress has near complete coverage for WP_Query, but I have no idea how it line up with Tribe__Events__Query.
FWIW, I tried an initial stab at. ElasticPress is up and working fine for search, but I couldn’t get it work for regular tribe_events queries reliably.
This (crude code, that ended up not working anyway) was what I was trying:
function mt_elasticsearch_tribe_events_query($query) { if ( ( $query->query['post_type'] == 'tribe_events' ) ) { $query->set('ep_integrate', true); } } add_action('pre_get_posts', 'mt_elasticsearch_tribe_events_query');Any help/guidance would be appreciated at this point.
Thanks,
Jon Brown
9seedsJanuary 13, 2017 at 4:53 pm #1218477Jen Russo
ParticipantQuick note: I did figure out ElasticPress doesn’t index protected (underscore prefixed) fields… so I added this:
function mt_elasticpress_whitelist_meta_keys( $meta, $post ) { return array_unique( array_merge( $meta, array( '_EventOrigin', '_EventAuditTrail', '_EventShowMapLink', '_EventShowMap', '_EventStartDate', '_EventEndDate', '_EventDuration', '_EventCurrencySymbol', '_EventCurrencyPosition', '_EventRecurrence', '_EventStartDateUTC', '_EventEndDateUTC', '_EventTimezone', '_EventTimezoneAbbr', '_EventOrganizerID', '_EventAllDay', '_EventNextPendingRecurrence', '_EventVenueID', '_EventCost', ) ) ); } add_filter( 'ep_prepare_meta_allowed_protected_keys', 'mt_elasticpress_whitelist_meta_keys', 10, 2 );and now it’s index those… however it’s returning ALL occurences of a recurring event on a single event page (looping through them all rather than just the current event)
January 16, 2017 at 5:18 pm #1219347George
ParticipantHey @Mauitime,
Thanks for reaching out! This is an interesting set of questions. We unfortunately cannot help with custom coding or with questions related to extending the functionality of our plugins; read more about these policies here ? https://theeventscalendar.com/knowledgebase/what-support-is-provided-for-license-holders/
With that being said, I think I can at least help point you in the right direction by recommending the use of two things within The Events Calendar:
1. tribe_get_events()
2. tribe_events_pre_get_posts()
1. tribe_get_events()
For individual and specified queries of events, the tribe_get_events() function may be useful to you—it’s a wrapper for get_posts() which is itself a wrapper for WP_Query, and so you may be able to pass that ep_integrate parameter as an argument through this function; this may work well because it’ll pass that ep_integrate parameter to WP_Query like you’re intending, but will also take care of some of the other event-related details for you. So something like this, for example:
$events = tribe_get_events( array(
'posts_per_page' => 20,
's' => 'search phrase',
'ep_integrate' => true
) );
2. tribe_events_pre_get_posts()
This may be more specifically helpful for your needs—instead of using WordPress’ own built-in pre_get_posts() filter, you might find more success by using The Events Calendar’s own version of pre_get_posts(), called tribe_events_pre_get_posts(). This may be more helpful because, much like how tribe_get_events() takes care of some event-related things that make it easier to work with in regards to events than the WordPress-default get_posts(), the tribe_events_pre_get_posts() filter takes care some of event-related configuration that may be relevant to your needs.
Something like this, for example:
function mt_elasticsearch_tribe_events_query( $query ) {
// No need to check for tribe_events in query because this will only run on events queries.
$query->set('ep_integrate', true);
}
add_action( 'tribe_events_pre_get_posts', 'mt_elasticsearch_tribe_events_query' );
As noted, we cannot help with this sort of thing and you’ll mostly have to take the reins here. I hope this information helps you get started, though! 😀
Cheers,
GeorgeFebruary 7, 2017 at 8:35 am #1230686Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Looking at ElasticSearch / ElasticPress to fix slow queries/timeouts/502s’ is closed to new replies.
