Skip to content

GeekGhc/es-scout

Repository files navigation

Laravel-Elasticsearch

Laravel集成Elasticsearch6进行全文搜索并配合高亮结果显示

首先先集成Java环境 具体参考这篇文章

安装过java环境后可以 执行java --version查看

java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

下载es压缩包

$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.3.zip

解压后 进入解压后文件夹启动

$ ./bin/elasticsearch

安装完毕后 配置并迁移数据库

使用thinker生成post测试数据

使用scout导入集群

php artisan scout:import "App\Post"

查看ES索引情况

$ curl -X GET 'localhost:9200/_cat/indices?v&pretty'

高亮配置参考请求方式(具体配置在App/Libraries/EsEngine 可自定义)

curl -X POST 'localhost:9200/scout/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "query": { "match": { "title" : "your key" } },
  "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
          "title": {}
        }
    }
}'

访问http://es-scout.example/search

1.gif

Releases

No releases published

Packages

No packages published