[英]elasticsearch query not working on nested query with php
我在查询时遇到问题,我有一个嵌套的文档
Array
(
[took] => 2
[timed_out] =>
[_shards] => Array
(
[total] => 5
[successful] => 5
[failed] => 0
)
[hits] => Array
(
[total] => 1
[max_score] => 1
[hits] => Array
(
[0] => Array
(
[_index] => holiday
[_type] => holiday
[_id] => 31245
[_score] => 1
[_source] => Array
(
[username] => john thomas
[user] => 3
[info] => test
[phone] => 166872
[data] => Array
(
[foo] => 28865
[bar] => new test
)
)
)
)
)
)
当我使用elasticsearch php库运行标准查询时
$client = new Elasticsearch\Client();
$params['index'] = 'holiday';
$params['type'] = 'holiday';
$params['body']['query']['match']['phone'] = '166872';
$results = $client->search($params);
echo '<pre>' , print_r($results) , '</pre>';
我得到结果。 但是当我更改查询参数以搜索foo
$params['body']['query']['match']['data']['foo'] = '28865';
我被抛出异常
{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
shardFailures {[9J2ZatYTTV2Sk8LQFKFeXg][holiday][2]:
SearchParseException[[holiday][2]: from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"match": {
"data": {
"foo": "28865"
}
}
}
}
]]];
nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][3]:
SearchParseException[[holiday][3]: from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"match": {
"data": {
"foo": "28865"
}
}
}
}
]]];
nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][0]:
SearchParseException[[holiday][0]: from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"match": {
"data": {
"foo": "28865"
}
}
}
}
]]];
nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][1]:
SearchParseException[[holiday][1]: from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"match": {
"data": {
"foo": "28865"
}
}
}
}
]]];
nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][4]:
SearchParseException[[holiday][4]: from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"match": {
"data": {
"foo": "28865"
}
}
}
}
]]];
nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }]",
"status": 400
}
有什么想法为什么嵌套查询会中断吗?
如果使用默认映射,则data
字段已动态映射为类型object
( 此处的文档)。
因此,要查询object
的子属性,应使用如下所示的点符号 :
{
"query": {
"match": {
"data.foo": "28865"
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.