Aggregation Doubt

Hello,

I need to know how many customers shopped in different stores. Consider the following index mapping:

curl -X PUT "localhost:9200/buy-data" -d '{
  "mappings": {
    "order": {
      "properties": {
        "state":{
          "type": "string",
          "index": "not_analyzed"
        },      
        "city":{
          "type": "string",
          "index": "not_analyzed"
        },
        "store":{
          "type": "string",
          "index": "not_analyzed"
        },
        "customer":{
          "type": "string",
          "index": "not_analyzed"
        },
        "date": {
          "type":   "date",
          "format": "dd-MM-yyyy"
        }
      }
    }
  }
}'

Create some sample data for the above index. The sample data is in the following format.

curl -X PUT "localhost:9200/buy-data/order/1" -d '{
  "state": "NY",
  "city": "New York",
  "store": "Manhathan Canal St",
  "customer": "John Smith",
  "date": "20-02-2018"
}'
curl -X PUT "localhost:9200/buy-data/order/2" -d '{
  "state": "NY",
  "city": "New York",
  "store": "Brooklin Atlantic Ave",
  "customer": "Alice Perri",
  "date": "20-02-2018"
}'
curl -X PUT "localhost:9200/buy-data/order/3" -d '{
  "state": "NY",
  "city": "New York",
  "store": "Queens 40th St",
  "customer": "John Smith",
  "date": "25-02-2018"
}'
curl -X PUT "localhost:9200/buy-data/order/4" -d '{
  "state": "NY",
  "city": "New York",
  "store": "Queens 40th St",
  "customer": "John Smith",
  "date": "28-02-2018"
}'
curl -X PUT "localhost:9200/buy-data/order/5" -d '{
  "state": "NY",
  "city": "New York",
  "store": "Brooklin Atlantic Ave",
  "customer": "Alice Perri",
  "date": "28-02-2018"
}'

Considering the above data the expected response is 1 because only 'John Smith' bought at different stores.

I do not know how to get this answer, I've tried various aggregations.

Does anyone have any ideas?

Tks!

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