嵌套筛选器不起作用的ElasticSearch排序

4dc9hkyq  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(0)|浏览(310)

我的文档有一个对象数组,每个对象都有一个值和一个置信度。我想根据objects属性对返回的文档进行排序,但只对与查询具有匹配值的对象进行排序。
文档的属性“tags”包含如下数组:

[{"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.html 以及http://w3facility.org/question/elasticsearch-sort-by-single-nested-document-key-in-array/
我也尝试过改变置信域,使其不被分析,这没有什么区别,并确保它是一个'长'类型。
背景。我的文档代表大约10000张图像,每个文档都有带有值和置信度的标记,因此用户可以根据文档中标记的置信度集搜索内容并获得匹配的图像。
更新:我的Map:

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
                                                )

                                        )

                                )

                        )

                )

        )

)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题