Elasticsearch限制返回的嵌套对象的数量

时间:2016-08-01 02:56:24

标签: ruby-on-rails ruby elasticsearch

我有一个user模型,其中包含articles个对象数组。当我尝试加载具有ID的用户时,该过程需要很长时间,因为它可能是数组中的数千个文章对象。我要做的是只加载100个嵌套文章。我正在使用Elasticsearch 1.5(旧版,因为它托管在AWS上),ES Persistence gemRuby on Rails

尝试了一些文档,但没有一个工作,例如 https://www.elastic.co/guide/en/elasticsearch/reference/1.5/search-aggregations-bucket-nested-aggregation.html

class User
  include Elasticsearch::Persistence::Model

  attribute :articles, Array[MiniArticle], mapping: { type: 'nested'}
  attribute :since_id
end

1 个答案:

答案 0 :(得分:0)

实现您想要的方法是使用inner_hits,但它不支持开箱即用。

pending pull request旨在添加对嵌套inner_hits的支持,但尚未合并。

更多信息here