Overview
ElasticPress (WordPress Plugin) is a free plugin for WordPress which vastly enhances the search speed of WordPress site, as it integrates into ElasticSearch’s powerful indexing system. The default settings for ElasticPress are pretty good, but you may run into some capacity issues with lots of posts or custom fields.
In this post, we’ll fix a common error which prevents posts from being indexed by ElasticSearch.
ElasticPress Index Error
You may encounter this error while trying to issue a manual index command.
wp elasticpress index --show-errors
The above command will show status updates with the posts indexed thus far. After those, if you run into this issue, you’ll see an error.
[illegal_argument_exception] Limit of total fields [1000] in index [index-name] has been exceeded
This will cause the post ID’s listed to not be indexed by ElasticSearch and thus ElasticPress.
The Issue
The issue is that the index.mapping.total_fields.limit value in ElasticPress for this index is too small. The default limit is 1000, and sometimes this isn’t enough to index all of your posts.
The Solution
What you can do to fix this is to increase the total_fields limits of the index with all of the custom fields. In the SSH command below, you can replace INDEX-NAME-HERE with the name of the real index.
This assumes that ElasticSearch is running on port 9200 via localhost on the server you issue this command on.
This also assumes curl is installed.
And finally, it assumes that you’ve changed the index name in the curl command below, or it won’t work.
curl -H 'Content-Type: application/json' -XPUT -d '{"index.mapping.total_fields.limit": 5000}' http://localhost:9200/INDEX-NAME-HERE/_settings
On a successful change, you’ll get a JSON response:
{"acknowledged":true}
You can then run another index command in WP-CLI via SSH, or update it in WordPress Admin, and it should populate the index with all of your posts. If it doesn’t get them all, keep incrementing the limit, but keep an eye on ElasticSearch CPU usage, and you should be ready to rock and roll!
Dear all,
Can I apply this setting for all index ?
Can I change elasticsearch config file ?
Thanks
You would need to apply this setting via the curl command to the index names you’re using, but yes that’s possible. The “config file” so to speak would be the ElasticPress configuration and wp-config.php which are available for you to edit. ElasticSearch configuration however could be amended if you have access to do so, to allow for higher field limits. Usually this would be set up at the system level, so you may need to ask your host to adjust this.