[英]Querying Elasticsearch with PHP
I'm having a little trouble translating some of the queries I use for elasticsearch into PHP readable queries. 将用于Elasticsearch的某些查询转换为PHP可读查询时遇到了一些麻烦。
For example this simple query works: 例如,以下简单查询有效:
$query = $elastic->search([
body' => [
'query' => [
'match' => [
'myfield' => 'mymatchingresult'
]
]
]
]);
But what I'm trying to get to work follow below. 但是,我要努力工作的是以下内容。 There isn't an error, it just doesn't run.
没有错误,只是没有运行。 I must not be understanding the structure.
我一定不了解结构。 The same query if placed in something like google extension sense seems to work.
如果将类似的查询放入Google扩展名之类的查询中,它似乎可以工作。 (With the php '=>' converted to ':' etc.)
(将php'=>'转换为':'等)
$query = $elastic->search([
'body' => [
'query' => [
'filtered' => [
'query' => [
'query_string' => [
'query' => '*',
'analyze_wildcard' => 'true'
]
],
'filter' => [
'bool' => [
'must' => [
'query' => [
'query_string' => [
'analyze_wildcard' => 'true',
'query' => 'cn:name'
]
],
'range' => [
'@timestamp' => [
'from' => '2012-05-01',
'to' => '2016-05-01'
]
]
]
]
]
]
]
]
]);
Thank you for the help! 感谢您的帮助! -John
-约翰
As far as I can tell, the constraints in your bool/must
filter must be enclosed in square brackets, ie bool/must
should be a pure array, not an associative array. 据我所知,
bool/must
过滤器中的约束必须放在方括号中,即bool/must
应该是纯数组,而不是关联数组。
Like this: 像这样:
$query = $elastic->search([
'body' => [
'query' => [
'filtered' => [
'query' => [
'query_string' => [
'query' => '*',
'analyze_wildcard' => 'true'
]
],
'filter' => [
'bool' => [
'must' => [
[
'query' => [
'query_string' => [
'analyze_wildcard' => 'true',
'query' => 'cn:name'
]
]
],
[
'range' => [
'@timestamp' => [
'from' => '2012-05-01',
'to' => '2016-05-01'
]
]
]
]
]
]
]
]
]
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.