elasticsearch-build-query

对Elasticsearch-PHP进行查询语句封装 可实现链式调用 方便 es查询

Installation via Composer

The recommended method to install ielongphp/es-build-query is through Composer.

Add tielongphp/es-build-query as a dependency in your project's composer.json file (change version to suit your version of tielongphp/es-build-query, for instance for ^1.0):

{

"require": {

"tielongphp/es-build-query": "^1.0",

}

}

Download and install Composer:

curl -s http://getcomposer.org/installer | php

Install your dependencies:

php composer.phar install

Require Composer's autoloader

Composer also prepares an autoload file that's capable of autoloading all the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process:

use EsBuildQuery\EsBuildQuery;

require 'vendor/autoload.php';

$config = '127.0.0.1:9200'

$elasticSearch = new EsBuildQuery($config);

You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at getcomposer.org.

Documentation && Quickstart

example:

1、

$elasticSearch = new \EsBuildQuery\EsBuildQuery("127.0.1.1:9200");

$config = [

'indexName' => '_indexName',

'indexType' => '_typeName'

];

$attrWhere['must'][]['range']['@timestamp'] = [

'gt' => strtotime('2019-01-01').'000',

'lte' => strtotime('2019-01-02').'000',

'format' => "epoch_millis"

];

//精确匹配:requestUri = '/a/b/c'

$attrWhere['must'][]['match']['requestUri'] = '/a/b/c';

$attList = $elasticSearch->_set($config)

->where($attrWhere)

->limit(20, 0)

->fields(['requestUri','apiStart'])

->select();

相当于SQl:

selsect requestUri,apiStart from tableName where @timestamp > ? and @timestamp<= ?

and requestUri = '/a/b/c' LIMIT 20

2、

// 正则查询:排除request 中带后缀名的 如.jpg、.js等

$commonWhere['must'][]['regexp']['request.keyword'] = '/*([^.]*)';// /*([^.]*?)

// 模糊匹配查询:只查询域名字段domain中包含XXX的数据

$commonWhere['must'][]['query_string'] = [

'query' => 'domain:*XXX*',

"analyze_wildcard" => true,

"default_field" => "*"

];

// group 分组查询

$arrList = $elasticSearch->_set($config)

->where($commonWhere)

->group("domain.keyword")

->select();

3、Some examples of where conditions

//可以实现模糊匹配查询:类似于 myql的like %/json%

$where['must'][]['match_phrase']['request']['query'] = '/json';

// apiGwResSign === 'amendments'

$where['must'][]['match']['apiGwResSign'] = 'amendments';

// request 不包含 '/nbig'

$where['must_not'][]['match_phrase']['request']['query'] = '/nbig';

....

4、The methods that the EsBuildQuery class can use are as follows

/**

* 设置参数

* @param array $config

* 配置

* array(

* 'indexName'=>'索引名称',

* 'indexType'=>'索引类型',

* 'numberOfShards'=>'主分片数量',

* 'numberOfReplicas'=>'从分片数量',

* 'mapping'=>'过滤器'

* )

*/

public function _set($config)

/**

* 创建索引

* 调用_set()方法完成赋值

* @author wen

* @param string $this ->indexName

* 索引名称

* @param int $this ->numberOfShards

* 主分片数量

* @param int $this ->numberOfReplicas

* 从分片数量

* @return bool

*/

public function createIndex()

/**

* 检测索引是否存在

* @author wen

* @param string $this ->indexName

* 索引名称

* @return bool

*/

public function checkIndex()

/**

* 插入索引数据

* 调用_set()方法完成赋值

* @author wen

* @param string $this ->indexName

* 索引名称

* @param string $this ->indexType

* 索引类型

* @param array $data

* 数据 array('字段1'=>'值1', '字段2'=>'值2' ...)

* @return bool|array

*/

public function add($data)

/**

* 判断索引数据是否存在

* 调用_set()方法完成赋值

* @author wen

* @param string $this ->indexName

* 索引名称

* @param string $this ->indexType

* 索引类型

* @param string $this ->documentId

* 文档id

* @return bool|array

*/

public function exists()

