gpt4 book ai didi

html - 从HTML搜索和查看Elasticsearch结果

转载 作者:行者123 更新时间:2023-12-03 01:40:16 25 4
gpt4 key购买 nike

我目前正在研究一个项目,正如标题所示,我想要做的是能够从HTML搜索已经在Elasticsearch上上传的集群,并在HTML中预览结果。

我想到了使用Logstash将搜索输入从HTML发送到elasticsearch的方法,但是我找不到在HTML中查看这些结果的方法。总的来说,我想做的是能够像kibana一样使用elasticsearch,但是可以从网站上进行。

感谢任何可能的帮助:)

最佳答案

使用php-elastic官方库(https://github.com/elastic/elasticsearch-php)。

您可以使用以下代码获取搜索结果:

$this->client = ClientBuilder::create()->setHosts(["ELASTICSEARCH_HOST:ELASTICSEARCH_PORT"])->build();

$queryBody = ["match_all" => new \stdClass()];

if($search) {
$queryBody = [
"match" => [
"_all" => $search
]
];

}
$params = [
"from" => $page * $this->pageSize, // if you want data for pagination
"size" => $this->pageSize, // if you want data for pagination
"index" => $index,
"type" => $type,
"_source_include" => $fields, // Your required field array
"body" => [
"query" => $queryBody
]

];
//Get the search result
$response = $this->client->search($params);

关于html - 从HTML搜索和查看Elasticsearch结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48323945/

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