【问题标题】:ElasticSearch 6.2 - aggs return : unknown_named_object_exceptionElasticSearch 6.2 - aggs 返回:unknown_named_object_exception
【发布时间】:2018-07-30 14:00:57
【问题描述】:
$params2 = [
        'index' => 'index',
        'type'  => "items",
        'body' => [
            'aggs'  => [
                "types" => [
                    "filter" => [
                        "bool" => [
                            "should" => [
                                ["term" => ["type_id" => 1]],
                                ["term" => ["type_id" => 2]]

                            ]
                        ]
                    ],
                    "aggs" => [
                        "types" =>[
                            ["terms" => ["field" => "type_id","size" => 4]],
                            "aggs" =>[
                                "top" => [
                                    ["top_hits" => ["size" => 2]]
                                ]
                            ]
                        ]
                    ]
                ]
            ],
        ]
    ];

当我将此参数传递给 $elastic->search($params2);

它返回我这个异常

{"error":{"root_cause":[{"type":"unknown_named_object_exception","re​​ason":"Unknown BaseAggregationBuilder [0]","line":1,"col":117}]," type":"unknown_named_object_exception","re​​ason":"Unknown BaseAggregationBuilder [0]","line":1,"col":117},"status":400}

我正在使用 ErickTamayo/laravel-scout-elastic 包

【问题讨论】:

  • 去掉["terms" => ["field" => "type_id","size" => 4]],周围的方括号 => "terms" => ["field" => "type_id","size" => 4],
  • 谢谢,现在我有了新异常 {"error":{"root_cause":[{"type":"parsing_exception","re​​ason":"[top 的聚合定义以 [START_ARRAY ],预期为 [START_OBJECT]。","line":1,"col":164}],"type":"parsing_exception","re​​ason":"[top 的聚合定义以 [START_ARRAY] 开头,预期为一个 [START_OBJECT].","line":1,"col":164},"status":400}

标签: php laravel elasticsearch


【解决方案1】:

您需要删除termstop_hits 周围的方括号

$params2 = [
        'index' => 'index',
        'type'  => "items",
        'body' => [
            'aggs'  => [
                "types" => [
                    "filter" => [
                        "bool" => [
                            "should" => [
                                ["term" => ["type_id" => 1]],
                                ["term" => ["type_id" => 2]]

                            ]
                        ]
                    ],
                    "aggs" => [
                        "types" =>[
                            "terms" => ["field" => "type_id","size" => 4],
                            "aggs" =>[
                                "top" => [
                                    "top_hits" => ["size" => 2]
                                ]
                            ]
                        ]
                    ]
                ]
            ],
        ]
    ];

【讨论】:

  • 是的,谢谢我已经改变它并有新的异常谢谢,现在我有新的异常 {"error":{"root_cause":[{"type":"parsing_exception","re​​ason": "[top 的聚合定义以 [START_ARRAY] 开头,预期为 [START_OBJECT]。","line":1,"col":164}],"type":"parsing_exception","re​​ason":"聚合定义对于 [top 以 [START_ARRAY] 开头,预期为 [START_OBJECT]。","line":1,"col":164},"status":400}
  • 您是否完全复制/粘贴了我的答案?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-18
  • 2023-02-10
  • 1970-01-01
  • 2018-12-17
  • 2016-03-27
  • 2014-10-13
相关资源
最近更新 更多