Home > Backend Development > PHP Tutorial > Please help me answer some questions related to `elasticsearch`. I can't see the steps in the document.

Please help me answer some questions related to `elasticsearch`. I can't see the steps in the document.

WBOY
Release: 2016-07-06 13:53:31
Original
927 people have browsed it

Description of completed work:

1. Elasticsearch and related plug-ins have been installed on the local windows machine.

2. Then install the elasticsearch-php client in laravel.

3. Wrote a SearchController as follows:

<code><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class SearchController extends Controller
{

    protected $client;

    public function __construct() {

        $this->client = \Elasticsearch\ClientBuilder::create()->build();
    }

    public function index()
    {
        $params = [
            'index' => 'node',
            'type' => 'article',
            'body' => [
                'query' => [
                    'match_all' => []
                ]
            ]
        ];

        $response = $this->client->search($params);
        print_r($response);
    }


    public function create()
    {
        $params = [
            'index' => 'node',
            'type' => 'article',
            'id' => '1029',
            'body' => [
                'query' => [
                    'match_all' => []
                ]
            ]
        ];

        $response = $this->client->index($params);
        print_r($response);
    }


    public function store(Request $request)
    {

    }

    public function show($id)
    {

    }


    public function edit($id)
    {

    }


    public function update(Request $request, $id)
    {

    }


    public function destroy($id)
    {
        
    }
}
</code>
Copy after login
Copy after login

Problem description:

1. Although I have completed the above 3 steps, I have no clue now and I can’t see any steps in the document. The specific performance is: If I want to index and query a data table named articles now, what else do I need to do? It's best to explain how to do each step. Thanks.

2. What do 'index', 'type' and 'body' mean?

3. If you don’t use mysql and use ES to save the index directly, what directory is the index file in by default?

Reply content:

Description of completed work:

1. Elasticsearch and related plug-ins have been installed on the local windows machine.

2. Then install the elasticsearch-php client in laravel.

3. Wrote a SearchController as follows:

<code><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class SearchController extends Controller
{

    protected $client;

    public function __construct() {

        $this->client = \Elasticsearch\ClientBuilder::create()->build();
    }

    public function index()
    {
        $params = [
            'index' => 'node',
            'type' => 'article',
            'body' => [
                'query' => [
                    'match_all' => []
                ]
            ]
        ];

        $response = $this->client->search($params);
        print_r($response);
    }


    public function create()
    {
        $params = [
            'index' => 'node',
            'type' => 'article',
            'id' => '1029',
            'body' => [
                'query' => [
                    'match_all' => []
                ]
            ]
        ];

        $response = $this->client->index($params);
        print_r($response);
    }


    public function store(Request $request)
    {

    }

    public function show($id)
    {

    }


    public function edit($id)
    {

    }


    public function update(Request $request, $id)
    {

    }


    public function destroy($id)
    {
        
    }
}
</code>
Copy after login
Copy after login

Problem description:

1. Although I have completed the above 3 steps, I have no clue now and I can’t see any steps in the document. The specific performance is: If I want to index and query a data table named articles now, what else do I need to do? It's best to explain how to do each step. Thanks.

2. What do 'index', 'type' and 'body' mean?

3. If you don’t use mysql and use ES to save the index directly, what directory is the index file in by default?

I have just come into contact with es recently

es can correspond to a mysql database

The concept of index is equivalent to a library
The concept of type is equivalent to a table
Document is equivalent to a record

Then if you want to operate, you must first have a library and a table before you can add, delete, check and modify

How to index and search documents

Index files are stored as files under ES_HOME/data

You can go to the official website to find the jdbc plug-in for logstash, jdbc official documentation

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template