分布式搜索引擎Elasticsearch PHP类封装 使用原生api
- //官方的 php api写的鸡肋了,下面这个类可以使用 es api 操作.
- <?php
- class ElasticSearch {
- public $index;
- function __construct($server = 'http://localhost:9200'){
- $this->server = $server;
- }
- function call($path, $http = array()){
- if (!$this->index) throw new Exception('$this->index needs a value');
- return json_decode(file_get_contents($this->server . '/' . $this->index . '/' . $path, NULL, stream_context_create(array('http' => $http))));
- }
- //curl -X PUT http://localhost:9200/{INDEX}/
- function create(){
- $this->call(NULL, array('method' => 'PUT'));
- }
- //curl -X DELETE http://localhost:9200/{INDEX}/
- function drop(){
- $this->call(NULL, array('method' => 'DELETE'));
- }
- //curl -X GET http://localhost:9200/{INDEX}/_status
- function status(){
- return $this->call('_status');
- }
- //curl -X GET http://localhost:9200/{INDEX}/{TYPE}/_count -d {matchAll:{}}
- function count($type){
- return $this->call($type . '/_count', array('method' => 'GET', 'content' => '{ matchAll:{} }'));
- }
- //curl -X PUT http://localhost:9200/{INDEX}/{TYPE}/_mapping -d ...
- function map($type, $data){
- return $this->call($type . '/_mapping', array('method' => 'PUT', 'content' => $data));
- }
- //curl -X PUT http://localhost:9200/{INDEX}/{TYPE}/{ID} -d ...
- function add($type, $id, $data){
- return $this->call($type . '/' . $id, array('method' => 'PUT', 'content' => $data));
- }
- //curl -X GET http://localhost:9200/{INDEX}/{TYPE}/_search?q= ...
- function query($type, $q){
- return $this->call($type . '/_search?' . http_build_query(array('q' => $q)));
- }
- }
分布式搜索引擎Elasticsearch PHP类封装 使用原生api的更多相关文章
- 分布式搜索引擎Elasticsearch在CentOS7中的安装
1. 概述 随着企业业务量的不断增大,业务数据随之增加,传统的基于关系型数据库的搜索已经不能满足需要. 在关系型数据库中搜索,只能支持简单的关键字搜索,做不到分词和统计的功能,而且当单表数据量到达上百 ...
- ElasticSearch logo 分布式搜索引擎 ElasticSearch
原文来自:http://www.oschina.net/p/elasticsearch Elastic Search 是一个基于Lucene构建的开源,分布式,RESTful搜索引擎.设计用于云计算中 ...
- 分布式搜索引擎Elasticsearch的简单使用
官方网址:https://www.elastic.co/products/elasticsearch/ 一.特性 1.支持中文分词 2.支持多种数据源的全文检索引擎 3.分布式 4.基于lucene的 ...
- 快速掌握分布式搜索引擎ElasticSearch(一)
前言 由于最近在项目中接触使用到了ElasticSearch,从本篇博客开始将给大家分享这款风靡全球的产品.将涉及到ElasticSearch的安装.基础概念.基本用法.高级查询.中文分词器.与Spr ...
- 分布式搜索引擎Elasticsearch的架构分析
一.写在前面 ES(Elasticsearch下文统一称为ES)越来越多的企业在业务场景是使用ES存储自己的非结构化数据,例如电商业务实现商品站内搜索,数据指标分析,日志分析等,ES作为传统关系型数据 ...
- 分布式搜索引擎Elasticsearch性能优化与配置
1.内存优化 在bin/elasticsearch.in.sh中进行配置 修改配置项为尽量大的内存: ES_MIN_MEM=8g ES_MAX_MEM=8g 两者最好改成一样的,否则容易引发长时间GC ...
- 分布式搜索引擎ElasticSearch+Kibana (Marvel插件安装详解)
在安装插件的过程中,尤其是安装Marvel插件遇到了很多问题,要下载license.Marvel-agent,又要下载安装Kibana 版本需求 Java 7 or later Elasticsear ...
- 分布式搜索引擎Elasticsearch的查询与过滤
一.写入 先来一个简单的官方例子,插入的参数为-XPUT,插入一条记录. curl -XPUT 'http://localhost:9200/test/users/1' -d '{ "use ...
- ElasticSearch 工具类封装(基于ElasticsearchTemplate)
1.抽象接口定义 public abstract class SearchQueryEngine<T> { @Autowired protected ElasticsearchTempla ...
随机推荐
- Machine Learning Algorithms Study Notes(4)—无监督学习(unsupervised learning)
1 Unsupervised Learning 1.1 k-means clustering algorithm 1.1.1 算法思想 1.1.2 k-means的不足之处 1 ...
- NOIP2006金明的预算方案[DP 有依赖的背包问题]
题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过N元钱就行”.今 ...
- Prefab Assist插件
资料 Prefab文档: http://game.ceeger.com/Manual/Prefabs.html 基础:基于NGUI制作组件的Prefab 前言 在一个游戏的UI中,有一些通用的组件,比 ...
- MVC调用SVC无法找到资源解决问题
webconfig配置下就可以,但MVC当中老是报错 404 not found.解决办法: routes.IgnoreRoute("{resource}.svc/{*pathInfo}&q ...
- 初识hibernate框架之一:进行简单的增删改查操作
Hibernate的优势 l 优秀的Java 持久化层解决方案 (DAO) l 主流的对象—关系映射工具产品 l 简化了JDBC 繁琐的编码 l 将数据库的连接信息都存放在配置文件 l 自己的ORM ...
- iOS中NSScanner 的用法
NSScanner是一个类,用于在字符串中扫描指定的字符,尤其是把它们翻译/转换为数字和别的字符串.可以创建NSScanner时制定他的String属性,然后scanner会按照你的要求从头到尾扫描这 ...
- ie 7/8不支持trim的属性的解决方案
if(!('trim' in String.prototype)){ String.prototype.trim = function(){ return this.replace(/^[\s\uFE ...
- Activity 与 Service 之间的消息传递
BgService代码 public class BgService extends Service { public static final String TAG = "BgServic ...
- Centos5.8 安装openvpn
安装openssl 和 openssl-devel, 建议使用最新版本, 编译安装 yum install gcc-c++ wget http://www.openssl.org/source/ope ...
- IO操作总结
1,读取文件将文件转换为二进制流 InputStream in = new FileInputStream("C:/test.png"); byte[] photo = new b ...