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

BUG: WP_User_Query orderby #62

Open
ws256 opened this issue Sep 20, 2022 · 2 comments
Open

BUG: WP_User_Query orderby #62

ws256 opened this issue Sep 20, 2022 · 2 comments

Comments

@ws256
Copy link

ws256 commented Sep 20, 2022

Hi there.

In order to get relevant user search results, we used 'orderby' => 'relevance' in WP_User_Query
But I would like to use other sorting options as well.
quote from documentation "You can sort by multiple fields as well i.e. title meta.my_key.raw"
'orderby' => 'relevance meta.my_key.long',
Only one sort option works.
If you specify two parameters, we get a 400 error. "Query Response Code: HTTP 400"

$wp_user_query = new WP_User_Query([
	'search' => esc_attr($query_str),
	'number' => 10,
	'paged' => $current_page,
	'orderby' => 'title meta.user_points.long',
	'order' => 'DESC',
	'offset' => $offset,
	'search_columns' => [
		'user_nicename',
		'display_name'
	],
	'search_fields' => [
		'meta' => [
			'display_name',
			'first_name',
			'last_name',
			'description',
			'expertise',
			'user_points',
			'city',
			'soft'
		],
	],
	'ep_integrate' => true,
]);

Error:

{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "No mapping found for [title] in order to sort on",
"index_uuid": "IV7U_v67T0-abeNgmVWPfw",
"index": "devsite-user"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "can_match",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "devsite-user",
"node": "-vua6l6HSJesVPT9PmU8uA",
"reason": {
"type": "query_shard_exception",
"reason": "No mapping found for [title] in order to sort on",
"index_uuid": "IV7U_v67T0-abeNgmVWPfw",
"index": "devsite-user"
}
}
]
},
"status": 400
}

  • WordPress version: 6.0.2
  • ElasticPress version: 4.3.0
  • Elasticsearch version: 7.10.2
  • Local
  • Post Search, Autosuggest, Users, Protected Content, Related Posts, Facets, Terms, Custom Search Results

Separate - works
'orderby' => 'meta.user_points.long'
or
'orderby' => 'relevance'

@ws256 ws256 added the bug Something isn't working label Sep 20, 2022
@oscarssanchez
Copy link
Contributor

Hi @ws256 ,

The reason you get that is because there's no field mapping "title" for users. Try something like:

'orderby' => 'display_name meta.user_points.long'

And this should work.

Probably worth changing in the docs to avoid confusions.

@oscarssanchez oscarssanchez removed the bug Something isn't working label Sep 28, 2022
@ws256
Copy link
Author

ws256 commented Sep 28, 2022

Hi @oscarssanchez,

'orderby' => 'display_name meta.user_points.long'
In this case, there are no errors 400. But the issuance is not at all what you need.
Sorting on the numerical field meta.user_points.long does not occur

Even if you use it
'orderby' => 'display_name relevance',
The only James Bond is on the 3rd page page. The results are no rrelevant.

In order for the search results to match the search query, you should use only one sorting option
'orderby' => 'relevance'

The other sorting options do not work if you use two keys.

'orderby' => 'meta.user_points.long'

or sorting by numeric field, it also works only if there is one key

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

No branches or pull requests

3 participants