Elasticsearch:预期字段名称但得到START_OBJECT“more_like_this”

时间:2018-05-02 11:02:02

标签: elasticsearch

我的所有Elasticsearch查询都运行正常,除非我使用“more_like_this”功能时,我总是得到“预期的字段名称但得到START_OBJECT'more_like_this'”错误。

这是我的常规查询“数组”:(工作正常)

Array
(
    [index] => videos
    [from] => 0
    [size] => 75
    [body] => Array
        (
            [query] => Array
                (
                    [bool] => Array
                        (
                            [must] => Array
                                (
                                    [0] => Array
                                        (
                                            [match] => Array
                                                (
                                                    [gender] => 1
                                                )

                                        )

                                    [1] => Array
                                        (
                                            [match_phrase] => Array
                                                (
                                                    [title] => my super title
                                                )

                                        )

                                    [2] => Array
                                        (
                                            [range] => Array
                                                (
                                                    [date] => Array
                                                        (
                                                            [lte] => 1525258744
                                                        )

                                                )

                                        )

                                )

                        )

                )

            [sort] => Array
                (
                    [date] => Array
                        (
                            [order] => desc
                        )

                )

        )

)

这里有一个more_like_this选项:(不行)

Array
(
    [index] => videos
    [from] => 0
    [size] => 75
    [body] => Array
        (
            [query] => Array
                (
                    [bool] => Array
                        (
                            [must] => Array
                                (
                                    [0] => Array
                                        (
                                            [match] => Array
                                                (
                                                    [gender] => 1
                                                )

                                        )

                                    [1] => Array
                                        (
                                            [range] => Array
                                                (
                                                    [date] => Array
                                                        (
                                                            [lte] => 1525258700
                                                        )

                                                )

                                        )

                                )

                        )

                    [more_like_this] => Array
                        (
                            [fields] => Array
                                (
                                    [0] => title
                                )

                            [like_text] => my super title
                            [min_term_freq] => 1
                            [max_query_terms] => 12
                        )

                )

        )

)

1 个答案:

答案 0 :(得分:0)

找到答案(感谢@Val),more_like_this应该是必须数组的一部分:

Array
(
    [index] => videos
    [from] => 0
    [size] => 75
    [body] => Array
        (
            [query] => Array
                (
                    [bool] => Array
                        (
                            [must] => Array
                                (
                                    [0] => Array
                                        (
                                            [match] => Array
                                                (
                                                    [gender] => 1
                                                )

                                        )

                                    [1] => Array
                                        (
                                            [more_like_this] => Array
                                                (
                                                    [fields] => Array
                                                        (
                                                            [0] => title
                                                        )

                                                    [like_text] => my super title
                                                    [min_term_freq] => 1
                                                    [max_query_terms] => 12
                                                )

                                        )

                                    [2] => Array
                                        (
                                            [range] => Array
                                                (
                                                    [date] => Array
                                                        (
                                                            [lte] => 1525269403
                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

)