当前位置: 首页 > 后端技术 > PHP

PHP如何使用ElasticsearchAPI接口

时间:2023-03-29 21:14:19 PHP

PHP中如何在实际场景中使用ElasticsearchAPI接口知识点?PHP?Elasticsearch?Restful接口菜鸟实际安装Elasticsearch官方PHPSDKhttps://github.com/elastic/el...composerrequireelasticsearch/elasticsearchCreateESClientuseElastic\弹性搜索客户端构建器;publicfunctioninfo(Request$request){//初始化$client=ClientBuilder::create()->setHosts(['localhost:9200'])->build();$response=$client->info();//响应格式$info=$response->asArray();$data=['es_info'=>$info,];$这->成功($数据);}执行返回结果JSON{"code":0,"message":"ok","data":{"es_info":{"name":"xqdsvtvnyje9zxeo","cluster_name":"elasticsearch","cluster_uuid":"tNPisFAxTVaRdXHKATIUWQ","version":{"number":"8.5.1","build_flavor":"default","build_type":"tar","build_hash":"c1310c45fc534583afe2c1c03046491efba2bba2","build_date":"2022-11-09T21:02:20.169855900Z","build_snapshot":false4.sion1:"9_","minimum_wire_compatibility_version":"7.17.0","minimum_index_compatibility_version":"7.0.0"},"tagline":"YouKnow,forSearch"}}}通过以上步骤,php和Elasticsearch就连接好了,然后使用api中的即可SDK。