Filling the holes


(Aleks) #1

Hi there,

I'm currently working with ElasticSearch to make a report that will show
stocks variable on an e-commerce web site.
Every minutes, I get products stocks informations (available, sold, initial
stock) that has changed during the last minute.

Here is an example of two products P1 and P2 with the available stock
evolution and the aggregation expected VS what I get :

ES result | 30 20 10 15
expected | 30 20 18 15
P1 | 10 8 6
P2 | 20 12 10 9
h h+1 h+2 h+3

Is is possible to fill the holes with the last (top) result in an
aggregation ?

Here is my mapping :

{
"stock": {
"properties": {
"OperationID": {
"type": "long"
},
"ProductID": {
"type": "long"
},
"StockEvolution": {
"type": "nested",
"properties": {
"Date": {
"type": "date",
"format": "dateOptionalTime"
},
"Initial": {
"type": "long"
},
"Real": {
"type": "long"
},
"Sold": {
"type": "long"
}
}
}
}
}
}

And here is a ES request I'm using :

{
"size": 0,
"query": {
"term": {
"OperationID": "$1"
}
},
"aggs": {
"stock_by_date": {
"nested": {
"path": "StockEvolution"
},
"aggs": {
"stocks": {
"terms": {
"field": "StockEvolution.Date",
"size" : 0,
"order" : { "_term" : "asc" }
},
"aggs": {
"sum_initial": {
"sum": {
"field": "StockEvolution.Initial"
}
},
"sum_real": {
"sum": {
"field": "StockEvolution.Real"
}
},
"sum_sold": {
"sum": {
"field": "StockEvolution.Sold"
}
}
}
}
}
}
}
}

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/122861ad-5928-4cdd-9825-297e923a0162%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #2