Download the PHP package inkime/elasticsearch-query-builder without Composer

On this page you can find all versions of the php package inkime/elasticsearch-query-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package elasticsearch-query-builder

ES网关查询生成器

提供了更贴近Yii2模型操作的API来查询ES网关数据

Latest Stable Version Total Downloads License PHP Version Require

Composer安装:

composer require inkime/elasticsearch-query-builder

支持API如下:

自定义日志操作:

常规查询

$result = EsModel::find()->index('wx')->query();
$count = $result['count'];
$list = $result['list'];

单条记录

EsModel::find()->index('wx')->one();

多条记录

EsModel::find()->index('wx')->offset(0)->limit(10)->all();

获取总数

EsModel::find()->index('weibo')->offset(0)->limit(5)->count();

exists

EsModel::find()->index('wx')->where(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'])->exists();

index

可任意切换索引库,如wx/weibo等
EsModel::find()->index('wx')->one();

select / addSelect

指定查询字段,支持追加操作,参数支持数组或字符串 #逗号分割
EsModel::find()->index('wx')->select('news_uuid')->addSelect(['news_title', 'news_sim_hash'])->one();

aggs / addAggs

注意:只能用query查询
EsModel::find()->index('wx')
->select('news_uuid,news_title,news_posttime,platform')
->aggs('platformCount', 'terms', ['field' => 'platform', 'size' => 3, 'order' => ['_count' => 'asc']])
->addAggs('dateDayCount', 'date_histogram', 
      ['field' => 'news_posttime', 'interval' => 'day', 'format' => 'yyyy-MM-dd', 'min_doc_count' => 0])
->limit(5)
->query();

aggregations

自定义聚合查询
EsModel::find()->index('wx')->select('news_is_origin')
->addSelect(['news_reposts_count', 'news_comment_count', 'news_like_count'])
->aggregations([
    'group' => [
        "terms" => ["field" => 'news_is_origin']
    ],
    'aggs' => [
        'news_reposts_count' => ['sum' => ['field' => 'news_reposts_count']],
        'news_comment_count' => ['sum' => ['field' => 'news_comment_count']],
        'news_like_count' => ['sum' => ['field' => 'news_like_count']],
    ]
])
->limit(2)
->query();

indexBy

EsModel::find()->index('wx')->select('news_uuid')->indexBy('news_uuid')->limit(5)->all();
支持匿名函数
$field = 'news_uuid';
$secretStr = 'qingbo#$%t2000';
EsModel::find()->index('wx')->select($field)->indexBy(function($v) use ($field, $secretStr) { 
    // $v 表示每条记录
    return $v[$field] . $secretStr;
})->limit(5)->all();

dsl

输出DSL语句,支持json/array两种格式,默认json
EsModel::find()->index('wx')->select('news_uuid')
->where(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'])->dsl()
->one();

map

自定义DSL语句,map或者addMap操作仅仅支持bool查询,bool键名支持省略
例如:['must' => [['match' => ['news_title' => '补贴']]]]
系统会补全:['bool' => ['must' => [['match' => ['news_title' => '补贴']]]]]
使用1:
EsModel::find()->index('wx')->select('news_is_origin')->addSelect('news_uuid')
->where(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'])
->map([
    'bool' => [
        'filter' => [
            'exists' => ['field' => 'news_is_origin']
        ]
    ]
]) // 自定义DSL
->one();
使用2,支持匿名函数:
$esModel->andWhere(['not', ['media_name' => '']])->map(function () use ($index) {
     return ['must' => [['term' => ['news_uuid' => $index . '0adb6d83ab00b225c370c0e957f658a8']]]];
})

addMap

自定义DSL语句
EsModel::find()->index('wx')->select('news_title,news_uuid')
->where(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'])
->addMap(['must' => [['match' => ['news_title' => '补贴']]]])
->query();

highlight

自定义高亮配置
public static function highLight($fields = [], $pre_tags = '<em>', $post_tags = '</em>')
{
    $newFieldsArr = [];
    foreach ($fields as $field) {
        $newFieldsArr[$field] = ['number_of_fragments' => 0];
    }
    return [
        "require_field_match" => false,
        "pre_tags" => [
            $pre_tags
        ],
        "post_tags" => [
            $post_tags
        ],
        "fields" => $newFieldsArr
    ];
}
EsModel::find()->index('wx')->select('news_title')->addSelect('news_uuid')
->where(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'])
->highlight(EsModel::highLight([$field])) // 高亮配置
->query(); // 仅支持query查询

collapse

EsModel::find()->index('wx')->select('news_uuid')->collapse('news_title')
->where(['media_name' => '城镇城镇交费'])->all();

where查询

EsModel::find()->index('wx')->select('news_uuid')
->where(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'])->one();

whereNot

EsModel::find()->index('wx')->select('news_uuid')
->where([
    'not', 
    ['news_uuid' => ['b15e02a0bddacc0ee61d51d36d0022eb', 'e698094102c12deb978e35617e72b633']]
])->one();

whereAnd

EsModel::find()->index('wx')->select('news_uuid,media_name')
->where(['and', ['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb','media_name' => '城镇城镇交费']])
->one();

whereOr

EsModel::find()->index('wx')->select('news_uuid')
->where(['or', ['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'], ['media_name' => '城镇城镇交费']])
->one();

whereBetween

EsModel::find()->index('wx')->select('news_is_origin')->where(['between', 'news_is_origin', 0, 1])
->one();

whereNotBetween

EsModel::find()->index('wx')->select('news_is_origin')
->where(['not between', 'news_comment_count', 10, 100])->one();

whereIn

EsModel::find()->index('wx')->select('media_name')
->where(['in', 'media_name', ['爆笑短片', '智慧人生', '', null]])->one();

whereNotIn

EsModel::find()->index('wx')->select('media_name')
->where(['not in', 'media_name', ['爆笑短片', '智慧人生', '', null]])->one();

whereRange

EsModel::find()->index('wx')->select('news_postweek_day')->where(['<', 'news_postweek_day', 3])
->orderBy('news_postweek_day desc')->one();
这里操作符支持:<、lt、<=、lte、>、gt、>=、gte

andWhere

EsModel::find()->index('wx')->select('news_uuid,media_name')
->where(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'])
->andWhere(['media_name' => '城镇城镇交费'])->one();

orWhere

EsModel::find()->index('wx')->select('news_uuid,media_name')
->where(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'])
->orWhere(['media_name' => '城镇城镇交费'])->one();

filterWhere

EsModel::find()->index('wx')->select('news_title')
->filterWhere(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb', 'news_title' => ''])
->one();

andFilterWhere

EsModel::find()->index('wx')->select('news_title')
->where(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'])
->andFilterWhere(['and', ['media_name' => '城镇城镇交费', 'news_title' => '']])
->one();

orFilterWhere

EsModel::find()->index('wx')->select('news_title')
->where(['news_uuid' => 'b15e02a0bddacc0ee61d51d36d0022eb'])
->orFilterWhere(['and', ['media_name' => '城镇城镇交费', 'news_posttime' => '2021-09-01 19:00:00']])
->one();

All versions of elasticsearch-query-builder with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package inkime/elasticsearch-query-builder contains the following files

Loading the files please wait ....