10up / ElasticPress

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

BUG: Term Archive - WooCommerce - Page Combined with Product #3537

Closed lewisSkyline closed 1 year ago

lewisSkyline commented 1 year ago

Describe the bug

Hello,

We have a WooCommerce site that is using ElasticPress. On a particular term archive page (product-category), the first result is actually a page. When looking at the debug bar, it seems to be combining some page data with the product (the ID and name is the page, but the post slug, term results etc are all matching a product instead).

I've tried checking through the theme and other plugins in case there are any filters that are interfering but I haven't been able to find anything. I suspect the issue is because this page in question contains references to products that match the term archive query - but I would've thought that there should be a post type filter of product on anyway.

I've pasted the query from Debug Bar below, as well as the first result showing the anomalous product.

{
    "from": 0,
    "size": 25,
    "post_filter": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "must": [
                            {
                                "terms": {
                                    "terms.product_cat.slug": [
                                        "gen4-people-puppets"
                                    ]
                                }
                            },
                            {
                                "terms": {
                                    "terms.product_cat.slug": [
                                        "gen4-people-puppets"
                                    ]
                                }
                            }
                        ],
                        "must_not": [
                            {
                                "terms": {
                                    "terms.product_visibility.term_taxonomy_id": [
                                        7
                                    ]
                                }
                            }
                        ]
                    }
                },
                {
                    "terms": {
                        "post_type.raw": [
                            "product"
                        ]
                    }
                },
                {
                    "terms": {
                        "post_status": [
                            "publish",
                            "acf-disabled",
                            "tribe-ea-success",
                            "tribe-ea-failed",
                            "tribe-ea-schedule",
                            "tribe-ea-pending",
                            "tribe-ea-draft",
                            "wc-printed"
                        ]
                    }
                }
            ]
        }
    },
    "query": {
        "match_all": {
            "boost": 1
        }
    },
    "sort": [
        {
            "menu_order": {
                "order": "asc"
            }
        },
        {
            "post_title.sortable": {
                "order": "asc"
            }
        }
    ]
}
{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 38,
        "max_score": null,
        "hits": [
            {
                "_index": "onewayukcom-post-1",
                "_type": "post",
                "_id": "85591",
                "_score": null,
                "_source": {
                    "post_id": 85591, //this is the page ID
                    "ID": 85591,
                    "post_author": {
                        ....
                    },
                    "post_date": "2023-06-23 00:34:29",
                    "post_date_gmt": "2023-06-22 23:34:29",
                    "post_title": "RPM 1 Download", //this is the page name
                    "post_excerpt": "",
                    "post_content_filtered": ".....",
                    "post_status": "publish",
                    "post_name": "gen4-biblical-people-puppet-abraham", //this is the product url.
                    "post_modified": "2023-06-29 10:33:55",
                    "post_modified_gmt": "2023-06-29 09:33:55",
                    "post_parent": 0,
                    "post_type": "product",

I've struggled reproducing this bug, but I'm struggling to find the problem hence opening this issue.

Steps to Reproduce

  1. Create a WordPress Install with WooCommerce (pages built with SiteOrigin page builder.
  2. Create a product category, a product, and a page.
  3. Set 'content' weighting to 60.
  4. Add shortcode to pull out the product on the page.
  5. Build the index
  6. Head to the product category page and observe results.

Screenshots, screen recording, code snippet

No response

Environment information

No response

WordPress and ElasticPress information

Failed Queries

WordPress

WordPress Environment

wp_version: 6.2.2 home_url: https://onewayuk.com site_url: https://onewayuk.com is_multisite: false theme: OnewayUK (1.0.0) parent_theme: Customify (0.4.2) plugins: Advanced Custom Fields (6.1.6), Advanced Custom Fields: Repeater Field (2.1.0), AgreeMe Checkboxes For WooCommerce (1.0.9), Better Search Replace (1.4.2), Contact Form 7 (5.7.7), Customer Reviews for WooCommerce (5.29.0), Customify Pro (0.2.0), Debug Bar (1.1.4), Debug Bar ElasticPress (3.0.0), Duplicate Menu (0.2.2), ElasticPress (4.6.1), Event Tickets (5.6.0), Event Tickets Plus (5.7.0), Extra product options For WooCommerce | Custom Product Addons and Fields (3.2.0), Facebook for WooCommerce (3.0.25), Font Awesome (4.3.2), Google Listings and Ads (2.4.10), HurryTimer (2.8.1), Jetpack (12.2.1), Kadence WooCommerce Email Designer (1.5.11), LiteSpeed Cache (5.4), Livemesh SiteOrigin Widgets (3.2), Mailchimp for WooCommerce (2.8.3), MC4WP: Mailchimp for WordPress (4.9.5), Microsoft Clarity (0.9.2), Page Builder by SiteOrigin (2.23.0), PDF Invoices & Packing Slips for WooCommerce (3.5.5), Portfolio (10.0), Product Slider for WooCommerce (2.6.7), Redirection (5.3.10), SiteOrigin Widgets Bundle (1.50.1), Smart Slider 3 Pro (3.5.1.17), Store Toolkit for WooCommerce (2.3.8), Takepayments CS Payment Gateway (2.0.6), The Events Calendar (6.1.1), The Events Calendar Pro (6.1.0), Transients Manager (2.0.3), Where Did You Hear About Us Checkout Field for WooCommerce (1.3.0), WooCommerce (7.8.0), WooCommerce Extended Coupon Features FREE (3.3.3), WooCommerce Google Analytics Integration (1.8.2), WooCommerce Payments (6.0.0), WooCommerce PayPal Payments (2.1.0), WooCommerce WishLists (2.0.5), Wordfence Security (7.9.3), WordPress Importer (0.8.1), WPCode Lite (2.0.4.4), WP Optin Wheel Pro (4.0.1), WP Rollback (1.7.3), Yoast Duplicate Post (4.5), Yoast SEO (20.9) and Zendesk Chat Widget (1.4.18) revisions: all

Server Environment

php_version: 7.4.33 memory_limit: 512M timeout: 30

Indexable Content

One Way UK — https://onewayuk.com

post_count: 5 page_count: 285 tribe_event_series_count: 0 customify_hook_count: 1 product_count: 774 wishlist_count: 7,914 tribe_venue_count: 93 tribe_organizer_count: 0 tribe_events_count: 71 post_meta_keys: 4 page_meta_keys: 53 tribe_event_series_meta_keys: 0 customify_hook_meta_keys: 0 product_meta_keys: 58 wishlist_meta_keys: 0 tribe_venue_meta_keys: 1 tribe_organizer_meta_keys: 0 tribe_events_meta_keys: 5 total-all-post-types: 111 distinct-meta-keys: _thumbnail_id, delegate_names, panels_data, ep_exclude_from_search, slider_0_image, slider_0_large_text, slider_0_small_text, slider_0_link, slider_1_image, slider_1_large_text, slider_1_small_text, slider_1_link, slider, next_event_text, next_event_colour, team_directory_text, team_directory_text_colour, team_directory_image, team_directory_button_colour, team_directory_button_text, team_directory_button_link, testimonials_0_testimonial, testimonials_1_testimonial, testimonials, testimonial_button_text, testimonial_button_link, offers_colour, offers_button_text, offers_button_link, new_products_colour, new_products_button_text, new_products_button_link, header_image, logo, header_right_text, facebook_link, twitter_link, google_plus_link, youtube_link, footer_title_colour, footer_menu_1_title, footer_menu_2_title, footer_text_title, footer_text, footer_right_title, footer_right_text, footer_credits, footer_right_images_0_image, footer_right_images, top_purple_left_column, top_purple_middle_column, litespeed_no_cache, litespeed_no_image_lazy, litespeed_no_vpi, _downloadable, _virtual, _sold_individually, _backorders, _manage_stock, _tax_class, _tax_status, total_sales, _sku, _stock, _stock_status, _wc_average_rating, _product_version, product_guides_0_guide, product_specifications_0_specification, _min_regular_price_variation_id, _max_variation_regular_price, _min_variation_regular_price, _max_price_variation_id, _min_price_variation_id, _max_sale_price_variation_id, _min_sale_price_variation_id, _max_variation_sale_price, _sale_price, _crosssell_ids, _product_image_gallery, _product_attributes, _min_variation_sale_price, _max_regular_price_variation_id, faqs, _price, delivery_and_returns, product_guides, product_specifications, key_features, main_description, faq, _min_variation_price, _max_variation_price, minimum_quantity, delivery_returns, product_spec, _regular_price, _default_attributes, _upsell_ids, rrp, format, wcpa_exclude_global_forms, fb_product_item_id, _purchase_note, _weight, fb_product_group_id, fb_visibility, fb_product_description, headline_visibility, label_visibility and wc_enable

ElasticPress

Settings

host: http://localhost:9200/ index_prefix: language: en_GB per_page: 200 network_active: false

Timeouts

request_timeout: 5 index_document_timeout: 15 bulk_request_timeout: 30

Elasticsearch Indices

onewayukcom-post-1

health: yellow status: open index: onewayukcom-post-1 uuid: pihvaTNHQ6mmt-9wnbeeFQ pri: 5 rep: 1 docs.count: 9138 docs.deleted: 1888 store.size: 45.5mb pri.store.size: 45.5mb total_fields_limit: 5000

onewayukcom-user

health: yellow status: open index: onewayukcom-user uuid: n0zMBn8dTTenCf02_gOHlQ pri: 5 rep: 1 docs.count: 3403 docs.deleted: 699 store.size: 10.8mb pri.store.size: 10.8mb total_fields_limit: 5000

Last Sync

2023/07/10 11:17:00 am

method: WP-CLI is_full_sync: No end_date_time: 2023/07/10 11:22:00 am total_time: 0 hours, 5 minutes, 0 seconds total: 12516 synced: 12516 skipped: 0 failed: 0 errors: array ( )

Feature Settings

Autosuggest

active: true autosuggest_selector: .ep-autosuggest, .search-field endpoint_url: force_inactive: false trigger_ga_event: 0

Custom Search Results

active: true force_inactive: false

Post Search

active: true decaying_enabled: true force_inactive: false highlight_enabled: false highlight_excerpt: false highlight_tag: mark synonyms_editor_mode: simple

Users

active: true force_inactive: false

WooCommerce

active: true force_inactive: false

Code of Conduct

burhandodhy commented 1 year ago

Hi @lewisSkyline,

We are not sure if you are changing it or not but at some point, we've accessed https://onewayuk.com/wp-json/wp/v2/product/85591 and that returned a product. Now, it does not return it anymore (ElasticPress wouldn't affect this REST API endpoint.) Can you please go to the page ID 85591 and save it? It should reindex that page and update Elasticsearch with the correct information.

As on why it was sync'd as product instead of a page, you'd need to investigate why that REST API endpoint was returning data and is not anymore.

Regards, Burhan

lewisSkyline commented 1 year ago

Hello @burhandodhy ,

Thank you for looking into things - it is appreciated.

I tried resaving the page, and it didn't seem to have any effect. I then ran a sync via the WP CLI and the anomalous result is still showing.

Oddly enough, when the sync was running, if I tried loading the edit screen in the admin area (https://onewayuk.com/wp-admin/post.php?post=85591&action=edit) - it loaded a product edit screen, with mostly product data from a different post (e.g the slug was showing as gen4-biblical-people-puppet-abraham).

Following your reply I've tested a few other endpoints of the API and this individual post is showing as a result even it shouldn't - https://onewayuk.com/wp-json/wp/v2/search?search=Rpm&type=post&subtype=product&per_page=6.

I've gone back into the admin area now the sync is complete, and it has gone back to the page edit screen. I've double checked the database and it is definitely showing the post 85591 is a page - not a product.

phpmyadmin-screenshot-post-85591

I'll continue looking into things. Thanks again for taking a look.

Regards, Lewis

felipeelia commented 1 year ago

Thanks for the update @lewisSkyline. Another thing you could do to debug the problem is duplicate that environment and disable ElasticPress (you probably saw a product during the sync because EP will automatically disable itself on searches during a full sync.)

I'll close the issue for now but if you have any updates to share, please feel free to add a new comment (and depending on your findings we can reopen it.)