Laravel5.3+Scout+ElasticSearch5.0
System environment
Ubuntu16.04, ElasticSearch5.0, JDK1.8
ElasticSearch5.0
There is no point in installing es5.0. As long as you follow the official document process, you can usually install it successfully and run it successfully.
But it is online Environment, others are still using es2.4. Firstly, the project is larger, and secondly, different versions of jdk have different memory requirements.
And after es5.0, due to the cancellation of site-plugin, many plug-ins cannot follow the It was installed in the previous way. For example, elasticSearch-head is very commonly used, and now it needs to be run through Grunt. Or other plug-ins are put into the www directory of Nginx or Apache to run.
Small problems that may occur after installation:
$JAVA_HOME cannot be found , but it is indeed installed. You can set the /etc/default/elasticsearch file and find JAVA_HOME=/usr/local/java/jdk1.8.0_101/jre;
Don’t install it if the environment memory is too small, es5.0 takes up almost I have 2.5G of memory. Of course, most people’s computers now have quite a lot of memory;
Install and configure Laravel/Scout
Add these three lines at the bottom of the .env file
SCOUT_DRIVER=customElasticSearch ELASTICSEARCH_INDEX=box ELASTICSEARCH_HOST=localhost:9200
These three lines of configuration are used by Scout to determine your Which Engine to use, and the address of the search engine.
Readers may find that my Driver is customElasticSearch, not elasticsearch.
Because when you open ElasticSearchEngine and find performSearch Method, you will find this piece of code inside
$query = [ 'index' => $this->index, 'type' => $builder->model->searchableAs(), 'body' => [ 'query' => [ 'filtered' => [ 'filter' => $filters, 'query' => [ 'bool' => [ 'must' => $matches ] ], ], ], ], ];
If you run search Method directly, you will be told that filtered has been cancelled. For details, see the official website address.
But you can’t directly change the package code. Fortunately, Scout provides a custom Engine.
So we create a new customElasticSearchEngine , inherit elasticSearchEngine, and rewrite performSearch Method. In it, I modified two places,
这只是演示, 要真使用以后一定要改 $matches[] = [ 'match' => [ '字段名' => $builder->query ] ];
$query = [ 'index' => $this->index, 'type' => $builder->model->searchableAs(), 'body' => [ 'query' => [ 'bool' => [ 'filter' => $filters, 'must' => $matches, ], ], ], ];
Possible pitfalls of using Scout
If you have a field with a primary key auto-incremented and named id in the database table, but you don’t If you want elasticSearch to use the id of the data table to serve as the id of es' Document, then you need to change the $primaryKey of the model and public $incrementing = false;, so that you can specify other values of the current data table to serve as the id of es. If es's Part of the data_id is the database id, and the other part is newly specified by you, which will affect your search and other operations.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
