gpt4 book ai didi

php - 摄取搜索( Elasticsearch )在 PHP 中不起作用

转载 作者:搜寻专家 更新时间:2023-10-31 21:23:16 25 4
gpt4 key购买 nike

我已经在我的本地服务器上安装了 elastic search 和 ingest 插件。弹性引擎运行良好。我设置了以下任务:

  1. 映射
  2. 索引

现在我一直在搜索,没有用。它返回空数组。这是我的 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查询而不是匹配:

 $params = [
'index' => 'ingest_index',
'type' => 'attachment',
'body' => [
'query' => [
'term' => [ <-- have this
'textField' => $query <-- try removing the comma
]
],
],
];

关于php - 摄取搜索( Elasticsearch )在 PHP 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41793344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com