CakePHP
  • 文档
    • 图书
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 礼品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • 烘焙坊
    • 特色资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 通讯
    • 领英
    • YouTube
    • 脸书
    • 推特
    • Mastodon
    • 帮助和支持
    • 论坛
    • 堆栈溢出
    • IRC
    • Slack
    • 付费支持
CakePHP

C Elastic Search 4.x API

  • 项目
    • Elastic Search
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 4.x
      • 4.x
      • 3.x
      • 2.x

命名空间

  • Cake\ElasticSearch
    • 关联
    • 数据源
    • 异常
    • 规则
    • 测试套件
    • 视图

类 QueryBuilder

命名空间: Cake\ElasticSearch

方法摘要

  • _parseQuery() protected

    将包含操作符的字段名称解析为 Filter 对象。

  • and() public

    使用“must”子句将所有传递的参数组合到一个 bool 查询中。

  • and_() public deprecated

    使用“must”子句将所有传递的参数组合到一个 bool 查询中。

  • between() public

    返回一个 Range 查询对象,该对象设置为查询具有介于 from 和 to 值之间的字段的文档

  • bool() public

    返回一个 bool 查询,可以与 addMust()、addShould()、addFilter 和 addMustNot() 方法链接。

  • exists() public

    返回一个 Exists 查询对象,该对象设置为查询具有存在属性或未设置为 null 的文档。

  • geoBoundingBox() public

    返回一个 GeoBoundingBox 查询对象,该对象设置为查询具有由两个坐标绑定属性的文档。

  • geoDistance() public

    返回一个 GeoDistance 查询对象,该对象设置为查询具有坐标半径距离内属性的文档。

  • geoPolygon() public

    返回一个 GeoPolygon 查询对象,该对象设置为查询具有由传递的地理点引起的区域内的属性的文档。

  • geoShape() public

    返回一个 GeoShapeProvided 查询对象,该对象设置为查询具有包含在指定几何形状类型中的属性的文档。

  • geoShapeIndex() public

    返回一个 GeoShapePreIndex 查询对象,该对象设置为查询具有包含在指定几何形状类型中的属性的文档。

  • gt() public

    返回一个 Range 查询对象,该对象设置为查询具有大于提供值的字段的文档。

  • gte() public

    返回一个 Range 查询对象,该对象设置为查询具有大于或等于提供值的字段的文档。

  • hasChild() public

    接受查询和要对其运行的子类型,并导致具有匹配查询的子文档的父文档。

  • hasParent() public

    通过具有匹配查询的父文档的子文档查询

  • ids() public

    查询仅具有提供 ID 的文档。

  • limit() public

    限制要执行的文档数量(每个分片)。

  • lt() public

    返回一个 Range 查询对象,该对象设置为查询具有小于提供值的字段的文档。

  • lte() public

    返回一个 Range 查询对象,该对象设置为查询具有小于或等于提供值的字段的文档。

  • match() public

    返回一个 Match 查询对象,该对象查询具有包含匹配项的字段的文档。

  • matchAll() public

    返回所有文档的查询。

  • nested() public

    返回一个 Nested 查询对象,该对象设置为通过路径查询子文档。

  • not() public

    返回一个 BoolQuery 查询,该查询具有通常用于否定其他查询表达式的 must_not 字段

  • or() public

    使用 should 子句将所有传递的参数组合到一个 BoolQuery 查询中。

  • or_() public deprecated

    使用 should 子句将所有传递的参数组合到一个 BoolQuery 查询中。

  • parse() public

    将数组转换为单个查询对象数组

  • prefix() public

    返回一个 Prefix 查询,以查询具有包含具有指定前缀的项的字段的文档

  • range() public

    返回一个 Range 查询对象,该对象设置为查询具有大于提供值的字段的文档。

  • regexp() public

    返回一个 Regexp 查询,以基于正则表达式查询文档。

  • script() public

    返回一个 Script 查询对象,该对象允许基于脚本的返回值进行查询。

  • simpleQueryString() public

    返回一个 SimpleQueryString 对象,该对象允许基于搜索字符串进行查询。

  • term() public

    返回一个 Term 查询对象,该对象查询具有包含项的字段的文档。

  • terms() public

    返回一个 Terms 查询对象,该对象查询具有包含某些项的字段的文档。