/**

* 获取索引数据

* 调用_set()方法完成赋值

* @author wen

* @param string $this ->indexName

* 索引名称

* @param string $this ->indexType

* 索引类型

* @param string $this ->documentId

* 文档id

* @return bool|array

*/

public function find()

/**

* 查询条件方法

* @author wen

* @param array $where

* 查询条件

* // must :: 多个查询条件的完全匹配,相当于 and。

// must_not :: 多个查询条件的相反匹配,相当于 not。

// should :: 至少有一个查询条件匹配, 相当于 or。

// term主要用于精确匹配哪些值

// terms 跟 term 有点类似,但 terms 允许指定多个匹配条件。 如果某个字段指定了多个值,那么文档需要一起去做匹配

// multi_match 同意内容搜索多个字段

// range 比较 gt gte lt lte

*/

public function where($where)

/**

* 数据分组

* @author wen

* @param string|array $group

* 字段名|聚合条件

*/

public function group($group)

/**

* 指定字段

* @author wen

* @param string|array $fields

* 字段

* 例:id,name

* 例:['id','name')

*/

public function fields($fields)

/**

* 数据排序

* @author wen

* @param string|array $sort

* 排序 最好是用数字类的进行排序

* 例:price:asc,time:desc

*/

public function order($sort)

/**

* 数据分页

* @author wen

* @param int $size

* 分页条数

* @param int $from

* 分页开始位置

*/

public function limit($size = 10, $from = 0)

/**

* 数据分页-深度

* @author wen

* @param string $time

* 查询时间

* @param int $size

* 分页条数

*/

public function scroll($size = 10, $time = "30s")

/**

* scroll_id 数据分页-深度第二页及以后需要的参数

* @author wen

* @param string $scroll_id

* 第一次请求或之后请求时得到的scroll_id

*/

public function scrollId($scroll_id)

/**

* 索引数据 统计

* @author wen

*/

public function count()

/**

* 高亮显示

* @author wen

* @param array $filedArr

* 需要高亮的字段 例 array('name', 'summary')

* @param string $pre_tags

* 开始标签

* @param string $post_tags

* 结束标签

*/

public function highlight($filedArr, $pre_tags = '', $post_tags = '')

/**

* 获取索引数据

* 调用_set()方法完成赋值

* @author wen

* @param string $this ->indexName

* 索引名称

* @param string $this ->indexType

* 索引类型

* @return bool|array

*/

public function select()

/**

* 修改索引数据

* 调用_set()方法完成赋值

* @author wen

* @param string $this ->indexName

* 索引名称

* @param string $this ->indexType

* 索引类型

* @param string $this ->documentId

* 文档id

* @param array $data

* 要修改的数据 必须保证数据字段和添加时全部对应 ['字段1'=>'值1', '字段2'=>'值2' ...]

* @return bool|array

*/

public function save($data)

/**

* 删除索引数据

* 调用_set()方法完成赋值

* @author wen

* @param string $this ->indexName

* 索引名称

* @param string $this ->indexType

* 索引类型

* @param string $this ->documentId

* 文档id

* @return bool

*/

public function delete()

/**

* 删除索引

* 调用_set()方法完成赋值

* @author wen

* @param string $this ->indexName

* 索引名称

* @return bool

*/

public function deleteIndex()

