1

The query returns this error.

Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"parsing_exception","reason":"unknown query [query]","line":1,"col":62}],"type":"x_content_parse_exception","reason":"[1:62] [bool] failed to parse field [should]","caused_by":{"type":"parsing_exception","reason":"unknown query [query]","line":1,"col":62,"caused_by":{"type":"named_object_not_found_exception","reason":"[1:62] unknown field [query]"}}},"status":400} in

How can i write this query ? . In array first one is (manufacturer_code,ean) parent, other objects are nested.

$query = [
            'bool' => [
                'should' => [
                    ['query' => [   //parent root
                        'query_string' => [
                            'fields' => ['manufacturer_code', 'ean'],
                            'query'  =>  $search,
                        ],
                    ],
                    ],

                    ['nested' => [   //nested parent.lang
                        'path'  => 'lang',
                        'query' => [
                            'query_string' => [
                                'fields' => 'lang.name',
                                'query'         =>  $search ,
                            ],
                        ],
                    ]],
                    ['nested' => [  //nested parent.product_base.lang
                        'path'  => 'product_base.lang',
                        'query' => [
                            'query_string' => [
                                'fields' => 'product_base.lang.meta_keywords',
                                'query'         =>  $search ,
                            ],
                        ],
                    ]],
                ],
                'minimum_should_match' => 1,
            ],

        ];

1 Answer 1

1

You're almost there, in the first should clause you need to remove the first query, i.e. query_string should be at top level

$query = [
            'bool' => [
                'should' => [
                    ['query_string' => [ //parent root     <-- modify this clause
                            'fields' => ['manufacturer_code', 'ean'],
                            'query'  =>  $search,
                        ],
                    ],

                    ['nested' => [   //nested parent.lang
                        'path'  => 'lang',
                        'query' => [
                            'query_string' => [
                                'fields' => 'lang.name',
                                'query'         =>  $search ,
                            ],
                        ],
                    ]],
                    ['nested' => [  //nested parent.product_base.lang
                        'path'  => 'product_base.lang',
                        'query' => [
                            'query_string' => [
                                'fields' => 'product_base.lang.meta_keywords',
                                'query'         =>  $search ,
                            ],
                        ],
                    ]],
                ],
                'minimum_should_match' => 1,
            ],

        ];
Sign up to request clarification or add additional context in comments.

Comments

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.