-
Notifications
You must be signed in to change notification settings - Fork 314
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
Ordering by random with seed triggers error #1490
Comments
Any update on this? |
@jgmediadesign @aaronjpitts I'm not sure exactly what the use-case is here. Are you attempting to pass a parameter of 8 into a RAND function and apply that to the Elasticsearch query? Currently, my understanding is that WP_Query only supports a "rand" value for random order, which ElasticPress does support. We don't have any support for any other formats of RAND, but if you can share where this comes from I'm happy to dig in. Otherwise, if you're looking to get random sort order, pass your parameter like this |
Probably a bit niche - but if you want to randomly order posts, but also use pagination you need to use a random seed - this may explain things a bit better... |
Hi @brandwaffle, yes @jgmediadesign is correct. The number is the seed which provides the random order, but by providing the seed it will ensure the same randomised order will always be shown given that seed. This is critical for pagination etc. and if you want to allow users to share search results by sharing the seed in the URL etc. |
@jgmediadesign @aaronjpitts got it, thanks! Looks like we can do this by adding a
I'll add an enhancement label to this and we will get it worked on as soon as possible (which could be a few weeks and also depends a bit on release schedule). In the meantime it should be filterable via Thanks for bringing this one to my attention! |
Thank you for the update @brandwaffle. Could you please give me an idea on how I could do this in the meantime with Many thanks |
I figured it out. For anyone else that may be needing this you can use the below, remember to add a 'seed' property to your WP_Query $args.
|
@aaronjpitts @jgmediadesign would you mind testing out the PR submitted above to see if it properly creates seeded random sort queries? Thanks again for submitting this ticket and for the active participation!!! |
@brandwaffle I just tried the PR and I can confirm it works :) |
Currently, when attempting to order randomly, but retain pagination using a random seed as shown in the example below, an error is returned. It is possible to support this sorting mechanic?
'orderby' => string 'RAND(8)'
ElasticPress returns the following error:
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "No mapping found for [RAND(8)] in order to sort on",
"index_uuid": "dIoG24_OSIGfs40rPkmoZg",
"index": "booking8890-post-1"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "booking8890-post-1",
"node": "lT4wyZTURuqZ9S6hc_GivQ",
"reason": {
"type": "query_shard_exception",
"reason": "No mapping found for [RAND(8)] in order to sort on",
"index_uuid": "dIoG24_OSIGfs40rPkmoZg",
"index": "booking8890-post-1"
}
}
]
},
"status": 400
}
The text was updated successfully, but these errors were encountered: