# Incremental counter in elasticsearch

**URL:** <https://discuss.elastic.co/t/incremental-counter-in-elasticsearch/97780>\
**Category:** Elasticsearch\
**Created:** [August 21, 2017, 2:15pm UTC](https://discuss.elastic.co/t/incremental-counter-in-elasticsearch/97780 "2017-08-21T14:15:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayme](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayme/32/6008_2.png) [@Jayme](https://discuss.elastic.co/u/Jayme)\
**Post date:** [August 21, 2017, 2:15pm UTC](https://discuss.elastic.co/t/incremental-counter-in-elasticsearch/97780/1 "2017-08-21T14:15:12Z")

</div>

Hi,  
I have a +/- large index of 200M documents, the content inside can be seen as a representation of a "user". One user/ JSON document can get fairly large.

I have a daily cron that does a search for each of the users in the index,  
it searches for other "users" that fall in his/ her filter and orders them by activeness/ attractiveness, nearby filters.

I want to keep track on how much a certain user has already been "used" / "seen" in other peoples searches.. so most logical would be to keep track of a field "usage" field that increments each time a user is found/ returned.  
This data can be volatile as the counter can be reset every day.

There are a few drawbacks / disadvantages though :

- a complete user document needs to be rewritten each time that field gets incremented /
- searches will go slower as the complete index will be rewritten each day / complete iteration.
- need to manually flush the counter value each day when starting a new iteration..

Would want to use parent/ child for this, but apparently you can't sort on "child\_values" in elasticsearch + in a sense this also written to the same index corpus starting from ES 6.0.

What's the best approach in solving something like this?  
Write a custom plugin and keep values like this in memory?

Thx  
Jayme

---

<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:** [September 18, 2017, 2:15pm UTC](https://discuss.elastic.co/t/incremental-counter-in-elasticsearch/97780/2 "2017-09-18T14:15:14Z")

</div>

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