如何排序不同优先级的多个ElasticSearch索引?



是否可以按索引对ElasticSearch结果进行排序?我不想改变他们的得分指数。但是我有artistssongs索引,我想先显示艺术家的结果,然后是歌曲,最好是保留原始乐谱。

这可能吗?

谢谢。

您可以在查询中按_index排序,例如:

POST artist/_doc/1
{
"user_id" : 1234,
"acc_id" : 4321,
"type_of_event" : "event",
"event_label" : "example activity",
"time_stamp" : 1582720371,
"event_info" : "example info"
}
POST songs/_doc/2
{
"user_id" : 1234,
"acc_id" : 4321,
"type_of_event" : "event",
"event_label" : "example activity",
"time_stamp" : 1582760371,
"event_info" : "example info"
}
POST artist/_doc/3
{
"user_id" : 12345,
"acc_id" : 4321,
"type_of_event" : "event",
"event_label" : "example activity",
"time_stamp" : 1582720371,
"event_info" : "example info"
}
POST songs/_doc/4
{
"user_id" : 1235,
"acc_id" : 4321,
"type_of_event" : "event",
"event_label" : "example activity",
"time_stamp" : 1592720371,
"event_info" : "example info"
}
POST /artist,songs/_search
{
"sort" : [ { "_index" : {"order" : "desc" }} ]
}

,输出为;

{
"took": 1,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": null,
"hits": [
{
"_index": "songs",
"_id": "2",
"_score": null,
"_source": {
"user_id": 1234,
"acc_id": 4321,
"type_of_event": "event",
"event_label": "example activity",
"time_stamp": 1582760371,
"event_info": "example info"
},
"sort": [
"songs"
]
},
{
"_index": "songs",
"_id": "4",
"_score": null,
"_source": {
"user_id": 1235,
"acc_id": 4321,
"type_of_event": "event",
"event_label": "example activity",
"time_stamp": 1592720371,
"event_info": "example info"
},
"sort": [
"songs"
]
},
{
"_index": "artist",
"_id": "1",
"_score": null,
"_source": {
"user_id": 1234,
"acc_id": 4321,
"type_of_event": "event",
"event_label": "example activity",
"time_stamp": 1582720371,
"event_info": "example info"
},
"sort": [
"artist"
]
},
{
"_index": "artist",
"_id": "3",
"_score": null,
"_source": {
"user_id": 12345,
"acc_id": 4321,
"type_of_event": "event",
"event_label": "example activity",
"time_stamp": 1582720371,
"event_info": "example info"
},
"sort": [
"artist"
]
}
]
}
}

如果需要,可以将desc更改为asc

最新更新