gpt4 book ai didi

php - FOSElastica嵌套查询

转载 作者:行者123 更新时间:2023-12-03 01:39:51 25 4
gpt4 key购买 nike

我的收藏如下:

  {
"_index" : "test_index",
"_type" : "test_type",
"_id" : "10000",
"_score" : 1.0,
"_source" : {
"user_id" : 12,
"index_date" : {
"date" : "2018-02-06 14:25:49.816952",
"timezone_type" : 3,
"timezone" : "UTC"
},
"rating" : null,
"orders" : [
{
"hour" : "08",
"count" : 1
},
{
"hour" : "10",
"count" : 1
}
],
"products" : [
{
"p_id" : 970111,
"count" : 4
},
{
"p_id" : 1280811,
"count" : 1
},

]
}
},

并尝试访问{“hour”:“10”}

我的查询是:
            $query = new Query\Nested();
$query->setPath('orders');

$term = new Term();
$term->setTerm('orders.hour', $order->getCreatedAt()->format('H'));
$query->setQuery($term);
dump($finder->find($query));die;

但我收到以下错误:
  [Elastica\Exception\ResponseException]                           
failed to create query: {
"nested" : {
"query" : {
"term" : {
"orders.hour" : {
"value" : "12",
"boost" : 1.0
}
}
},
"path" : "orders",
"ignore_unmapped" : false,
"score_mode" : "avg",
"boost" : 1.0
}
} [index: test_index] [reason: all shards failed]

最佳答案

您的文档看起来不像嵌套查询。

我假设finder是您的repository manager,它被定义为orders存储库,您的代码应如下所示

$finder = $this->get('fos_elastica.repository_manager')->getRepository('YourBundle:order');

$boolquery = new Query\BoolQuery();

$term = new Query\Term();
$term->setTerm('hour', $order->getCreatedAt()->format('H'));

$boolquery->addMust($term);

$finder->find($boolquery);

关于php - FOSElastica嵌套查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48646929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com