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