方法详情

_parseQuery() ¶ protected

_parseQuery(string $field, mixed $value): Elastica\Query\AbstractQuery

将包含操作符的字段名称解析为 Filter 对象。

参数
string $field

包含操作符的字段名称

mixed $value

要传递给查询的值

返回
Elastica\Query\AbstractQuery

and() ¶ public

and(Elastica\Query\AbstractQuery ...$queries): Elastica\Query\BoolQuery

使用“must”子句将所有传递的参数组合到一个 bool 查询中。

示例

{{{ $bool = $builder->and( $builder->terms('tags', ['cool', 'stuff']), $builder->exists('comments') ); }}}

参数
Elastica\Query\AbstractQuery ...$queries

要比较的查询。

返回
Elastica\Query\BoolQuery

and_() ¶ public

and_(Elastica\Query\AbstractQuery ...$queries): Elastica\Query\BoolQuery

使用“must”子句将所有传递的参数组合到一个 bool 查询中。

示例

{{{ $bool = $builder->and( $builder->terms('tags', ['cool', 'stuff']), $builder->exists('comments') ); }}}

参数
Elastica\Query\AbstractQuery ...$queries

要比较的查询。

返回
Elastica\Query\BoolQuery

between() ¶ public

between(string $field, mixed $from, mixed $to): Elastica\Query\Range

返回一个 Range 查询对象,该对象设置为查询具有介于 from 和 to 值之间的字段的文档

参数
string $field

要查询的字段。

mixed $from

下限值。

mixed $to

上限值。

返回
Elastica\Query\Range
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

bool() ¶ public

bool(): Elastica\Query\BoolQuery

返回一个 bool 查询,可以与 addMust()、addShould()、addFilter 和 addMustNot() 方法链接。

返回
Elastica\Query\BoolQuery
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html

exists() ¶ public

exists(string $field): Elastica\Query\Exists

返回一个 Exists 查询对象,该对象设置为查询具有存在属性或未设置为 null 的文档。

参数
string $field

要检查是否存在字段。

返回
Elastica\Query\Exists
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html

geoBoundingBox() ¶ public

geoBoundingBox(string $field, array|string $topLeft, array|string $bottomRight): Elastica\Query\GeoBoundingBox

返回一个 GeoBoundingBox 查询对象,该对象设置为查询具有由两个坐标绑定属性的文档。

示例

{{{ $query = $builder->geoBoundingBox('location', [40.73, -74.1], [40.01, -71.12]);

$query = $builder->geoBoundingBox( 'location', ['lat => 40.73, 'lon' => -74.1], ['lat => 40.01, 'lon' => -71.12] );

$query = $builder->geoBoundingBox('location', 'dr5r9ydj2y73', 'drj7teegpus6'); }}}

参数
string $field

要比较的字段。

array|string $topLeft

左上角坐标。

array|string $bottomRight

右下角坐标。

返回
Elastica\Query\GeoBoundingBox
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html

geoDistance() ¶ public

geoDistance(string $field, array|string $location, string $distance): Elastica\Query\GeoDistance

返回一个 GeoDistance 查询对象,该对象设置为查询具有坐标半径距离内属性的文档。

示例

{{{ $query = $builder->geoDistance('location', ['lat' => 40.73, 'lon' => -74.1], '10km');

$query = $builder->geoBoundingBox('location', 'dr5r9ydj2y73', '5km'); }}}

参数
string $field

要比较的字段。

array|string $location

要比较的坐标。

string $distance

距离半径。

返回
Elastica\Query\GeoDistance
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html

geoPolygon() ¶ public

