是否可以按索引对ElasticSearch结果进行排序。我不想按索引更改它们的得分。但我有artists和songs索引,我想先显示艺术家结果,然后再显示歌曲,当保留原始得分时更好。这可能吗?
artists
songs
fcg9iug31#
你可以在一个查询中按_index排序,如下所示;
_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
desc
asc
1条答案
按热度按时间fcg9iug31#
你可以在一个查询中按
_index
排序,如下所示;输出为;
如果需要,可以将
desc
更改为asc