我在Elasticsearch中创建了父/子关系。
我会过滤数千张图片,代码的小例子
$query = array(
'query_string' => array(
'query' => $queryParams['category'],
'default_operator' => 'AND',
'default_field' => 'allParentCategories',
)
);
$reqParams['body'] = array(
'query' => array(
'filtered' => array(
'query' => $query,
'filter' => array(
'bool' => array(
'must' => $filtersArray,
),
),
),
)
);
这就是我得到的结果
array (size=8)
'_index' => string 'images-15' (length=9)
'_type' => string 'image' (length=5)
'_id' => string '48026' (length=5)
'_score' => null
'_routing' => string '2' (length=1)
'_parent' => string '2' (length=1)
'_source' =>
array (size=15)
'thumb' => string 'fasdfas' (length=52)
'author' =>
array (size=6)
'firstName' => string 'asdfas' (length=3)
'lastName' => string 'asdf' (length=3)
'fullName' => string 'asdfas' (length=7)
'id' => string '2' (length=1)
'picture' => null
'username' => string 'asdfa' (length=6)
'downloadURL' => string 'asdfasd' (length=87)
'creationDate' => string '2016-07-15 11:20:12' (length=19)
'tags' =>
array (size=0)
empty
'size' =>
array (size=2)
'bytes' => int 735025
'formatted' => string '717.8 KB' (length=8)
'downloads' => int 0
'added_by' => int 2
'width' => int 900
'is_icon' => boolean false
'is_vector' => boolean false
'id' => int 48026
'views' => int 0
'height' => int 900
'likes' => int 1
'sort' =>
array (size=2)
0 => int 1468581612000
1 => int 48026
我已经尝试过这样的事情:
$reqParams['body'] = array(
'query' => array(
'has_parent' => [
'parent_type' => 'user',
'query' => [
'match_all' => []
],
'inner_hits' => [
'_source' => ['*']
]
],
)
);
在第一种情况下,我只能获得对我来说无用的父ID 目的
在第二种情况下,我可以访问父文档的所有_source字段 但我无法过滤。
我需要它可以访问_parent _source字段并保持图像过滤。