【发布时间】:2019-11-19 16:21:37
【问题描述】:
我按照这篇文章连接 laravel 和 ElasticSearch: https://madewithlove.be/how-to-integrate-your-laravel-app-with-elasticsearch/
我在 MySQL 数据库中有一个表,它具有树字段:“title”、“description”和“price”。 “标题”和“描述”是字符串类型。所以我写了下面的代码进行搜索,这工作正常:
private function searchOnElasticsearch(string $query): array
{
$instance = new Article;
$items = $this->search->search([
'index' => $instance->getSearchIndex(),
'type' => $instance->getSearchType(),
'body' => [
'query' => [
'multi_match' => [
'fields' => ['title', 'description'],
'query' => $query,
],
],
],
]);
return $items;
}
但是现在,我需要检查 bigInt 类型 的“价格”字段,就像其他两个字段一样:'fields' => ['title', 'description','price'],
更新
当我在字段中添加“价格”时,我在 laravel 中收到此错误:
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"失败 创建查询: {\n \"multi_match\" : {\n \"query\" : \"bad\",\n \"字段\" : [\n \"描述^1.0\",\n \"价格^1.0\",\n \"tags^1.0\",\n \"title^1.0\"\n ],\n \"type\" : \"best_fields\",\n \"operator\" : \"OR\",\n \"slop\" : 0,\n \"prefix_length\" : 0,\n \"max_expansions\" : 50,\n \"zero_terms_query\" : \"NONE\",\n \"auto_generate_synonyms_phrase_query\" : true,\n \"fuzzy_transpositions\" : true,\n \"boost\" : 1.0\n }\n}","index_uuid":"mm787GxMS4WjjjqwRD5YIw","index":"commodities"}],"type":"search_phase_execution_exception","reason":"all 碎片 失败","阶段":"查询","分组":true,"failed_shards":[{"shard":0,"index":"commodities","node":"JYWiIdbLQtu3aWkm_F-e9Q","reason" :{"type":"query_shard_exception","reason":"失败 创建查询: {\n \"multi_match\" : {\n \"query\" : \"bad\",\n \"字段\" : [\n \"描述^1.0\",\n \"价格^1.0\",\n \"tags^1.0\",\n \"title^1.0\"\n ],\n \"type\" : \"best_fields\",\n \"operator\" : \"OR\",\n \"slop\" : 0,\n \"prefix_length\" : 0,\n \"max_expansions\" : 50,\n \"zero_terms_query\" : \"NONE\",\n \"auto_generate_synonyms_phrase_query\" : true,\n \"fuzzy_transpositions\" : true,\n \"boost\" : 1.0\n }\n}","index_uuid":"mm787GxMS4WjjjqwRD5YIw","index":"commodities","caused_by":{"type":"number_format_exception","reason":"For 输入字符串:\"bad\""}}}]},"status":400}
【问题讨论】:
-
当您将
price字段添加到您的查询时会发生什么? -
请将完整的错误添加到您的帖子中,它比 cmets 更清晰
标签: php laravel elasticsearch