10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.24k stars 312 forks source link

The Feature Sync Is Looping #3976

Open DarioBF opened 1 week ago

DarioBF commented 1 week ago

Describe your question

Hello,

We have just installed an ElasticSearch 8.15.1 instance, and the ElasticPress plugin is stuck in a loop during the initial sync. Is there a specific version of ElasticSearch required?

Best regards.

Code of Conduct

burhandodhy commented 1 day ago

Hi @DarioBF,

The plugin works fine with Elasticsearch 8.12.2. Since 8.15.1 is not a major version, I believe the plugin should also work with it. To figure out the problem, can you please confirm if you are seeing any errors in the browser console?

Additionally, have you tried running the sync using the WP CLI command wp elasticpress sync --setup --yes --show-errors --force?

Regards, Burhan

DarioBF commented 21 hours ago

It seems that the CLI method worked.

Now, I have another problema trying to use the related posts query function: $related_posts_query = \ElasticPress\Features::factory() ->get_registered_feature( 'related_posts' ) ->get_related_query( $post_id, 5 );

This site has no posts, only custom post types contents... Is there any way to make that "get_related_query" and "find_related" search for current post type?

The documentation followed is not enough about that issue: https://www.elasticpress.io/documentation/article/related-posts-api/

DarioBF commented 16 minutes ago

Hi again, maybe this is the way?

function modify_related_posts_query_args( $args ) {
    $post_id   = get_the_ID();
    $post_type = get_post_type( $post_id );

    $args['post_type'] = $post_type;
    return $args;
}
add_filter( 'ep_find_related_args', 'modify_related_posts_query_args' );

function abn_eloutput_related_posts( $content ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        return $content;
    }
    if ( ! class_exists( '\ElasticPress\Features' ) ) {
        return $content;
    }

    $post_id = get_the_ID();

    $related_posts_query = \ElasticPress\Features::factory()
        ->get_registered_feature( 'related_posts' )
        ->get_related_query( $post_id, 5 );

    if ( $related_posts_query instanceof WP_Query ) {
        if ( $related_posts_query->have_posts() ) {
            while ( $related_posts_query->have_posts() ) {
                $related_posts_query->the_post();
                // echo '<a href="' . get_the_permalink() . '">' . get_the_title() . '</a><br>';
                var_dump( get_the_title() );
            }
            wp_reset_postdata();
        } else {
            echo 'No hay publicaciones relacionadas de ElasticPress.';
        }
    } else {
        echo 'La consulta no es una instancia de WP_Query';
    }

    return $content;
}
add_action( 'the_content', 'abn_eloutput_related_posts', 10 );

It's working, I think!

Is it the proper way to implement something like this?

Regards.