1. Go to this page and download the library: Download chenyuanqi/elasticsearch library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chenyuanqi / elasticsearch example snippets
'providers' => [
// elasticsearch service
chenyuanqi\elasticsearch\SearchServiceProvider::class,
],
$data = [
'name' => 'Kyyomi',
'age' => 18,
'birth' => '2017-03-03'
];
// However, you can set id for the record. For instance, "Search::insert($data, 1);"
Search::insert($data);
$data = [
'birth' => '1999-03-03'
];
// update by id
Search::updateById($data, 1);
// update by query
Search::queryString('name:"Kyyomi"')->update($data);
$data = [
'birth' => '1999-03-03'
];
// delete by id
Search::deleteById(1);
// delete by query, not support for version >2.0 (consider plugin: delete-by-query)
Search::queryString('name:"Kyyomi"')->delete();
Search::ids([1, 2, 3]);
// If other field with in or not in function
Search::whereIn('name', ['A', 'B', 'C']);
Search::whereNotIn('name', ['A', 'B', 'C']);
Search::where('id', '=', 100)->search();
// The same as last sentence
Search::where('id', 100)->search();
Search::where('id', '=', 100)->orWhere('age', '>=', 18)->search();
// Also, we can use like query
Search::where('name', 'like', '%天天%')->search();
// any more where function like whereBetween, whereNotBetween
Search::whereBetween('id', [1, 2]);
// paging style
Search::queryString('name:"珍珠海盗"')->limit(0, 10)->search();
// scroll style
Search::queryString('name:"珍珠海盗"')->scroll(1000, '30s', 'scan')->search();
// If you want use scroll id for search or delete it
Search::searchByScrollId('xxx');
Search::deleteByScrollId('xxx');
Search::queryString('name:"珍珠海盗"')->count();
Search::queryString('name:"珍珠海盗"')->search();
Search::debug();
// If you need curl sentence, do it
Search::toCurl();
use chenyuanqi\elasticsearch\Builder;
$search = new Builder(false);