centos下elasticsearch elasticsearch-php安装


Elasticsearch是一个建立在全文搜索引擎Apache Lucene(TM)基础上的搜索引擎,可以说 Lucene是当今最先进,最高效的全功能开源搜索引擎框架
查找相关文章:centos elasticsearch php

最近在了解elasticsearch,因此记录以下安装记录

elasticsearch 2.0需要php 5.4以上版本

安装jdk

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u65-b17/jdk-8u65-linux-x64.rpm"

sudo yum localinstall jdk-8u65-linux-x64.rpm


安装elasticsearch

sudo rpm --import http://packages.elastic.co/GPG-KEY-elasticsearch
sudo vi /etc/yum.repos.d/elasticsearch.repo

加入如下内容

[elasticsearch-2.0]
name=Elasticsearch repository for 2.x packages
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
sudo yum -y install elasticsearch
sudo vi /etc/elasticsearch/elasticsearch.yml

修改如下内容

network.host: localhost
http.port: 9200


启动elasticsearch

service elasticsearch start

测试一下

curl http://localhost:9200

如果出现类似这样的结果说明安装成功了

{
  "name" : "Hellfire",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.0.0",
    "build_hash" : "de54438d6af8f9340d50c5c786151783ce7d6be5",
    "build_timestamp" : "2015-10-22T08:09:48Z",
    "build_snapshot" : false,
    "lucene_version" : "5.2.1"
  },
  "tagline" : "You Know, for Search"
}


安装php sdk

vi composer.json

加入如下内容

{
    "require": {
        "elasticsearch/elasticsearch": "~2.0@beta"
    }
}

执行安装

curl -s http://getcomposer.org/installer | php
php composer.phar install --no-dev


测试一下php调用

<?php
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
#$client = \Elasticsearch\ClientBuilder::create()->build();
$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
    'body' => ['testField' => 'abc']
];
$response = $client->index($params);
print_r($response);


更多的使用参考官方网站和这里

https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html

https://github.com/elastic/elasticsearch-php


感谢

https://www.digitalocean.com/community/tutorials/how-to-install-elasticsearch-logstash-and-kibana-elk-stack-on-centos-7


中文文档

https://www.gitbook.com/book/fuxiaopang/learnelasticsearch/details 

http://learnes.net/