1.安裝JDK ElasticSearch是用JAVA語言開發的,其運行需要安裝JDK。 JDK (Java Development Kit) ,是整個Java的核心,包括了Java運行環境(Java Runtime Envirnment),一堆Java工具和Java基礎的類庫(rt.jar)。 2 ...
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) }