Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 嵌套筛选器不起作用的弹性搜索排序_Sorting_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Filter_Nested - Fatal编程技术网 elasticsearch,filter,nested,Sorting,elasticsearch,Filter,Nested" /> elasticsearch,filter,nested,Sorting,elasticsearch,Filter,Nested" />

Sorting 嵌套筛选器不起作用的弹性搜索排序

Sorting 嵌套筛选器不起作用的弹性搜索排序,sorting,elasticsearch,filter,nested,Sorting,elasticsearch,Filter,Nested,我的文档有一个对象数组,每个对象都有一个值和一个置信度。 我希望根据objects属性对返回的文档进行排序,但只对具有与查询匹配值的对象进行排序 文档具有包含如下数组的属性“tags”: [{"type":"imagga","value":"stone","confidence":16}, {"type":"imagga","value":"surface","confidence":13}, {"type":"imagga","value":"texture","confidence":2

我的文档有一个对象数组,每个对象都有一个值和一个置信度。 我希望根据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"
            ]
        ]
    ]
];
这不管用。我的筛选查询工作正常,只返回匹配的文档,但它们并没有按应有的顺序排序

我以这个为例,它看起来非常相似,但不起作用: 和

我还尝试将置信域更改为不进行分析,这没有任何区别,并确保它是“长”类型

背景。我的文档代表大约10000张图像,每个文档都有带有值和置信度的标记,因此用户可以根据文档中标记的置信度集搜索内容并获得匹配的图像

更新: 我的映射:

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()
                    )
                )
            )
        )
    )
)
我的结果(删除一些标签以减少此示例):


您能否显示发出的整个查询、
标记的相关映射以及最终从查询中获得的结果?完成。我使用的是php客户端,有数组。
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
                                                )


                                        )

                                )

                        )

                )

        )

)