PluginProbe
ElasticPress / 5.0.1
ElasticPress v5.0.1
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.0.1, at includes/classes/ElasticsearchErrorInterpreter.php

121 lines 4.6 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://elasticpress.zendesk.com/hc/en-us/articles/360051401212-I-get-the-error-Limit-of-total-fields-in-index-has-been-exceeded-',
95 'https://elasticpress.zendesk.com/hc/en-us/articles/360052019111'
96 ),
97 ];
98 }
99
100 if ( Utils\is_epio() ) {
101 return [
102 'error' => $error,
103 'solution' => sprintf(
104 /* translators: ElasticPress.io My Account URL */
105 __( 'We did not recognize this error. Please open an ElasticPress.io <a href="%s">support ticket</a> so we can troubleshoot further.', 'elasticpress' ),
106 'https://www.elasticpress.io/my-account/'
107 ),
108 ];
109 }
110
111 return [
112 'error' => $error,
113 'solution' => sprintf(
114 /* translators: New GitHub issue URL */
115 __( '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' ),
116 'https://github.com/10up/ElasticPress/issues/new/choose'
117 ),
118 ];
119 }
120 }
121