获取所有没有孩子的记录,即使它们存在于elasticsearch中

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

我使用elasticsearch_rails gem来执行elasticsearch查询。我有这样的映射

mapping do
    indexes :id, type: 'keyword'
    indexes :name, type: 'text'
    indexes :slug, type: 'keyword'
    indexes :variants, type: 'nested' do
      indexes :id, type: 'keyword'
      indexes :sku, type: 'keyword'
      indexes :main, type: 'boolean'
      indexes :price, type: 'float'
    end
  end

def as_indexed_json(options = {})
    as_json(only: ['id', 'name', 'slug'],
            include: {
                variants: {
                    only: ['id', 'sku', 'main', 'price']
                }
            })
  end

而我想要做的是获得所有“父母”元素,但没有“变体”。我的意思是我希望所有产品都没有变种,即使它们有一些变种。

我正在尝试这样做,因为当我有一个包含大量变体的产品(fe。产品有2.5k变种)时,elasticsearch会返回整个“集合”(产品及其所有变体),如果我要列出20每个产品都有2k个变种,它将永远消失。

我正在使用简单的Product.elasticsearch.search('*')查询检索所有产品

问候。

ruby-on-rails ruby elasticsearch ruby-on-rails-5
1个回答
1
投票

要不传输所有源数据,要使用的elasticsearch关键字是“_source”https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html

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