Fadel
Fadel

Reputation: 711

Elasticsearch Get Parent Fields

in my index i have two types Ads ans Product,

Product :

_index: fadel
_type: product
_id: 103|2
_version: 1
_score: 1
_source: {
code: 35569058
manufacturer: Packard Bell
tax_class_id: [ ]
visibility: 4
price: [ ]
in_stock: 1
.....
....

Ads

_index: fadel
_type: ads
_id: 92
_version: 1
_score: 1
_source: {
customer_id: 2
ads_id: 92
product_id: 28
price_current: 1200.0000
is_pro_customer: 0
state: 13
qty_current: 19
}
fields: {
_parent: 28|2
}

so how can i get all ads for a product, and how I can retrieve the associated product to an ad

PS : 1 product may have one or more ads, but an ad associated to 1 product

thank you

Upvotes: 0

Views: 905

Answers (1)

imotov
imotov

Reputation: 30163

The _parent field is indexed and stored, so you can use it as any other field. For example, you can search using _parent field to retrieve all ads for the given product, or you can retrieve the value store in the _parent field and use Get operation to retrieve the product.

Upvotes: 1

Related Questions