Elasticsearch PHP API (https://www.elastic.co/guide/en/elasticsearch/client/php-api/index.html)
PHP API: 1.0 (current) 사용
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_quickstart.html 보시면 간단하게 설치및 사용법 나옵니다.
1. 설치
PHP 5.3.9 이상
1) composer.json 파일 생성
{
"require": {
"elasticsearch/elasticsearch": "~1.0"
}
}
2) composer 설치
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install
2. 인덱싱
insert.php
<?
require 'vendor/autoload.php'; $client = new Elasticsearch\Client();
$params = array ();
$params [ 'body' ] = array ( 'title' => '기사제목', 'media' => '매체명', 'link' => 'http://news~~~' );
$params [ 'index' ] = '인덱스명' ;
$params [ 'type' ] = '타입명' ;
$params [ 'id' ] = '문서ID' ;
$ret = $client -> index ( $params );?>
3. 검색
search.php
<?
require 'vendor/autoload.php'; $client = new Elasticsearch\Client();
$params['body'] = array(
'query' => array(
'multi_match' => array(
'fields' => array('title', 'media'),
'query' => '검색어'
)
)
);
$results = $client->search($params);
print_r($results);
?>
'Elasticsearch' 카테고리의 다른 글
[Elasticsearch-PHP] 검색 (0) | 2015.08.27 |
---|---|
[Elasticsearch] 한글 분석기를 이용한 실전 인덱싱 & 검색 (0) | 2015.08.25 |
[Elasticsearch] 한글 형태소 분석기 은전한잎 설치 (0) | 2015.08.21 |
[Elasticsearch] 엘라스틱서치 데이터 입력 (0) | 2015.08.20 |
[Elasticsearch] 엘라스틱서치 설치 (0) | 2015.08.19 |