Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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 Elasticsearch排序嵌套字段_Sorting_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Sorting,elasticsearch" /> elasticsearch,Sorting,elasticsearch" />

Sorting Elasticsearch排序嵌套字段

Sorting Elasticsearch排序嵌套字段,sorting,elasticsearch,Sorting,elasticsearch,我将ElasticSearch6与PHP一起使用 “我的文档”有一个嵌套字段,如下所示: "prices" : { "type" : "nested", "properties" : { "date" : { "type" : "date" }, "duration" : { "type" : "short" },

我将ElasticSearch6与PHP一起使用

“我的文档”有一个嵌套字段,如下所示:

    "prices" : {
        "type" : "nested",
        "properties" : {
          "date" : {
            "type" : "date"
          },
          "duration" : {
            "type" : "short"
          },
          "persons" : {
            "type" : "short"
          },
          "pets" : {
            "type" : "short"
          },
          "price" : {
            "type" : "float"
          }
        }
基本上每个文档都有很多价格,但我知道每个文档只有一个价格与过滤器/查询匹配

我用它来搜索和排序,改编自这里的教程:(对不起,PHP数组格式):


我得到了正确的结果,但文件没有按价格排序。如何正确地对它们进行排序?文档应该按照与过滤器匹配的价格进行排序。

显然我使用的是旧文档。上述查询的正确排序部分是:

    'sort' => [
        'prices.price' => [
            'order' => 'asc',
            'mode' => 'avg',
            'nested' => [
                'path' => 'prices',
                'filter' => [
                    'bool' => [
                        'must' => [
                            ['match' => ['prices.duration' => 14]],
                            ['match' => ['prices.date' => '2018-09-01']],
                            ['match' => ['prices.pets' => 2]],
                            ['match' => ['prices.persons' => 2]]
                        ]
                    ]
                ]
            ]
        ]
    ]
    'sort' => [
        'prices.price' => [
            'order' => 'asc',
            'mode' => 'avg',
            'nested' => [
                'path' => 'prices',
                'filter' => [
                    'bool' => [
                        'must' => [
                            ['match' => ['prices.duration' => 14]],
                            ['match' => ['prices.date' => '2018-09-01']],
                            ['match' => ['prices.pets' => 2]],
                            ['match' => ['prices.persons' => 2]]
                        ]
                    ]
                ]
            ]
        ]
    ]