-2

I want to convert the following SQL query to Elasticsearch search query. Can anyone help me with this, thanks.

Select sum(total_apples_count) 
from basket where ( apple_color in (
    select apple_color from apple_details where type = "O") || 
    apple_texture in (
        select apple_texture from apple_details where type = "O"
    ) 
);
Community
  • 1
  • 1
Murdoc230
  • 1
  • 2

1 Answers1

0

You could simply append using : as such if you're using IN:

apple_color :()

This SO might help you.

In order to use SUM within your ES query, you could do something like this within your request body:

"aggs":{  
          "total":{  
              "sum":{  
                  "script":"doc['total_apples_count'].value"
               }
           }
       }

Ref for aggregation of sum.

Community
  • 1
  • 1
Kulasangar
  • 9,046
  • 5
  • 51
  • 82
  • consider the table titles (total_apples_count, apple_details ) to be record types when it comes to elasticsearch and there are infinite counts of records in each table or data type. the sample you linked uses static values as references like :(401 403) but in my case i have over 1,000,000 records as reference. – Murdoc230 Dec 06 '16 at 14:59