嵌套过滤器不起作用的弹性搜索排序

时间:2015-05-24 18:38:59

标签: sorting elasticsearch filter nested

我的文档有一个对象数组,每个对象都有一个值和一个置信度。 我想基于对象属性对返回的文档进行排序,但只对与查询具有匹配值的对象进行排序。

文档中包含属性标记'包含如下数组:

[{"type":"imagga","value":"stone","confidence":16},
 {"type":"imagga","value":"surface","confidence":13},
 {"type":"imagga","value":"texture","confidence":25}]

我尝试在搜索中添加一个排序:

$searchParams['sort'] = [
    "tags.confidence" => [
        "order" => "desc",
        "mode" => "min",
        "nested_path" => "tags",
        "nested_filter" => [
            "term" => [
                "tags.value" => "tree"
            ]
        ]
    ]
];

这不起作用。我的过滤器查询有效,并且只返回匹配的文档,但它们没有按原样排序。

我用这个作为一个例子,它看起来很相似,但没有用: https://www.elastic.co/guide/en/elasticsearch/guide/master/nested-sorting.htmlhttp://w3facility.org/question/elasticsearch-sort-by-single-nested-document-key-in-array/

我还尝试将置信区域更改为not_analyzed,这没有任何区别,并确保它是一个长期的'类型。

背景。我的文档代表大约10,000张图像,每个文档都有一个具有值和置信度的标记,因此用户可以根据文档中标记的置信度搜索某些内容并获取匹配的图像。

更新: 我的映射:

Array(
    [_source] => Array(
        [enabled] => 1
    ) [properties] => Array(
        [fieldName] => Array(
            [type] => geo_point
        ) [tags . value] => Array(
            [type] => string[index] => not_analyzed
        ) [tags . confidence] => Array(
            [type] => long[index] => not_analyzed
        )
    )
)

我的查询:

Array(
    [sort] => Array(
        [tags . confidence] => Array(
            [order] => desc[mode] => min[nested_path] => tags[nested_filter] => Array(
                [term] => Array(
                    [tags . value] => tree
                )
            )
        )
    ) [index] => mediadump_index[size] => 100[from] => 0[body] => Array(
        [query] => Array(
            [function_score] => Array(
                [functions] => Array(
                    [0] => Array(
                        [random_score] => stdClassObject()
                    )
                ) [filter] => Array(
                    [bool] => Array(
                        [must] => Array(
                            [0] => Array(
                                [term] => Array(
                                    [tags . value] => tree
                                )
                            )
                        ) [must_not] => Array()
                    )
                )
            )
        )
    )
)

我的结果(删除了一些标签以减少此示例):

Array
(
    [took] => 3
    [timed_out] => 
    [_shards] => Array
        (
            [total] => 5
            [successful] => 5
            [failed] => 0
        )

    [hits] => Array
        (
            [total] => 1682
            [max_score] => 0.9996578
            [hits] => Array
                (
                    [0] => Array
                        (
                            [_index] => mediadump_index
                            [_type] => file
                            [_id] => 3173
                            [_score] => 0.9996578
                            [_source] => Array
                                (
                                    [id] => 3173
                                    [hash] => fe535555a08aa13dcfa5d80dd451fbf3
                                    [media_type] => image
                                    [file_type] => jpeg
                                    [medium_width] => 450
                                    [medium_height] => 300
                                    [datetime] => 2013-02-21 13:19:55
                                    [longtime] => 1361452795
                                    [pin] => Array
                                        (
                                            [location] => Array
                                                (
                                                    [lat] => 27.809999465942
                                                    [lon] => 33.459999084473
                                                )

                                        )

                                    [latitude] => 27.809999465942
                                    [longitude] => 33.459999084473
                                    [elevation] => 0
                                    [literal_location] => 
                                    [tags] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => exif.cameramake
                                                    [value] => sony
                                                    [confidence] => 50
                                                    [group] => exif
                                                )

                                            [43] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => sunset
                                                    [confidence] => 9
                                                )

                                            [44] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => tourism
                                                    [confidence] => 8
                                                )

                                            [45] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => travel
                                                    [confidence] => 19
                                                )

                                            [46] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => tree
                                                    [confidence] => 10
                                                )

                                            [58] => Array
                                                (
                                                    [type] => places.formattedaddress
                                                    [value] => red sea governorate, egypt
                                                    [confidence] => 65
                                                    [group] => places
                                                )

                                            [59] => Array
                                                (
                                                    [type] => tag
                                                    [value] => *
                                                    [confidence] => 50
                                                )

                                            [60] => Array
                                                (
                                                    [type] => uniquedirectorypath
                                                    [value] => /africa/egypt
                                                    [confidence] => 50
                                                )

                                        )

                                )

                        )

                    [1] => Array
                        (
                            [_index] => mediadump_index
                            [_type] => file
                            [_id] => 2917
                            [_score] => 0.9489555
                            [_source] => Array
                                (
                                    [id] => 2917
                                    [hash] => 60506e48708ab46d0b619bf5328aa648
                                    [media_type] => image
                                    [file_type] => jpeg
                                    [medium_width] => 450
                                    [medium_height] => 300
                                    [datetime] => 2013-07-09 18:14:34
                                    [longtime] => 1373393674
                                    [pin] => Array
                                        (
                                            [location] => Array
                                                (
                                                    [lat] => -7.5199999809265
                                                    [lon] => 36.659999847412
                                                )

                                        )

                                    [latitude] => -7.5199999809265
                                    [longitude] => 36.659999847412
                                    [elevation] => 0
                                    [literal_location] => 
                                    [tags] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => exif.cameramake
                                                    [value] => sony
                                                    [confidence] => 50
                                                    [group] => exif
                                                )

                                            [1] => Array
                                                (
                                                    [type] => exif.datetime
                                                    [value] => 2013:07:09 18:14:34
                                                    [confidence] => 50
                                                    [group] => exif
                                                )

                                            [37] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => spring
                                                    [confidence] => 11
                                                )

                                            [38] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => stone
                                                    [confidence] => 8
                                                )

                                            [39] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => summer
                                                    [confidence] => 15
                                                )

                                            [40] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => tourism
                                                    [confidence] => 12
                                                )

                                            [41] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => travel
                                                    [confidence] => 15
                                                )

                                            [42] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => tree
                                                    [confidence] => 22
                                                )

                                            [43] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => trees
                                                    [confidence] => 13
                                                )

                                            [44] => Array
                                                (
                                                    [type] => imagga
                                                    [value] => water
                                                    [confidence] => 8
                                                )


                                        )

                                )

                        )

                )

        )

)

0 个答案:

没有答案