geoPolygon(string $field, array $geoPoints): Elastica\Query\GeoPolygon

返回一个 GeoPolygon 查询对象,该对象设置为查询具有由传递的地理点引起的区域内的属性的文档。

示例

{{{ $query= $builder->geoPolygon('location', [ ['lat' => 40, 'lon' => -70], ['lat' => 30, 'lon' => -80], ['lat' => 20, 'lon' => -90], ]);

$query = $builder->geoPolygon('location', [ 'drn5x1g8cu2y', ['lat' => 30, 'lon' => -80], '20, -90', ]); }}}

参数
string $field

要比较的字段。

array $geoPoints

构成多边形的地理点列表

返回
Elastica\Query\GeoPolygon
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html

geoShape() ¶ public

geoShape(string $field, array $geoPoints, string $type = Elastica\Query\GeoShapeProvided::TYPE_ENVELOPE): Elastica\Query\GeoShapeProvided

返回一个 GeoShapeProvided 查询对象,该对象设置为查询具有包含在指定几何形状类型中的属性的文档。

示例

{{{ $query = $builder->geoShape('location', [[13.0, 53.0], [14.0, 52.0]], 'envelope');

$query = $builder->geoShape('location', [ [[-77.03653, 38.897676], [-77.009051, 38.889939]], 'linestring' ]); }}}

您可以在此处了解支持的形状以及如何创建它们: https://elastic.ac.cn/guide/en/elasticsearch/reference/current/geo-shape.html

参数
string $field

要比较的字段。

array $geoPoints

构成形状的地理点列表。

string $type optional

要使用的形状类型(envelope、linestring、polygon、multipolygon...)

返回
Elastica\Query\GeoShapeProvided
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html

geoShapeIndex() ¶ public

geoShapeIndex(string $field, string $id, string $index = 'shapes', string $path = 'shape'): Elastica\Query\GeoShapePreIndexed

返回一个 GeoShapePreIndex 查询对象,该对象设置为查询具有包含在指定几何形状类型中的属性的文档。

示例

{{{ $query = $builder->geoShapeIndex('location', 'DEU', 'countries', 'shapes', 'location'); }}}

参数
string $field

要比较的字段。

string $id

包含预索引形状的文档的 ID。

string $index 可选

包含预索引形状的索引名称。

string $path 可选

指定为包含预索引形状的路径的字段。

返回
Elastica\Query\GeoShapePreIndexed
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html

gt() ¶ public

gt(string $field, mixed $value): Elastica\Query\Range

返回一个 Range 查询对象,该对象设置为查询具有大于提供值的字段的文档。

参数
string $field

要查询的字段。

mixed $value

要比较的值。

返回
Elastica\Query\Range
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

gte() ¶ public

gte(string $field, mixed $value): Elastica\Query\Range

返回一个 Range 查询对象,该对象设置为查询具有大于或等于提供值的字段的文档。

参数
string $field

要查询的字段。

mixed $value

要比较的值。

返回
Elastica\Query\Range
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

hasChild() ¶ public

hasChild(Elastica\QueryElastica\Query\AbstractQuery|string $query, string $type): Elastica\Query\HasChild

接受查询和要对其运行的子类型,并导致具有匹配查询的子文档的父文档。

参数
Elastica\QueryElastica\Query\AbstractQuery|string $query

查询。

string $type

要查询的子类型。

返回
Elastica\Query\HasChild
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html

hasParent() ¶ public

hasParent(Elastica\QueryElastica\Query\AbstractQuery|string $query, string $type): Elastica\Query\HasParent

通过具有匹配查询的父文档的子文档查询

参数
Elastica\QueryElastica\Query\AbstractQuery|string $query

查询。

string $type

要查询的父类型。

返回
Elastica\Query\HasParent
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html

ids() ¶ public

ids(array $ids = []): Elastica\Query\Ids

查询仅具有提供 ID 的文档。

参数
array $ids 可选

