摄取搜索(弹性搜索)在 PHP 中不起作用
Ingest Search (Elastic Search) is not working in PHP
我已经在我的本地服务器上安装了 elastic search 和 ingest 插件。弹性引擎 运行 很好。我设置了以下任务:
- 映射
- 索引
现在我一直在搜索,没有用。它 returns 空数组。这是我在 PHP:
中的代码
public function ingest_processor_searching($query)
{
$client = $this->client;
$params = [
'index' => 'ingest_index',
'type' => 'attachment',
'body' => [
'query' => [
'match' => [
'textField' => $query,
]
],
],
];
$response = $client->search($params);
return $response;
}
结果:
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
但是我有 GET 的数据 http://localhost:9200/ingest_index/attachment/2
{
"_index": "ingest_index",
"_type": "attachment",
"_id": "2",
"_version": 1,
"found": true,
"_source": {
"file_path": "/Users/selimreza/Sites/haber_dev/public/uploads/files/bower.txt",
"attachment": {
"content_type": "text/plain; charset=ISO-8859-1",
"language": "en",
"content": "Welcome to Dhaka",
"content_length": 18
},
"textField": "V2VsY29tZSB0byBEaGFrYQo="
}
}
我做错了什么?
尝试从 'textField' => $query
中删除 ,
,因为您没有匹配多个值。如果仍然不起作用,请尝试使用 term 查询而不是 match
:
$params = [
'index' => 'ingest_index',
'type' => 'attachment',
'body' => [
'query' => [
'term' => [ <-- have this
'textField' => $query <-- try removing the comma
]
],
],
];
我已经在我的本地服务器上安装了 elastic search 和 ingest 插件。弹性引擎 运行 很好。我设置了以下任务:
- 映射
- 索引
现在我一直在搜索,没有用。它 returns 空数组。这是我在 PHP:
中的代码public function ingest_processor_searching($query)
{
$client = $this->client;
$params = [
'index' => 'ingest_index',
'type' => 'attachment',
'body' => [
'query' => [
'match' => [
'textField' => $query,
]
],
],
];
$response = $client->search($params);
return $response;
}
结果:
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
但是我有 GET 的数据 http://localhost:9200/ingest_index/attachment/2
{
"_index": "ingest_index",
"_type": "attachment",
"_id": "2",
"_version": 1,
"found": true,
"_source": {
"file_path": "/Users/selimreza/Sites/haber_dev/public/uploads/files/bower.txt",
"attachment": {
"content_type": "text/plain; charset=ISO-8859-1",
"language": "en",
"content": "Welcome to Dhaka",
"content_length": 18
},
"textField": "V2VsY29tZSB0byBEaGFrYQo="
}
}
我做错了什么?
尝试从 'textField' => $query
中删除 ,
,因为您没有匹配多个值。如果仍然不起作用,请尝试使用 term 查询而不是 match
:
$params = [
'index' => 'ingest_index',
'type' => 'attachment',
'body' => [
'query' => [
'term' => [ <-- have this
'textField' => $query <-- try removing the comma
]
],
],
];