I have mapping for product like listed below:
{
"PRODUCT" : {
"properties" : {
......................
"price" : {
"type" : "nested",
"properties" : {
"id" : {
"type" : "string"
},
"type" : {
"type" : "string"
},
"value" : {
"properties" : {
"gb" : {
"type" : "long"
},
"fr" : {
"type" : "long"
},
"usa" : {
"type" : "long"
},
"rus" : {
"type" : "long"
},
"grmn" : {
"type" : "long"
}
}
},
"test" : {
"type" : "long"
}
}
}
.........................
}
}
}
Here is example of object:
{
.................
"price" : [{
"id" : "default",
"type" : "price",
"value" : {
"gb" : 2290,
"grmn" : 2290
"fr" : 2250,
"usa" : 1980,
"rus" : 73280,
},
"test" : 1
}, {
"id" : "usCristmasPromo",
"type" : "promo",
"value" : {
"gb" : 2290,
"grmn" : 2290
"fr" : 2250,
"usa" : 1760,
"rus" : 73280,
},
"test" : 1
}, {
"id" : "regularCustomerDiscount",
"type" : "promo",
"value" : {
"gb" : 2175,
"grmn" : 2175
"fr" : 2137,
"usa" : 1881,
"rus" : 69616,
},
"test" : 1
}
],
........................
}
Each product have one 'default' price object with type='price' and dozens prices with type='promo'. In field id name of promotion action stores. User have region property (gb/fr/grmn/rus) and several promotions (some of them global, some only for regular customers). I need to build statistical facet (min/max) for price value. That query works well;
{
"size" : 10,
"query" : {
....................
},
"sort" : [{
"price.value.usa" : {
"order" : "asc",
"mode" : "min",
"nested_filter" : {
"terms" : {
"price.id" : [
"regularCustomerDiscount",
"default"
]
}
}
}
}
],
"facets" : {
"priceStatistic" : {
"nested" : "price",
"statistical" : {
"field" : "test"
},
"facet_filter" : {
"terms" : {
"price.id" : [
"regularCustomerDiscount",
"default"
]
}
}
}
}
}
But if i change "field" : "test" for "field" : "value.usa" i will recieve exception:
nested: FacetPhaseExecutionException[Facet [priceStatistic]: No mapping found for field [value.usa]
I test different variations:
"script": "doc['value.usa'].value"
"script": "doc['value']['usa'].value"
"script": "doc.get('value').get('usa').value"
"script": "doc.get('value.usa').value"
"script": "doc.value.usa.value"
and etc, but no one work.
how can i recive min/max price of products in query for regular customer from usa region?