# Query help: get distinct Search base on created\_at

**URL:** <https://discuss.elastic.co/t/query-help-get-distinct-search-base-on-created-at/122830>\
**Category:** Elasticsearch\
**Created:** [March 7, 2018, 6:42am UTC](https://discuss.elastic.co/t/query-help-get-distinct-search-base-on-created-at/122830 "2018-03-07T06:42:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohammad\_S07](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@mohammad\_S07](https://discuss.elastic.co/u/mohammad_S07)\
**Post date:** [March 7, 2018, 6:42am UTC](https://discuss.elastic.co/t/query-help-get-distinct-search-base-on-created-at/122830/1 "2018-03-07T06:42:53Z")

</div>

hi  
first, I have apologized for my weak English, I store data in the elastic search like this

```
{
      "_index": "my_index",
      "_type": "doc",
      "_id": "6lDquGEBFRQVe0x93eHk",
      "_version": 1,
      "_score": 1,
      "_source": {
        "Barcode": "6947503728601",
        "category":"pen", 
        "name": "panter",
         "price":"4$",
        "created_at": "1519225855"
      }
      }

```

Each data set has a barcode. For example, all panter pen have "6947503728601" as a barcode but they have different created\_at values.

I want to search for a barcode and get the last one of them based on the created\_at value (I want to get one)

How can I implement the search?

---

<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:** [April 4, 2018, 6:43am UTC](https://discuss.elastic.co/t/query-help-get-distinct-search-base-on-created-at/122830/2 "2018-04-04T06:43:00Z")

</div>

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