要通过查询的 ID 列表。

返回
Elastica\Query\Ids
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html

limit() ¶ public

limit(int $limit): Elastica\Query\Limit

限制要执行的文档数量(每个分片)。

参数
int $limit

要查询的最大文档数量。

返回
Elastica\Query\Limit
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-limit-query.html

lt() ¶ public

lt(string $field, mixed $value): Elastica\Query\Range

返回一个 Range 查询对象,该对象设置为查询具有小于提供值的字段的文档。

参数
string $field

要查询的字段。

mixed $value

要比较的值。

返回
Elastica\Query\Range
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

lte() ¶ public

lte(string $field, mixed $value): Elastica\Query\Range

返回一个 Range 查询对象,该对象设置为查询具有小于或等于提供值的字段的文档。

参数
string $field

要查询的字段。

mixed $value

要比较的值。

返回
Elastica\Query\Range
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

match() ¶ public

match(string $field, string $value): Elastica\Query\MatchQuery

返回一个 Match 查询对象,该对象查询具有包含匹配项的字段的文档。

示例

{{{ $builder->match('user.name', 'jose'); }}}

参数
string $field

要查询的字段。

string $value

要在字段中查找的匹配项。

返回
Elastica\Query\MatchQuery
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-match-query.html

matchAll() ¶ public

matchAll(): Elastica\Query\MatchAll

返回所有文档的查询。

返回
Elastica\Query\MatchAll
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html

nested() ¶ public

nested(string $path, Elastica\Query\AbstractQuery $query): Elastica\Query\Nested

返回一个 Nested 查询对象,该对象设置为通过路径查询子文档。

示例

{{{ $builder->nested('comments', $builder->term('author', 'mark')); }}}

参数
string $path

表示要查询的属性路径的点分隔字符串。

Elastica\Query\AbstractQuery $query

查询条件。

返回
Elastica\Query\Nested
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html

not() ¶ public

not(Elastica\Query\AbstractQuery|array $query): Elastica\Query\BoolQuery

返回一个 BoolQuery 查询,该查询具有通常用于否定其他查询表达式的 must_not 字段

参数
Elastica\Query\AbstractQuery|array $query

要取反的查询。

返回
Elastica\Query\BoolQuery
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html

or() ¶ public

or(Elastica\Query\AbstractQuery ...$queries): Elastica\Query\BoolQuery

使用 should 子句将所有传递的参数组合到一个 BoolQuery 查询中。

示例

{{{ $bool = $builder->or( $builder->not($builder->exists('tags')), $builder->exists('comments') ); }}}

参数
Elastica\Query\AbstractQuery ...$queries

要比较的查询。

返回
Elastica\Query\BoolQuery

or_() ¶ public

or_(Elastica\Query\AbstractQuery ...$queries): Elastica\Query\BoolQuery

使用 should 子句将所有传递的参数组合到一个 BoolQuery 查询中。

示例

{{{ $bool = $builder->or( $builder->not($builder->exists('tags')), $builder->exists('comments') ); }}}

参数
Elastica\Query\AbstractQuery ...$queries

要比较的查询。

返回
Elastica\Query\BoolQuery

parse() ¶ public

parse(Elastica\Query\AbstractQuery|array $conditions): Elastica\Query\AbstractQuery|array

将数组转换为单个查询对象数组

解析单个数组。

