Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElasticPress Facet widget - no 'post__in' mapping #1885

Closed
MildConcussion opened this issue Sep 9, 2020 · 6 comments
Closed

ElasticPress Facet widget - no 'post__in' mapping #1885

MildConcussion opened this issue Sep 9, 2020 · 6 comments
Assignees
Labels

Comments

@MildConcussion
Copy link

As soon as I try to use the facet widget inside a product category it doesn't work and I get the error
"No mapping found for [post__in] in order to sort on"

Am I supposed to filter the query for it to work?

@MildConcussion MildConcussion added the type:question Further information is requested. label Sep 9, 2020
@brandwaffle
Copy link
Contributor

@MildConcussion can you share the query body that's being sent that generates that error?

@MildConcussion
Copy link
Author

Here is the query body:

{
    "from": 0,
    "size": 4,
    "sort": [
        {
            "post__in": {
                "order": "desc"
            }
        }
    ],
    "query": {
        "match_all": {
            "boost": 1
        }
    },
    "post_filter": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "must": {
                            "terms": {
                                "post_id": [
                                    38772,
                                    38737,
                                    38741,
                                    38466,
                                    38717,
                                    37794,
                                    37775,
                                    37702,
                                    35693,
                                    37602,
                                    35555,
                                    37583,
                                    37120,
                                    31968,
                                    35431
                                ]
                            }
                        }
                    }
                },
                {
                    "terms": {
                        "post_type.raw": [
                            "product"
                        ]
                    }
                },
                {
                    "term": {
                        "post_status": "publish"
                    }
                },
                {
                    "term": {
                        "post_lang": "et"
                    }
                }
            ]
        }
    }
}

@MildConcussion
Copy link
Author

Would really love to use ElasticPress with as much of the features as possible. It really speeds things up!

@brandwaffle Any tips that I could implement and get it to work? Could I fix this by filtering "ep_formatted_args" and replacing "post__in" with something else? I shall try and report back.

Also there is a smaller issue when using the regular WooCommerce filter widget instead of ElasticPress facet one. This is related to WPML. I have the indexing and filtering by post_lang, but the counts on the widgets are wrong - seems to count all languages.

@MildConcussion
Copy link
Author

Filtering "ep_formatted_args" and replacing the sort worked to fix the query not running, but the results are still weird.

On the main shop page the filtering by product attribute works, but as soon as you go into a product category and try it there, it doesn't - shows every product in the category.

The queries are as follows.

In subcategory without any filters selected:

{
    "from": 0,
    "size": 12,
    "sort": [
        {
            "_score": {
                "order": "desc"
            }
        },
        {
            "post_date": {
                "order": "desc"
            }
        }
    ],
    "query": {
        "match_all": {
            "boost": 1
        }
    },
    "post_filter": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "must": [
                            {
                                "terms": {
                                    "terms.product_cat.slug": [
                                        "filmikangelased"
                                    ]
                                }
                            },
                            {
                                "terms": {
                                    "terms.product_cat.slug": [
                                        "filmikangelased"
                                    ]
                                }
                            }
                        ],
                        "must_not": [
                            {
                                "terms": {
                                    "terms.product_visibility.term_taxonomy_id": [
                                        7
                                    ]
                                }
                            }
                        ]
                    }
                },
                {
                    "terms": {
                        "post_type.raw": [
                            "product"
                        ]
                    }
                },
                {
                    "terms": {
                        "post_status": [
                            "publish"
                        ]
                    }
                },
                {
                    "term": {
                        "post_lang": "et"
                    }
                }
            ]
        }
    },
    "aggs": {
        "terms": {
            "filter": {
                "bool": {
                    "must": [
                        {
                            "bool": {
                                "must": [
                                    {
                                        "terms": {
                                            "terms.product_cat.slug": [
                                                "filmikangelased"
                                            ]
                                        }
                                    }
                                ]
                            }
                        },
                        {
                            "terms": {
                                "post_type.raw": [
                                    "product"
                                ]
                            }
                        },
                        {
                            "terms": {
                                "post_status": [
                                    "publish"
                                ]
                            }
                        },
                        {
                            "term": {
                                "post_lang": "et"
                            }
                        }
                    ]
                }
            },
            "aggs": {
                "category": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.category.slug"
                    }
                },
                "post_tag": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.post_tag.slug"
                    }
                },
                "post_format": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.post_format.slug"
                    }
                },
                "product_cat": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.product_cat.slug"
                    }
                },
                "product_tag": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.product_tag.slug"
                    }
                },
                "product_shipping_class": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.product_shipping_class.slug"
                    }
                },
                "pa_brand": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.pa_brand.slug"
                    }
                },
                "ep_custom_result": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.ep_custom_result.slug"
                    }
                },
                "pa_variatsoon": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.pa_variatsoon.slug"
                    }
                }
            }
        }
    }
}

