Ismet
(Ismet Glumcevic)
September 16, 2022, 10:08am
1
Hi, I have two inventory fields:
inventory.warehouse1.availableInventory: 10
inventory.warehouse2.availableInventory: 20
I need to make a query with sum of these two fields and make a boost if total > 0.
I try to make runtime total field but get an error.
PUT product/_mapping
{
"runtime": {
"total": {
"type": "long",
"script": {
"source": "emit(doc['inventory.warehouse1.availableInventory'].value +
doc['inventory.warehouse2.availableInventory'].value)"
}
}
}
}
Error:
"reason": "Root mapping definition has unsupported parameters: [runtime :
{total={type=long, script=.
{source=emit(doc['inventory.warehouse1.availableInventory'].value +
doc['inventory.warehouse2.availableInventory'].value)}}}]"
How to make sum of two fields and make condition > 0?
warkolm
(Mark Walkom)
September 21, 2022, 1:47am
2
What version of Elasticsearch are you running?
Ismet
(Ismet Glumcevic)
September 21, 2022, 5:01am
3
Elastisearch version 7.10
warkolm
(Mark Walkom)
September 21, 2022, 5:51am
4
Runtime fields were added in 7.11.
Given 7.10 is unsupported, as is 7.11, you should be upgrading to 7.17 at a minimum.
1 Like
Ismet
(Ismet Glumcevic)
September 30, 2022, 8:23am
5
Thanks.
Is there some other solution for boosting sum of two fields like
inventory.warehouse1.availableInventory: 10
inventory.warehouse2.availableInventory: 20
You could naturally index the sum in a separate field and boost on that, but apart from that I am not aware of any other solution on 7.10. I would recommend upgrading to get access to runtime fields.
1 Like
system
(system)
Closed
October 28, 2022, 8:42am
7
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.