ElasticPress icon indicating copy to clipboard operation
ElasticPress copied to clipboard

Missing posts and post types

Open ccanada81 opened this issue 12 years ago • 20 comments

Lots of posts missing from multisite index. A curl query of 'q=post_type:nav_menu_item' returns two menu items of the dozens currently in the database. Multiple custom post types don't appear at all.

ccanada81 avatar Nov 05 '14 00:11 ccanada81

The menu items could be a bug. I doubt anyone has used the plugin for that. Have you tried reindexing? Also, the plugin only indexes public post types by default.

tlovett1 avatar Nov 05 '14 03:11 tlovett1

Reindexed more than once - same results. And the custom post types in question are public. I only bring up the menu item type to illustrate the nature of the missing posts problem (i.e., there are numerous menu items but only two are being indexed).

ccanada81 avatar Nov 05 '14 05:11 ccanada81

Can you trace through the code? Should be easy to see which posts are being sent to ES.

tlovett1 avatar Nov 05 '14 05:11 tlovett1

I'm sure I'm being a little dense, but how exactly do you mean?

ccanada81 avatar Nov 05 '14 16:11 ccanada81

Can you trace through the code to pin point where the problem is happening? This seems like something very unique to your setup so it won't be easy for me to reproduce.

tlovett1 avatar Nov 05 '14 16:11 tlovett1

I'll provide an example. My code is built such that the method in which the loop lives grabs the value of the 's' query string argument and builds the custom query accordingly. Like so:

    $args = array(
    's' => $this->query['s'],
    'sites' => 'all'
);

$sposts = new WP_Query($args);

Let's say I do a search for 'chapter'. A MySQL query for post_status = 'publish' AND post_title LIKE '%chapter%' on blog ID 1 yields 15 posts - 1 menu item, and 14 belonging to post type called 'mclq_resource'. The custom query I built above returns 0 menu items and 1 mclq_resource, which is the same result I get via an equivalent curl query. If I define the post_type argument as all post types for which 'exclude_from_search' is false, I get 0 results.

Is this what you had in mind?

ccanada81 avatar Nov 05 '14 16:11 ccanada81

I tested out some code similar to what you have here and I'm able to get expected results from my multisite index. In regards to the nav menus, I'm not seeing any evidence that this is even indexed in my local version, so it would seem correct to me that the nav_menu_item post type isn't returned. As Taylor pointed out, this is an item that hasn't been tested extensively.

Have you tried utilizing sense to check your indexes that the data is there? This should be bundled within your Elasticsearch server http://www.elasticsearch.org/guide/en/marvel/current/#_sense

At this moment I haven't been able to replicate any issues along these lines.

NicoleGeissinger avatar Nov 07 '14 07:11 NicoleGeissinger

You said your post type was set to be public, but was it also set to be publicly_queryable? Could you paste in the post type registration for us to take a look at?

Also can you paste a gist of the output from Elasticsearch (not ElasticPress) when you run this query directly:

POST _search
{
   "size": 10000,
   "query": {
      "match_all": {}
   }
}

I'm not sure why nav menus are being indexed, that's not a normal thing to happen.

Additionally - as @tlovett1 was eluding to, if you're able to debug this situation and follow the process of the indexing you will be able to see where the problem is. If you're not familiar or not able to use XDEBUG and an editor capable of performing step through debugging, you could start where you think the problem may be occurring and start placing var_dump( $var ); die; where $var is a variable you wish to look at, to see what is happening in your code.

AaronHolbrook avatar Nov 08 '14 14:11 AaronHolbrook

Respectively:

  1. If the post type is public - and it most certainly is, via public => true in the args array - then it is publicly_queryable by default.
  2. As requested: http://goo.gl/fy7kDd
  3. I'm familiar and comfortable with XDEBUG, but I'm still confused about what I'd be looking for. If the return via WP_Query (which is what I assume I'm debugging in this case) matches the return via curl, then what about the code should I expect to have to change in order to improve upon the curl return?

Thanks for all your help, by the way.

ccanada81 avatar Nov 10 '14 17:11 ccanada81

I think these are the steps we need to go through:

  1. Find a post missing from the index
  2. Re-index via WP-CLI
  3. Check if the post is now in the index

How many posts are you indexing? Maybe WP CLI is timing out? If the post is not synced, this should be a pretty easy fix.

tlovett1 avatar Nov 11 '14 16:11 tlovett1

It's certainly in the hundreds, but WP-CLI doesn't return any messages to the effect that it has timed out. I have re-indexed more than once without any change.

ccanada81 avatar Nov 14 '14 15:11 ccanada81

Any thoughts on this? Am I out of luck?

ccanada81 avatar Nov 17 '14 23:11 ccanada81

Can you tell me how many posts are missing from the index?

tlovett1 avatar Nov 18 '14 04:11 tlovett1

A query for post_type => 'any' and post_status => 'publish' returns 803 posts.

ccanada81 avatar Nov 18 '14 18:11 ccanada81

Is 803 the number you are expecting? Looking for how many posts are missing.

tlovett1 avatar Nov 19 '14 20:11 tlovett1

Yes. 13 sites.

ccanada81 avatar Nov 19 '14 20:11 ccanada81

Have you had an opportunity to look into this one? The gist above shows 124 hits, and the WP_Query return for all non-excluded post types yields 803 posts, an apparent discrepancy of nearly 700 items.

Is there more I can provide to help illustrate what's happening here?

ccanada81 avatar Nov 26 '14 01:11 ccanada81

Can you paste the console output when running a WP-CLI index? Also, can you find a post that is not index and provide the attributes of the post (post_name, post_status, etc)?

If I were you I would setup logging within the index method. Specifically logging the output of the cURL request sent to Elasticsearch for each bulk post request.

tlovett1 avatar Nov 27 '14 01:11 tlovett1

Hi all, I think we can close this. @tlovett1 - what we found was that custom post types registered within a helper class were not being seen by ElasticPress. They looked like they were there, they had a menu, we could add new post type content, edit them, view them, etc. But they weren't getting indexed. Running get_post_types() in functions.php, for public post types, showed us the CPTs were missing.

Following the breadcrumbs, it was something about how they were being registered that fixed it. Content is being indexed and is queryable.

Moral of the story - be careful one does not over-complicate post type registration.

Thanks for the help, all. I'm happy to write more on this, if it helps others in similar positions.

ramseyp avatar Dec 05 '14 17:12 ramseyp

Happy to help!

tlovett1 avatar Dec 05 '14 18:12 tlovett1