# Dealing with nested documents and multiplication

Hello, I need help I want to calculate the score of a document using the
information in a nested doc of it.

More context, I have the document mapping.

"product": {
"properties": {
"name" : {
"type": "string"
}
"offers": {
"type": "nested",
"properties" : {
"id" : {
"type": "string",
"index": "not_analized"
}
"price": {
"type": "double"
}
}
}
}
}

A doc example would be :

"product": {
"name" : "tv",
"offers" : [
{"id" : "1", "price": 10},
{"id" : "2", "price": 11},
{"id" : "3", "price": 7},
]
}

I want to make the following query. Given a set of offers with an id and a
expected price, for instance

query : [{"id": "1", "price" : 15}, {"id": "3", "price": 15}]

I wanna order the doc according the fallowing algorithm
the score of a doc should be.

Do the intersection of the query offers with the offers of the doc.
for each nested offers of the doc in the intersection, apply a linear decay
function with the corresponding offer in the query
and finally multiply these value.

I can do almost all this query, but as the offers are nested document, I
can modify the doc score with
min, max, sum, avg but not with product.

Here is what i was trying...

{
"explain": true,
"query": {
"bool" : {
"should" : [{
"nested" : {
"query" : {
"function_score" : {
"filter" : {
"term" : { "id" : "1"}
},
"functions" : [{
"linear" : {
"price" : {
"origin" : "15",
"scale" : "2",
"offset" : "1"
}
}
}]
}
},
"path" : "offers",
"score_mode" : "sum"
}
},{
"nested" : {
"query" : {
"function_score" : {
"filter" : {
"term" : { "id" : "3"}
},
"functions" : [{
"linear" : {
"price" : {
"origin" : "15",
"scale" : "2",
"offset" : "1"
}
}
}]
}
},
"path" : "offers",
"score_mode" : "sum"
}
}]
}
}
}

But the nested is summing and the should is also summing.
Another idea is replace the product with the sum of logarithm, so I would
need in this
case calculate the log of the linear decay function.

In conclusion,
I can not figure out a way of multiply in the score of the parent document
the value calculated in each nested child.
I can not figure out a way of get the log of the nested query and then use
the sum of the should.

does Some one have an idea of how to do it?

Thanks and sorry for the long post.
Matias.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.