php拉查询封装,对Elasticsearch-PHP进行查询语句封装 可实现链式调用 方便 es查询...相关推荐

  1. docker安装es+mac安装Kibana工具+es查询语法笔记

    一.docker安装es 1.下载镜像 docker pull elasticsearch:7.9.0 下载完后,查看镜像 docker images ​​ 2.启动镜像 docker network ...

  2. elasticsearch RestHighLevelClient 使用方法及封装工具

    目录 EsClientRHL 更新日志 开发原因: 使用前你应该具有哪些技能 工具功能范围介绍 工具源码结构介绍 开始使用 未来规划 git地址:https://gitee.com/zxporz/ES ...

  3. es查询语句拼接 java_JAVA使用ElasticSearch查询in和not in的实现方式

    JAVA使用ElasticSearch查询in和not in的实现方式 发布时间:2020-08-22 16:03:11 来源:脚本之家 阅读:119 作者:执笔记忆的空白 ElasticSearch ...

  4. 《深入理解Elasticsearch(原书第2版)》一2.2 查询改写

    本节书摘来自华章出版社<深入理解Elasticsearch(原书第2版)>一书中的第2章,第2.2节,作者[美]拉斐尔·酷奇(Rafal Ku) 马雷克·罗戈任斯基(Marek Rogoz ...

  5. Elasticsearch在docker下安装运行,ES查询、分词器

    目录 Elasticsearch的一点背景 数据输入 数据输出 集群 集群灾备 集群管理 Docker容器中运行ElasticSearch.Kibana.cerebro ElasticSearch K ...

  6. MySQL 慢查询日志导入 Elasticsearch 可视化查询分析

    当应用程序后台 SQL 查询慢的时候我们一般第一时间会查看数据库慢查询记录,但是慢查询记录是原始文本,直接查询搜索分析比较费时费力,虽然业界有针对 MySQL 慢查询分析的命令行工具(比如:pt-qu ...

  7. php kibana查询,Kibana+Logstash+Elasticsearch 日志查询系统搭建

    搭建该日志查询系统的目的就是为了运维.研发很方便的进行日志的查询.Kibana一个免费的web壳:Logstash集成各种收集日志插件,还是一个比较优秀的正则切割日志工具:Elasticsearch一 ...

  8. ElasticSearch 6.3版本(ES)查询人名关键字不拆词查询

    ElasticSearch 6.3版本(ES)查询关键字不拆词查询:类似mysql 的 like 语句. mysql的sql语法类似如下,采用大量like和locate语法,进行模糊查询,导致查询一个 ...

  9. 【236期】ElasticSearch 进阶:一文全览各种 ES 查询在 Java 中的实现

    点击上方"Java精选",选择"设为星标" 别问别人为什么,多问自己凭什么! 下方有惊喜,留言必回,有问必答! 每天 08:15 更新文章,每天进步一点点... ...

最新文章

  1. 7.10 数据注解特性--NotMapped
  2. 《自然语言处理中的因果推理》综述论文,以色列理工谷歌等13位NLP大牛阐述因果推理NLP的估计、预测、解释和超越...
  3. DataGridView使用技巧十一:DataGridView用户输入时,单元格输入值的设定
  4. 求求你别在用IF ELSE校验参数了
  5. springboot单例模式注入对象_springboot 请求流程简介
  6. python int64,如何从Python生成唯一的64位整数?
  7. dedecms提取某栏目及子栏目名称到首页怎么弄
  8. Oracle的reman命令
  9. System.arraycopy详解
  10. 俄罗斯方块---九宫格版
  11. 如何快速进入一个陌生的领域,高手通常用这三步
  12. C#语言和数据库基础
  13. RoboWare Studio安装教程
  14. 实验用USB转RS-232下载线制作
  15. 计算机办公操作excel,办公中常用的Word及Excel的方法有哪些
  16. 瑞幸的“快”与连咖啡的“慢”
  17. 用Rdkit把化学结构式的Smiles转换为InchI
  18. 程序员所使用的各种软件分享及破解
  19. 移动硬盘 无法读取 插入电脑没反应 无法识别 怎么办
  20. 美元汇率Pascal题解

热门文章

  1. 行尸走肉android手机版下载地址,行尸走肉无人之地手机版下载_行尸走肉无人之地手机版安卓下载2021_求知软件网...
  2. 资本扎堆?自动驾驶“梦幻开局”
  3. 接口--多态(向上造型--向下造型)
  4. 十一假期,小灰送书!
  5. 云原生应用架构中的文化变革 一:秉承精益制造之魂,启行 DevOps 之路!
  6. 流量红利已经耗尽?这几本书带你玩转电商各路技巧
  7. 2022南京公积金贷款提前还款
  8. 中望软件华东区技术部经理尚飞:中望设计云与制造大数据解决方案
  9. 5G商用助力,2022年物联网终端将达180亿个
  10. java excel 分页合并,excel分页-Excel办公技巧——完整显示跨页合并的单元格