Php Elasticsearch-2019年按嵌套字段排序
因此,我试图找出一种基于嵌套文档的单个属性对文档进行排序的方法。比如说,我有一个“视频”索引。每个视频都有一个视频所属类别的列表。每个类别都是一个嵌套文档,其中包含有关该类别的特定元数据,例如id、视图、slug。下面是一个映射示例:Php Elasticsearch-2019年按嵌套字段排序,php,sorting,
elasticsearch,Php,Sorting,
elasticsearch,因此,我试图找出一种基于嵌套文档的单个属性对文档进行排序的方法。比如说,我有一个“视频”索引。每个视频都有一个视频所属类别的列表。每个类别都是一个嵌套文档,其中包含有关该类别的特定元数据,例如id、视图、slug。下面是一个映射示例: "videos" : { "properties" : { "categories" : { "type" : "nested", "properties" : { "id" : {
"videos" : {
"properties" : {
"categories" : {
"type" : "nested",
"properties" : {
"id" : {
"type" : "integer"
},
"views" : {
"type" : "integer"
},
"slug" : {
"type" : "keyword"
}
}
},
"title" : {
"type" : "text"
},
}
}
下面是一个示例文档:
{
"_index" : "videos",
"_id" : "123",
"_source" : {
"title" : "this is a test video",
"categories" : [
{
"id" : 3533,
"slug" : "animals",
"views" : 314
},
{
"id" : 3564,
"slug" : "comedy",
"views" : 814
},
{
"id" : 4072,
"slug" : "politics",
"views" : 80
}
],
}
}
所以我想按某个类别的视图对视频进行排序。例如,按“喜剧”类别的视图按降序对视频进行排序。我已经在网上搜索了一个解决方案,但大多数都是针对某个问题的,或者使用了过时的查询。Ypu需要使用嵌套过滤器。你可以得到更多的信息 结果
"hits" : [
{
"_index" : "videos",
"_type" : "_doc",
"_id" : "uT6bRGsBFW2mvGhmMxUU",
"_score" : null,
"_source" : {
"title" : "this is a test video",
"categories" : [
{
"id" : 3533,
"slug" : "animals",
"views" : 314
},
{
"id" : 3564,
"slug" : "comedy",
"views" : 814
},
{
"id" : 4072,
"slug" : "politics",
"views" : 80
}
]
},
"sort" : [
814
]
},
{
"_index" : "videos",
"_type" : "_doc",
"_id" : "uj6bRGsBFW2mvGhmXxWl",
"_score" : null,
"_source" : {
"title" : "this is a test video",
"categories" : [
{
"id" : 3533,
"slug" : "animals",
"views" : 314
},
{
"id" : 3564,
"slug" : "comedy",
"views" : 900
},
{
"id" : 4072,
"slug" : "politics",
"views" : 80
}
]
},
"sort" : [
900
]
}
]
"hits" : [
{
"_index" : "videos",
"_type" : "_doc",
"_id" : "uT6bRGsBFW2mvGhmMxUU",
"_score" : null,
"_source" : {
"title" : "this is a test video",
"categories" : [
{
"id" : 3533,
"slug" : "animals",
"views" : 314
},
{
"id" : 3564,
"slug" : "comedy",
"views" : 814
},
{
"id" : 4072,
"slug" : "politics",
"views" : 80
}
]
},
"sort" : [
814
]
},
{
"_index" : "videos",
"_type" : "_doc",
"_id" : "uj6bRGsBFW2mvGhmXxWl",
"_score" : null,
"_source" : {
"title" : "this is a test video",
"categories" : [
{
"id" : 3533,
"slug" : "animals",
"views" : 314
},
{
"id" : 3564,
"slug" : "comedy",
"views" : 900
},
{
"id" : 4072,
"slug" : "politics",
"views" : 80
}
]
},
"sort" : [
900
]
}
]