Elasticsearch nested object based filter and count operation

I am new on elasticsearch. trying to use it on analytics calculations. I don't know, does it possible to do that but, I am trying to find customers who has 0 purchases. I stored, orders as nested object arrays for each customer. Here you may found an example mapping properties of customers index:

"first_name" => [
 "type" => "text"
],
"last_name" => [
	"type"=> "text"
],
"email" => [
	"type"=> "text"
],
"total_spent" => [
	"type"=> "text"
],
"aov" => [
	"type"=> "float"
],
"orders_count" => [
	"type"=> "integer"
],
"orders" => [
	"type" => "nested",
	"properties" => [
		"order_id" => [
			"type"=>"text"
		],
		"total_price" => [
			"type"=>"float"
		]
	]
]

Example Customer indexes:

    [
   {
      "_index":"customers_index",
      "_type":"_doc",
      "_id":"1",
      "_score":1,
      "_source":{
         "first_name":"Stephen",
         "last_name":"Long",
         "email":"egnition_sample_91@egnition.com",
         "total_spent":"0.00",
         "aov":0,
         "orders":[]
      }
   },
   {
      "_index":"customers_index",
      "_type":"_doc",
      "_id":"2",
      "_score":1,
      "_source":{
         "first_name":"Reece",
         "last_name":"Dixon",
         "email":"egnition_sample_57@egnition.com",
         "total_spent":"0.10",
         "aov":"0.1",
         "orders":[
            {
               "total_price":"0.10",
               "placed_at":"2020-09-24T20:08:35.000000Z",
               "order_id":2723671867546
            }
         ]
      }
   },
   {
      "_index":"customers_index",
      "_type":"_doc",
      "_id":"3",
      "_score":1,
      "_source":{
         "first_name":"John",
         "last_name":"Marshall",
         "email":"egnition_sample_94@egnition.com",
         "total_spent":"0.10",
         "aov":"0.04",
         "orders":[
            {
               "total_price":"0.10",
               "placed_at":"2020-09-24T20:10:52.000000Z",
               "order_id":2723675930778
            },
            {
               "total_price":"0.30",
               "placed_at":"2020-09-24T20:09:45.000000Z",
               "order_id":2723673899162
            },
            {
               "total_price":"0.10",
               "placed_at":"2020-09-16T09:55:22.000000Z",
               "order_id":2704717414554
            }
         ]
      }
   }
]

First of all, I want to ask do you think this kind of mapping fits with nature of elastic search? As an example, I am able to group customers by specific date range and sum total_spent as aggregated data. However, What I want to learn is, does it possible to find customers who has no order with the filtering nested orders array for the specific date range? Do you think, this kind of queries, has some performance issues?

I have not familiar with nosql databases. I am an RDBMS guy. So, I am trying to understand the concept of Elastic Search as an analytics db.

Thanks for responses

Edit:
Possible response that I expected:

    {
    ...
    "aggregations":[
    {
    "date":"2020-09-01",
    "total_customers_zero_purchased":15
    }
    ...
    ]
    }

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