samedi 17 novembre 2018

Elasticsearch syntax error with multi fields search

I look at "Elasticsearch Do's, Don'ts and Pro-Tips - Itamar Syn Hershko" video tutorial at https://www.youtube.com/watch?v=c9O5_a50aOQ I see condition on several fiedls https://imgur.com/a/17zAZ4w and try to make it in my Laravel 5.7 app(with elasticsearch/elasticsearch plugin) as :

$elasticQuery = [
    "bool" => [
        'must'   => [
            'multi_match' => [
                'query'  => $text,
                'fields' => ['name^4', 'description']
            ],
        ],
        "should" => [
            'term' => [
                "category_id" => 1,
            ]
        ]
    ]
];

but I got error :

{"error":{"root_cause":[{"type":"parsing_exception","reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":130}],"type":"parsing_exception","reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":130},"status":400}

When I use simple condition:

        $elasticQuery = [
            'multi_match' => [
                'query' => $text,
                'fields' => ['name^4', 'description'],
            ],
        ];

I got valid results as :

[hits] => Array
    (
        [total] => 1
        [max_score] => 7.4126062
        [hits] => Array
            (
                [0] => Array
                    (
                        [_index] => select_vote
                        [_type] => vote
                        [_id] => 16
                        [_score] => 7.4126062
                        [_source] => Array
                            (
                                [id] => 16
                                [slug] => in-the-film-babe-what-type-of-animal-was-babe
                                [name] => In the film Babe, what type of animal was Babe?
                                [description] => Babe is a 1995 A...
                                [created_at] => 2018-11-10 09:14:15
                                [category_id] => 2
                                [category] => Array
                                    (
                                        [name] => Movie&Cartoons
                                        [slug] => movie-cartoons
                                        [created_at] => 2018-11-10 09:14:12
                                    )

                            )

                    )

            )

    )

Which is valid format for multi request ?

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire