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: Queries with "orderby=type" or "orderby=post_type" do not work with ElasticPress. #1257

Closed
dannydamsky opened this issue Feb 19, 2019 · 5 comments · Fixed by #1388
Closed
Assignees

Comments

@dannydamsky
Copy link

I am using Elasticsearch with the Ingest Attachment plugin installed so that queries in documents are enabled in ElasticPress.

What I'm trying to do is get search results with PDF files that contain the search query inside them.
It works. But only if I do NOT provide the "orderby=type" parameter in the request/in the WP_Query.
If I provide the parameter, the ordering is done correctly, but the results that ElasticPress fetched from the documents do not appear in the search.

After Googling for hours and trying a bunch of things in with WP_Query, I have absolutely no idea how to fix this issue.

One thing to note is that "orderby=title" DOES work for some reason.

Current WordPress version: 5.0.2
Current ElasticPress version: 2.8.1
Current Elasticsearch version: 6.4.0 (same results with 6.3.0 as well)

Where do you host your Elasticsearch server: http://127.0.0.1:9200

Other plugins installed (WooCommerce, Simple Redirect Manager, etc..):

ACF to REST API
Advanced Custom Fields
Advanced Custom Fields PRO
Advanced Custom Fields: Ninjaforms Add-on
Enable Visual Mode in CloudFront
EventON
EventON - Full cal
Google Analytics +
JSON Basic Authentication
Media Library Assistant
Nav Menu Images
Ninja Forms
Restore Image Title
ShareThis Share Buttons
Shield
Simple CSV/XLS Exporter
Smush Pro
TinyMCE Advanced
Toolset Types
Ultimate Tag Cloud Widget
User Role Editor
W3 Total Cache
WP Add Mime Types
WP Mail SMTP
WP Mailto Links - Manage Email Links
WP REST API - filter fields
WP REST API - Meta Endpoints
WPML Media
WPML Multilingual CMS
WPML String Translation
WPML Translation Management
WPMU DEV Dashboard
WR MegaMenu

Steps to reproduce:

  1. Go here http://ratag.02.elasticdom.com/?s=אשקלון
  2. Add &orderby=type to the URL (if you add &orderby=title instead the issue does not persist)
  3. Notice that some of the posts previously shown are missing (Same result as disabling the ElasticPress plugin)
@brandwaffle
Copy link
Contributor

@dannydamsky thanks for submitting this issue!

One quick question I'm hoping you can clarify: in #3 on the steps to reproduce, you mentioned the result is the same with the plugin disabled. Am I understanding that correctly or does the orderby=type query work if ElasticPress is turned off?

@dannydamsky
Copy link
Author

@brandwaffle

The result is the same in the sense that in both cases ElasticPress doesn't work.

The query always works, but when I add orderby=type it doesn't fetch the results from ElasticPress.

This is apparent because ElasticPress fetches certain search results (PDF files containing the keyword for example) that do not appear when the plugin is disabled and/or when the orderby=type parameter is used.

@allan23 allan23 self-assigned this Mar 4, 2019
@RetroGameTalk
Copy link

RetroGameTalk commented Mar 21, 2019

@dannydamsky i don't know if this will help you. But since i'm an idiot and wasn't aware of the existence of "type" i created my own parameter. Which works for me. So if you are just interested in get this working ASAP you could use my method. But i think EP team should dig into the original issue for a solution.

My workaround concist on creating a new parameter let's call it something unused like: thetype

So on the link you use it like: http://ratag.02.elasticdom.com/?s=keyword&cat=-5&thetype=attachment

And then add this on functions.php add:

if ( ! is_admin() && is_search() && $query->is_main_query() ) {
		
			if ( isset($_GET['thetype'])) {
						
		$query->set('post_type', wp_unslash($_GET['thetype']));
		}		
	}

This works on my end, not a solution to the original problem but a workaround as i said. Cheers!

@jeffpaul jeffpaul self-assigned this May 22, 2019
@RetroGameTalk
Copy link

Since 3.03 my code above doesn't work any more.
I'm only trying to filter search by post type.
Like so:

/?s=query&post_type=amazing_type

But it doesn't do it. Why?

@tlovett1
Copy link
Member

tlovett1 commented Jul 2, 2019

@oscarssanchez is investigating.

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

Successfully merging a pull request may close this issue.

8 participants