Я новичок в Elastic press и получил некоторые проблемы на многосетевом сайте Wordpress и получил это исключение при попытке выполнить WP-запрос:
Причина: SearchParseException [не удалось проанализировать источник поиска [{"from": 0, "size": 3, "sort": [{"_ score": {"order": "desc"}}], " запрос ": {" BOOL ": {" должны ": [{" multi_match ": {" запрос ":" тест " "тип": "фраза", "поле": { "0": "post_title"," 1 ":" POST_CONTENT», "2": "post_excerpt", "3": "author_name", "таксономия": [ "post_tag", "категория"]}, "наддува": 4, "нечеткость": 0, "оператор": "и"}}, { "multi_match": { "запрос": "тест", "полей": { "0": "POST_TITLE", "1": "POST_CONTENT", "2":» post_excerpt», "3": "AUTHOR_NAME", "таксономия": [ "post_tag", "категория"]}, "подталкивание": 2, "размытость": 0}}, { "multi_match": { "поля": { "0": "POST_TITLE", "1": "POST_CONTENT", "2": "post_excerpt", "3": "AUTHOR_NAME", "таксономия": [ "post_tag", "категория"]}, "запрос ":" тест " "нечеткость": 0, "оператор": "и"}}]}}, "post_filter": { "BOOL": { "должен": [{ "термины": {" post_type.raw ": [" пост " "страница", "вложения", "событие"]}}, { "термины": { "post_status": [ "опубликовать", "ACF-инвалидов"]}}]}}," Aggs ": {" термины ": {" фильтр ": {" BOOL ": {" должен ": [{" термины ": {" post_type.raw ": [" сообщение " "страница", "присоединение"," события "]}}, {" термины ": { "Post_status": [ "опубликовать", "ACF-инвалидов"]}}]}}, "Aggs": { "категория": { "термины": { "размер": 10000, "поле": "термины. category.slug "}}," post_tag ": {" термины ": {" размер ": 10000," поле ":" terms.post_tag.slug "}}," post_format ": {" термины ": {" размер» : 10000, "поле": "terms.post_format.slug"}}, "key_themes": { "термины": { "размер": 10000, "поле": "terms.key_themes.slug"}}, "темы" : { "термины": { "размер": 10000, "поле": "terms.themes.slug"}}, "story_labels": { "термины": { "размер": 10000, "поле": "термины. story_labels.slug "}}," актив класса ": {" термины ": {" размер ": 10000," поле ":" terms.asset-class.slug "}}," область ": {" термины ": { "размер": 10000, "поле": "terms.region.slug"}}, "размер": { "термины": { "размер": 10000, "поле": "terms.size.slug"}} , "место": { "термины": { "размер": 10000, "поле": "terms.places.slug"}}, "организация": { "термины": { "размер": 10000, "поле" : "terms.organizations.slug"}}, "люди": { "термины": { "размер": 10000, "поле": "terms.people.slug"}}}}}}]]; nested: QueryParsingException [[multi_match] запрос не поддерживает [fields]];
пример кода эластичного пресса, который вызывает эту проблему:
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of ElasticpressFilters
*
* @author serafim_inplayer
*/
class ElasticpressFilters
{
public function __construct()
{
/*
* Hook into ep_formatted_args to add wighting arguments.
*/
add_filter('ep_formatted_args', [$this, 'set_es_search_args'], 300, 2);
}
function set_es_search_args($formatted_args, $args)
{
$search_fields = [
'post_title',
'post_excerpt',
'post_content'
];
if (isset($args['search_fields'])) {
$search_fields = $args['search_fields'];
}
if (isset($args['exact']) && $args['exact'] == true) {
$query = [
'multi_match' => [
'query' => '',
'type' => 'phrase',
'fields' => $search_fields,
'boost' => apply_filters('ep_match_phrase_boost', 4, $search_fields, $args),
'operator' => 'and',
'fuzziness' => 0,
]
];
if (!empty($args['s'])) {
unset($formatted_args['query']);
$query['multi_match']['query'] = $args['s'];
$formatted_args['query'] = $query;
}
} else {
$query = [
'bool' => [
'should' => [
[
'multi_match' => [
'query' => '',
'type' => 'phrase',
'fields' => $search_fields,
'boost' => apply_filters('ep_match_phrase_boost', 4, $search_fields, $args),
'fuzziness' => 0,
'operator' => 'and',
]
],
[
'multi_match' => [
'query' => '',
'fields' => $search_fields,
'boost' => apply_filters('ep_match_boost', 2, $search_fields, $args),
'fuzziness' => 0,
]
],
[
'multi_match' => [
'fields' => $search_fields,
'query' => '',
'fuzziness' => 0,
'operator' => 'and',
],
]
],
],
];
/**
* We are using ep_integrate instead of ep_match_all. ep_match_all will be
* supported for legacy code but may be deprecated and removed eventually.
*
* @since 1.3
*/
if (!empty($args['s'])) {
$query['bool']['should'][2]['multi_match']['query'] = $args['s'];
$query['bool']['should'][1]['multi_match']['query'] = $args['s'];
$query['bool']['should'][0]['multi_match']['query'] = $args['s'];
$formatted_args['query'] = apply_filters('ep_formatted_args_query', $query, $args);
} else if (!empty($args['ep_match_all']) || !empty($args['ep_integrate'])) {
$formatted_args['query']['match_all'] = ['boost' => 1];
}
}
/*
* Exclude posts with defined categories by slugs in array
*/
if (!empty($args['ep_integrate']) && !empty($args['ep_exclude_categories'])) {
$formatted_args['post_filter']['bool']['must'][0]
['bool']['should'][0]['bool']['must_not'][]
['terms']['terms.category.slug'] = $args['ep_exclude_categories'];
}
/*
* If ep_exists_key_themes is true will display all posts with key themes
*/
if (!empty($args['ep_integrate']) && !empty($args['ep_exists_key_themes'])) {
$formatted_args['post_filter']['bool']['must'][0]
['bool']['should'][1]['bool']['must'][]
['exists']['field'] = 'terms.key_themes.term_id';
}
return $formatted_args;
}
Проблема, которая вызывает это, когда $ search_fields получил следующие значения (массив внутри массива):
$search_fields = array(
'post_title',
'post_content',
'post_excerpt',
'author_name',
'taxonomies' => array(
'post_tag',
'category',
)
);
Спасибо за помощь.