2
$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]]
                                ]
                            ]
                        ]
                    ]
                ]
            ],
        ]
    ];

when i pass this params to $elastic->search($params2);

its return me this exception

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

i am using ErickTamayo/laravel-scout-elastic package

2
  • 2
    Remove the square brackets around ["terms" => ["field" => "type_id","size" => 4]], => "terms" => ["field" => "type_id","size" => 4], Commented Feb 20, 2018 at 9:09
  • thanks, now i have new exception {"error":{"root_cause":[{"type":"parsing_exception","reason":"Aggregation definition for [top starts with a [START_ARRAY], expected a [START_OBJECT].","line":1,"col":164}],"type":"parsing_exception","reason":"Aggregation definition for [top starts with a [START_ARRAY], expected a [START_OBJECT].","line":1,"col":164},"status":400} Commented Feb 20, 2018 at 9:20

1 Answer 1

1

You need to remove the square brackets around terms and top_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]
                                ]
                            ]
                        ]
                    ]
                ]
            ],
        ]
    ];
Sign up to request clarification or add additional context in comments.

2 Comments

yea,thanks i already change it and have new exception thanks, now i have new exception {"error":{"root_cause":[{"type":"parsing_exception","reason":"Aggregation definition for [top starts with a [START_ARRAY], expected a [START_OBJECT].","line":1,"col":164}],"type":"parsing_exception","reason":"Aggregation definition for [top starts with a [START_ARRAY], expected a [START_OBJECT].","line":1,"col":164},"status":400}
Did you copy/paste exactly my answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.