With pa_brand filter selected the query is:

{
    "from": 0,
    "size": 12,
    "sort": [
        {
            "_score": {
                "order": "desc"
            }
        },
        {
            "post_date": {
                "order": "desc"
            }
        }
    ],
    "query": {
        "match_all": {
            "boost": 1
        }
    },
    "post_filter": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "should": [
                            {
                                "terms": {
                                    "terms.pa_brand.slug": [
                                        "avengers"
                                    ]
                                }
                            },
                            {
                                "terms": {
                                    "terms.product_cat.slug": [
                                        "filmikangelased"
                                    ]
                                }
                            },
                            {
                                "terms": {
                                    "terms.product_cat.slug": [
                                        "filmikangelased"
                                    ]
                                }
                            }
                        ],
                        "must_not": [
                            {
                                "terms": {
                                    "terms.product_visibility.term_taxonomy_id": [
                                        7
                                    ]
                                }
                            }
                        ]
                    }
                },
                {
                    "terms": {
                        "post_type.raw": [
                            "product"
                        ]
                    }
                },
                {
                    "terms": {
                        "post_status": [
                            "publish"
                        ]
                    }
                },
                {
                    "term": {
                        "post_lang": "et"
                    }
                }
            ]
        }
    },
    "aggs": {
        "terms": {
            "filter": {
                "bool": {
                    "must": [
                        {
                            "bool": {
                                "should": [
                                    {
                                        "terms": {
                                            "terms.product_cat.slug": [
                                                "filmikangelased"
                                            ]
                                        }
                                    }
                                ]
                            }
                        },
                        {
                            "terms": {
                                "post_type.raw": [
                                    "product"
                                ]
                            }
                        },
                        {
                            "terms": {
                                "post_status": [
                                    "publish"
                                ]
                            }
                        },
                        {
                            "term": {
                                "post_lang": "et"
                            }
                        }
                    ]
                }
            },
            "aggs": {
                "category": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.category.slug"
                    }
                },
                "post_tag": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.post_tag.slug"
                    }
                },
                "post_format": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.post_format.slug"
                    }
                },
                "product_cat": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.product_cat.slug"
                    }
                },
                "product_tag": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.product_tag.slug"
                    }
                },
                "product_shipping_class": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.product_shipping_class.slug"
                    }
                },
                "pa_brand": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.pa_brand.slug"
                    }
                },
                "ep_custom_result": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.ep_custom_result.slug"
                    }
                },
                "pa_variatsoon": {
                    "terms": {
                        "size": 10000,
                        "field": "terms.pa_variatsoon.slug"
                    }
                }
            }
        }
    }
}

@MildConcussion
Copy link
Author

Guess the problem is the "should"? As it has both the "product_cat" and the "pa_brand" it shows the same results.

Any ideas how to fix this? Cheers!

@felipeelia felipeelia added question and removed type:question Further information is requested. labels Apr 29, 2021
@felipeelia
Copy link
Member

Hi @MildConcussion,

First of all, sorry for the late response here. So, regarding the sort by post__in clause, we are keeping track of it in this issue.

For the second problem, I hope you fixed that somehow. For users with the same problem that happen to get to this page, I'd check if products in the brand "avengers" really have "post_lang" as "et". Also, linking to this plugin may help.

Due to the lack of movement we had here, I'm closing the issue now but if you can come back and share the solution (if any), that would be perfect. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants