分布式全文搜索解决方案
1.安装jdk
elasticsearch是用java语言开发的,其运行需要安装jdk。
jdk (java development kit) ,是整个java的核心,包括了java运行环境(java runtime envirnment),一堆java工具和java基础的类库(rt.jar)。
2.安装
出现以上界面,则启动成功
2.1
github托管地址:
npm install
启动:打开命令行,切换到elasticsearch-head目录,执行以下命令
npm run start
由于跨域(elasticsearch位于9200端口),需要添加配置: e:\elasticsearch-7.1.0\config\elasticsearch.yml中
#新添加的配置行 http.cors.enabled: true http.cors.allow-origin: "*"
2.2
在项目目录下,执行以下命令
composer require elasticsearch/elasticsearch
配置php.ini的sys_temp_dir
单个 elastic 实例称为一个节点(node)。一组节点构成一个集群(cluster)。
在elasticsearch中,文档归属于一种类型(type),而这些类型存在于索引(index)中类比传统关系型数据库:
relational db -> databases -> tables -> rows -> columns elasticsearch -> indices -> types -> documents -> fields
每一个索引可以包含多个类型(types)(表)
每一个类型包含多个文档(documents)(行)
然后每个文档包含多个字段(fields)(列)。
$es = \elasticsearch\clientbuilder::create()->sethosts(['127.0.0.1:9200'])->build(); $params = [ 'index' => 'test_index' ]; $r = $es->indices()->create($params); dump($r);die;
预期结果:
array(3) { ["acknowledged"] => bool(true) ["shards_acknowledged"] => bool(true) ["index"] => string(10) "test_index" }
3
$es = \elasticsearch\clientbuilder::create()->sethosts(['127.0.0.1:9200'])->build(); $params = [ 'index' => 'test_index', 'type' => 'test_type', 'id' => 100, 'body' => ['id'=>100, 'title'=>'php从入门到精通', 'author' => '张三'] ]; $r = $es->index($params); dump($r);die;
预期结果:
array(8) { ["_index"] => string(10) "test_index" ["_type"] => string(9) "test_type" ["_id"] => string(3) "100" ["_version"] => int(1) ["result"] => string(7) "created" ["_shards"] => array(3) { ["total"] => int(2) ["successful"] => int(1) ["failed"] => int(0) } ["_seq_no"] => int(0) ["_primary_term"] => int(1) }
$es = \elasticsearch\clientbuilder::create()->sethosts(['127.0.0.1:9200'])->build(); $params = [ 'index' => 'test_index', 'type' => 'test_type', 'id' => 100, 'body' => [ 'doc' => ['id'=>100, 'title'=>'es从入门到精通', 'author' => '张三'] ] ]; $r = $es->update($params); dump($r);die;
预期结果:
array(8) { ["_index"] => string(10) "test_index" ["_type"] => string(9) "test_type" ["_id"] => string(3) "100" ["_version"] => int(2) ["result"] => string(7) "updated" ["_shards"] => array(3) { ["total"] => int(2) ["successful"] => int(1) ["failed"] => int(0) } ["_seq_no"] => int(1) ["_primary_term"] => int(1) }
$es = \elasticsearch\clientbuilder::create()->sethosts(['127.0.0.1:9200'])->build(); $params = [ 'index' => 'test_index', 'type' => 'test_type', 'id' => 100, ]; $r = $es->delete($params); dump($r);die;
预期结果:
array(8) { ["_index"] => string(10) "test_index" ["_type"] => string(9) "test_type" ["_id"] => string(3) "100" ["_version"] => int(3) ["result"] => string(7) "deleted" ["_shards"] => array(3) { ["total"] => int(2) ["successful"] => int(1) ["failed"] => int(0) } ["_seq_no"] => int(2) ["_primary_term"] => int(1) }
上一篇: 星露谷蕨菜,蕨菜才是重点