# Aggregation Doubt

**URL:** <https://discuss.elastic.co/t/aggregation-doubt/121924>\
**Category:** Elasticsearch\
**Created:** [February 28, 2018, 6:54pm UTC](https://discuss.elastic.co/t/aggregation-doubt/121924 "2018-02-28T18:54:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodolfobarbeiro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodolfobarbeiro/32/28264_2.png) [@rodolfobarbeiro](https://discuss.elastic.co/u/rodolfobarbeiro)\
**Post date:** [February 28, 2018, 6:54pm UTC](https://discuss.elastic.co/t/aggregation-doubt/121924/1 "2018-02-28T18:54:36Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 28, 2018, 6:54pm UTC](https://discuss.elastic.co/t/aggregation-doubt/121924/2 "2018-03-28T18:54:59Z")

</div>

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