Home

elasticsearch 安装相关资料

安装elasticsearch相关资料

https://repo.huaweicloud.com/java/jdk/8u151-b12/

https://repo.huaweicloud.com/elasticsearch/6.4.0/


export PATH="/home/jdk1.8.0_151/bin:$PATH" CLASSPATH="/home/jdk1.8.0_151/lib:."

JAVA_HOME="/home/jdk1.8.0_151/"

jvm.options

https://www.cnblogs.com/gwyy/p/12205245.html


vim /etc/security/limits.conf
elsearch hard nofile 65536
elsearch soft nofile 65536

supervisor运行elasticsearch

[program:elas]
command=/home/elasticsearch-6.4.0/bin/elasticsearch
directory=/home/elasticsearch-6.4.0/bin/
autorestart=true
startsecs=13
startretries=1
environment=JAVA_HOME=/home/jdk1.8.0_151
stdout_logfile=/www/server/panel/plugin/supervisor/log/elas.out.log
stderr_logfile=/www/server/panel/plugin/supervisor/log/elas.err.log
stdout_logfile_maxbytes=2MB
stderr_logfile_maxbytes=2MB
user=elsearch
priority=999
numprocs=1
process_name=%(program_name)s_%(process_num)02d

php 搜索elasticsearch

composer require elasticsearch/elasticsearch

搜索

         $client = ClientBuilder::create()->setHosts(['192.168.0.154'])->build();
        $params = [
            'index' => 'goods_index',
            'type' => 'goods_type',
            'body' => [
                'size' => $size,
                'from' => $from,
                'min_score' => 0.5,
                'query' => [
                    'bool' => [
                        'filter' => [
                            'term' => [ 'goods_status' => 10 ]
                        ],
                        'should' => [
                            'match' => [ 'goods_name' => $search ]
                        ]
                    ]
                ]
            ]
        ];
        $response = $client->search($params);

新增修改与删除

//删除索引
$params = ['index' => 'goods_index'];
$client->indices()->delete($params);


$client = ClientBuilder::create()->setHosts(['192.168.0.154'])->build();
        Goods::event('after_insert',function ($item) use ($client) {            
            $params = [
                'index' => 'goods_index',
                'type' => 'goods_type',
                'id' => $item->goods_id,
                'body' => [
                    'goods_name' => $item->goods_name,                    
                    'goods_status' => $item->goods_status["value"],
                    'is_delete' => 0
                ]
            ];
            $client->index($params);
        });
        Goods::event('after_update',function ($item) use ($client) {
            $params = [
                'index' => 'goods_index',
                'type' => 'goods_type',
                'id' => $item->goods_id,
                'body' => [
                    'doc' => [
                        'goods_name' => $item->goods_name,                    
                        'goods_status' => $item->goods_status['value'],
                        'is_delete' => $item->is_delete
                    ]
                ]
            ];
            $client->update($params);            
        });
        Goods::event('after_delete',function ($item) use ($client) {
            $params = [
                'index' => 'goods_index',
                'type' => 'goods_type',
                'id' => $item->goods_id,                
            ];
            $client->delete($params);            
        });