PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / includes / classes / ElasticsearchErrorInterpreter.php

ElasticsearchErrorInterpreter.php in ElasticPress 5.3.5, at includes/classes/ElasticsearchErrorInterpreter.php

138 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Error Interpreter Class File
4 *
5 * @since 5.0.0
6 * @package elasticpress
7 */
8
9 namespace ElasticPress;
10
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * ElasticsearchErrorInterpreter class
15 *
16 * @package ElasticPress
17 */
18 class ElasticsearchErrorInterpreter {
19 /**
20 * Format the error message and provide a solution
21 *
22 * @param string $error Error message
23 * @return array Array containing `error` and `solution`
24 */
25 public function maybe_suggest_solution_for_es( $error ) {
26 $sync_url = Utils\get_sync_url();
27
28 if ( 'no such index' === $error ) { // ES 5.x error
29 return [
30 'error' => 'no such index',
31 'solution' => sprintf(
32 /* translators: Sync Page URL */
33 __( 'It seems one of the indices is missing. <a href="%1$s">Delete all data and sync</a> to fix the issue.', 'elasticpress' ),
34 $sync_url
35 ),
36 ];
37 }
38
39 if ( preg_match( '/no such index \[(.*?)\]/', $error, $matches ) ) {
40 return [
41 'error' => 'no such index [???]',
42 'solution' => sprintf(
43 /* translators: 1. Index name; 2. Sync Page URL */
44 __( 'It seems the %1$s index is missing. <a href="%2$s">Delete all data and sync</a> to fix the issue.', 'elasticpress' ),
45 '<code>' . $matches[1] . '</code>',
46 $sync_url
47 ),
48 ];
49 }
50
51 if ( preg_match( '/No mapping found for \[(.*?)\] in order to sort on/', $error, $matches ) ) {
52 return [
53 'error' => 'No mapping found for [???] in order to sort on',
54 'solution' => sprintf(
55 /* translators: 1. Index name; 2. Sync Page URL */
56 __( 'The field %1$s was not found. Make sure it is added to the list of indexed fields and run <a href="%2$s">a new sync</a> to fix the issue.', 'elasticpress' ),
57 '<code>' . $matches[1] . '</code>',
58 $sync_url
59 ),
60 ];
61 }
62
63 /* translators: 1. Field name; 2. Sync Page URL */
64 $field_type_solution = __( 'It seems you saved a post without doing a full sync first because <code>%1$s</code> is missing the correct mapping type. <a href="%2$s">Delete all data and sync</a> to fix the issue.', 'elasticpress' );
65
66 if ( preg_match( '/Fielddata is disabled on text fields by default. Set fielddata=true on \[(.*?)\]/', $error, $matches ) ) {
67 return [
68 'error' => 'Fielddata is disabled on text fields by default. Set fielddata=true on [???]',
69 'solution' => sprintf( $field_type_solution, $matches[1], $sync_url ),
70 ];
71 }
72
73 if ( preg_match( '/field \[(.*?)\] is of type \[(.*?)\], but only numeric types are supported./', $error, $matches ) ) {
74 return [
75 'error' => 'field [???] is of type [???], but only numeric types are supported.',
76 'solution' => sprintf( $field_type_solution, $matches[1], $sync_url ),
77 ];
78 }
79
80 if ( preg_match( '/Alternatively, set fielddata=true on \[(.*?)\] in order to load field data by uninverting the inverted index./', $error, $matches ) ) {
81 return [
82 'error' => 'Alternatively, set fielddata=true on [???] in order to load field data by uninverting the inverted index.',
83 'solution' => sprintf( $field_type_solution, $matches[1], $sync_url ),
84 ];
85 }
86
87 if ( preg_match( '/Limit of total fields \[(.*?)\]( in index \[(.*?)\])? has been exceeded/', $error, $matches ) ) {
88 return [
89 'error' => 'Limit of total fields [???] in index [???] has been exceeded',
90 'solution' => sprintf(
91 /* translators: Elasticsearch or ElasticPress.io; 2. Link to article; 3. Link to article */
92 __( 'Your website content has more public custom fields than %1$s is able to store. Check our articles about <a href="%2$s">Elasticsearch field limitations</a> and <a href="%3$s">how to index just the custom fields you need</a> and sync again.', 'elasticpress' ),
93 Utils\is_epio() ? __( 'ElasticPress.io', 'elasticpress' ) : __( 'Elasticsearch', 'elasticpress' ),
94 'https://www.elasticpress.io/resources/articles/i-get-the-error-limit-of-total-fields-in-index-has-been-exceeded/',
95 'https://www.elasticpress.io/resources/articles/how-to-exclude-metadata-from-indexing/'
96 ),
97 ];
98 }
99
100 if ( preg_match( '/Number of (.*) index errors/', $error, $matches ) ) {
101 return [
102 'error' => $error,
103 'solution' => '',
104 ];
105 }
106
107 if ( Utils\is_epio() ) {
108 if ( preg_match( '/you have reached the limit of indices your plan supports/', $error, $matches ) ) {
109 return [
110 'error' => $error,
111 'solution' => sprintf(
112 /* translators: ElasticPress.io Article URL */
113 __( 'Please refer to <a href="%s">this article</a> outlining how to address this issue.', 'elasticpress' ),
114 'https://www.elasticpress.io/resources/articles/how-to-fix-the-you-have-reached-the-limit-of-indices-of-your-plan-and-it-was-not-possible-to-create-a-new-index-error/'
115 ),
116 ];
117 }
118 return [
119 'error' => $error,
120 'solution' => sprintf(
121 /* translators: ElasticPress.io My Account URL */
122 __( 'We did not recognize this error. Please open an ElasticPress.io <a href="%s">support ticket</a> so we can troubleshoot further.', 'elasticpress' ),
123 'https://www.elasticpress.io/my-account/'
124 ),
125 ];
126 }
127
128 return [
129 'error' => $error,
130 'solution' => sprintf(
131 /* translators: New GitHub issue URL */
132 __( 'We did not recognize this error. Please consider opening a <a href="%s">GitHub Issue</a> so we can add it to our list of supported errors.', 'elasticpress' ),
133 'https://github.com/10up/ElasticPress/issues/new/choose'
134 ),
135 ];
136 }
137 }
138