Boost based on value of sum two fields

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?

What version of Elasticsearch are you running?

Elastisearch version 7.10

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

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

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.