首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何对具有不同优先级的多个ElasticSearch索引进行排序?

如何对具有不同优先级的多个ElasticSearch索引进行排序?
EN

Stack Overflow用户
提问于 2022-11-09 12:14:51
回答 1查看 22关注 0票数 0

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

这有可能吗?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2022-11-15 00:28:00

您可以在查询中按_index进行排序(如以下所示);

代码语言:javascript
复制
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" }} ]
}

输出为;

代码语言:javascript
复制
{
  "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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74374729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档