我使用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('*')查询检索所有产品
问候。
要不传输所有源数据,要使用的elasticsearch关键字是“_source”https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html