分布式搜索引擎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 ...
随机推荐
- [麦先生]Laravel框架实现发送短信验证
今天在做到用户注册和个人中心的安全管理时,我借助实现第三方短信平台在Laravel框架中进行手机验证的设置; 由于我们做的是一个为客户提供医疗咨询和保健品网站,所以对客户个人隐私的保护显得尤为重要, ...
- 【温故而知新-Javascript】使用地理定位
地理定位(Geolocation)API让我们可以获取用户当前地理位置的信息(或者至少是正在运行浏览器的系统的位置).它不是HTML5规范的一部分,但经常被归组到与HTML5相关的新功能中. 1. 使 ...
- AngularJS Filters
过滤器可以使用一个管道字符(|)添加到表达式和指令中. AngularJS 过滤器 AngularJS 过滤器可用于转换数据: 过滤器 描述 currency 格式化数字为货币格式. filter 从 ...
- KSFramework常见问题:Excel如何进行SVN协作、差异比较?
Excel如何进行SVN协作.差异比较? 嗯,这是一个令人困惑的问题.游戏开发.程序开发时,使用Excel可以添加文档.注释.图标.批注等等各种辅助信息: 但是Excel是非纯文本格式,在使用SVN. ...
- 自动化工作之自动更新SVN
任务计划程序 任务计划程序是Window自带的组件 微软文档 http://windows.microsoft.com/zh-cn/windows-vista/automate-tasks-with- ...
- 关于PHP上传文件和中文名乱码情况
关于PHP文件上传 在前端HTML页面,表单如下 Upload.html <!doctype html><html lang="en"><head&g ...
- Netty Client重连实现
from:http://itindex.net/detail/54161-netty-client 当我们用Netty实现一个TCP client时,我们当然希望当连接断掉的时候Netty能够自动重连 ...
- Python的高级特性4:函数式编程
函数式编程的核心就是把函数当成对象来进行编程. 有两个常用到的方法:map/reduce,filter,其中map和filter是内建方法,而reduce不是,所以需要import相关模块. map接 ...
- 启动Eclipse后卡在 android sdk content loader 的解决办法
Make sure that eclipse is not active. If it is active kill eclipse from the processes tab of the tas ...
- 添加JSON Data到已经存在的JSON文件中
早上在学习<Post model至Web Api创建或是保存数据>http://www.cnblogs.com/insus/p/4343833.html ,如果你第二添加时,json文件得 ...