弹性搜索,搜索多个元素,我还可以设置每个元素将收到的数据数量的计数

问题描述 投票:0回答:1

抱歉,如果标题不清楚。我想获得两个品牌的结果(假设品牌A和品牌B。我的查询

{ "size":100,
  "query": { 
  "constant_score" : { 
    "filter" : { 
      "bool": {
        "should": [
          { "term": {"brand": "brandA"} },
          { "term": {"brand": "brandB"} }
        ]
      }
      }
    }
  }
}

我想要这种格式的结果:

{{"brand" : "brandA",
          "contentType" : "audiofile",
          "expirationDate" : "2100-01-01T00:00:00.000Z",
          "pubdate" : "2024-02-26T11:00:00.000Z",
          "editorial" : {
            "keywords" : [ ]
          },
  {"brand" : "brandB",
          "contentType" : "audiofile",
          "expirationDate" : "2100-01-01T00:00:00.000Z",
          "pubdate" : "2024-02-26T11:00:00.000Z",
          "editorial" : {
            "keywords" : [ ]
          }}

另外,是否可以对收到的数据数量设置限制。例如,我希望如果收到的总数据为 100,那么品牌 A 应该有 60% 的数据,品牌 B 应该有 40% 的数据

elasticsearch elastic-stack elasticsearch-dsl elastic-database-pool
1个回答
0
投票

现在已经解决了:)

我在弹性搜索中使用了top_hits。

© www.soinside.com 2019 - 2024. All rights reserved.