{{{ $query = $builder->parse([ 'name' => 'mark', 'age <=' => 35 ]);

// 等同于: $query = [ $builder->term('name', 'mark'), $builder->lte('age', 35) ]; }}}

创建“或”条件。

{{{ $query = $builder->parse([ 'or' => [ 'name' => 'mark', 'age <=' => 35 ] ]);

// 等同于: $query = [$builder->or( $builder->term('name', 'mark'), $builder->lte('age', 35) )]; }}}

否定条件。

{{{ $query = $builder->parse([ 'not' => [ 'name' => 'mark', 'age <=' => 35 ] ]);

// 等同于: $query = [$builder->not( $builder->and( $builder->term('name', 'mark'), $builder->lte('age', 35) ) )]; }}}

检查字段是否存在。

{{{ $query = $builder->parse([ 'name is' => null, 'age is not' => null ]);

// 等同于: $query = [ $builder->not($builder->exists('name')), $builder->exists('age') ]; }}}

检查值是否在术语列表中。

{{{ $query = $builder->parse([ 'name in' => ['jose', 'mark'] ]);

// 等同于: $query = [$builder->terms('name', ['jose', 'mark'])] }}}

支持的操作符列表是:

<, >, <=, >=, in, not in, is, is not, !=

参数
Elastica\Query\AbstractQuery|array $conditions

要解析的条件列表。

返回
Elastica\Query\AbstractQuery|array

prefix() ¶ public

prefix(string $field, string $prefix, float $boost = 1.0): Elastica\Query\Prefix

返回一个 Prefix 查询,以查询具有包含具有指定前缀的项的字段的文档

参数
string $field

要查询的字段。

string $prefix

要检查的前缀。

float $boost 可选

可选的提升值。

返回
Elastica\Query\Prefix
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html

range() ¶ public

range(string $field, array $args): Elastica\Query\Range

返回一个 Range 查询对象,该对象设置为查询具有大于提供值的字段的文档。

$args 数组接受以下键:

  • gte: 大于或等于
  • gt: 大于
  • lte: 小于或等于
  • lt: 小于
参数
string $field

要查询的字段。

array $args

描述搜索范围的数组。

返回
Elastica\Query\Range
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

regexp() ¶ public

regexp(string $field, string $regexp, float $boost = 1.0): Elastica\Query\Regexp

返回一个 Regexp 查询,以基于正则表达式查询文档。

示例

{{{ $builder->regexp('name.first', 'ma.*'); }}}

参数
string $field

要查询的字段。

string $regexp

正则表达式。

float $boost 可选

提升值

返回
Elastica\Query\Regexp
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html

script() ¶ public

script(Elastica\Script\AbstractScript|array|string $script): Elastica\Query\Script

返回一个 Script 查询对象,该对象允许基于脚本的返回值进行查询。

示例

{{{ $builder->script("doc['price'].value > 1"); }}}

参数
Elastica\Script\AbstractScript|array|string $script

脚本。

返回
Elastica\Query\Script
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-script-query.html

simpleQueryString() ¶ public

simpleQueryString(array|string $fields, string $string): Elastica\Query\SimpleQueryString

返回一个 SimpleQueryString 对象,该对象允许基于搜索字符串进行查询。

示例

{{{ $builder->simpleQueryString(['body'], '"fried eggs" +(eggplant | potato) -frittata'); }}}

参数
array|string $fields

要在其中搜索的字段。

string $string

要在字段中查找的模式。

返回
Elastica\Query\SimpleQueryString
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html

term() ¶ public

term(string $field, string $value): Elastica\Query\Term

返回一个 Term 查询对象,该对象查询具有包含项的字段的文档。

示例

{{{ $builder->term('user.name', 'jose'); }}}

参数
string $field

要查询的字段。

string $value

要在字段中查找的术语。

返回
Elastica\Query\Term
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-term-query.html

terms() ¶ public

terms(string $field, array $values): Elastica\Query\Terms

返回一个 Terms 查询对象,该对象查询具有包含某些项的字段的文档。

示例

{{{ $builder->terms('user.name', ['jose', 'mark']); }}}

参数
string $field

要查询的字段。

array $values

要在字段中查找的术语列表。

返回
Elastica\Query\Terms
另请参见
https://elastic.ac.cn/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 图书
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题 (Github)
  • 烘焙坊
  • 特色资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 通讯
  • 领英
  • YouTube
  • 脸书
  • 推特
  • Mastodon
  • 帮助和支持
  • 论坛
  • 堆栈溢出
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成