当前位置:Gxlcms > PHP教程 > 请大神帮解答一下`elasticsearch`的相关问题,看文档看不出个步骤来

请大神帮解答一下`elasticsearch`的相关问题,看文档看不出个步骤来

时间:2021-07-01 10:21:17 帮助过:40人阅读

已完成工作描述:

1、已在本地windows机器上安装好了elasticsearch及相关插件。

2、然后在laravel中安装好了elasticsearch-php客户端。

3、写了如下这么一个SearchController控制器:

  1. <code><!--?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. class SearchController extends Controller
  6. {
  7. protected $client;
  8. public function __construct() {
  9. $this--->client = \Elasticsearch\ClientBuilder::create()->build();
  10. }
  11. public function index()
  12. {
  13. $params = [
  14. 'index' => 'node',
  15. 'type' => 'article',
  16. 'body' => [
  17. 'query' => [
  18. 'match_all' => []
  19. ]
  20. ]
  21. ];
  22. $response = $this->client->search($params);
  23. print_r($response);
  24. }
  25. public function create()
  26. {
  27. $params = [
  28. 'index' => 'node',
  29. 'type' => 'article',
  30. 'id' => '1029',
  31. 'body' => [
  32. 'query' => [
  33. 'match_all' => []
  34. ]
  35. ]
  36. ];
  37. $response = $this->client->index($params);
  38. print_r($response);
  39. }
  40. public function store(Request $request)
  41. {
  42. }
  43. public function show($id)
  44. {
  45. }
  46. public function edit($id)
  47. {
  48. }
  49. public function update(Request $request, $id)
  50. {
  51. }
  52. public function destroy($id)
  53. {
  54. }
  55. }
  56. </code>

问题描述:

1、虽然完成了以上3步,但现在没有头绪,看文档也看不出个步骤来。具体表现就是:假如我现在就要对一个名为articles的数据表进行索引和查询,还需要做什么?最好说一下每一步怎么做。谢谢。

2、'index' 、 'type' 、'body'是什么含义?

3、如果不用mysql,直接使用ES保存索引,那索引文件默认在什么目录?

回复内容:

已完成工作描述:

1、已在本地windows机器上安装好了elasticsearch及相关插件。

2、然后在laravel中安装好了elasticsearch-php客户端。

3、写了如下这么一个SearchController控制器:

  1. <code><!--?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. class SearchController extends Controller
  6. {
  7. protected $client;
  8. public function __construct() {
  9. $this--->client = \Elasticsearch\ClientBuilder::create()->build();
  10. }
  11. public function index()
  12. {
  13. $params = [
  14. 'index' => 'node',
  15. 'type' => 'article',
  16. 'body' => [
  17. 'query' => [
  18. 'match_all' => []
  19. ]
  20. ]
  21. ];
  22. $response = $this->client->search($params);
  23. print_r($response);
  24. }
  25. public function create()
  26. {
  27. $params = [
  28. 'index' => 'node',
  29. 'type' => 'article',
  30. 'id' => '1029',
  31. 'body' => [
  32. 'query' => [
  33. 'match_all' => []
  34. ]
  35. ]
  36. ];
  37. $response = $this->client->index($params);
  38. print_r($response);
  39. }
  40. public function store(Request $request)
  41. {
  42. }
  43. public function show($id)
  44. {
  45. }
  46. public function edit($id)
  47. {
  48. }
  49. public function update(Request $request, $id)
  50. {
  51. }
  52. public function destroy($id)
  53. {
  54. }
  55. }
  56. </code>

问题描述:

1、虽然完成了以上3步,但现在没有头绪,看文档也看不出个步骤来。具体表现就是:假如我现在就要对一个名为articles的数据表进行索引和查询,还需要做什么?最好说一下每一步怎么做。谢谢。

2、'index' 、 'type' 、'body'是什么含义?

3、如果不用mysql,直接使用ES保存索引,那索引文件默认在什么目录?

最近也是刚接触了es

es可以对应一个mysql数据库

index的概念就相当于库
type的概念就相当于表
document就相当于记录

那么你要操作,你首先要有个库,要有个表,才能进行增删查改

怎么索引和搜索去看文档吧

索引文件以文件形式存储在ES_HOME/data

logstash的jdbc插件你可以去官网找,jdbc官方文档

人气教程排行