# Doc.\_version as script\_value

**URL:** <https://discuss.elastic.co/t/doc--version-as-script-value/4370>\
**Category:** Elasticsearch\
**Created:** [May 9, 2011, 9:04am UTC](https://discuss.elastic.co/t/doc--version-as-script-value/4370 "2011-05-09T09:04:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fatA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fata/32/3236_2.png) [@fatA](https://discuss.elastic.co/u/fatA)\
**Post date:** [May 9, 2011, 9:04am UTC](https://discuss.elastic.co/t/doc--version-as-script-value/4370/1 "2011-05-09T09:04:47Z")

</div>

Hello,  
I am tring to use versioning feature as increment counter. I got  
documents like {"event":"event1"} and i put them when and event  
happens, so every time i put version is incremented.

I can search that index and i use version as event counter.

One response is:  
{  
"\_index" : "events",  
"\_type" : "counter",  
"\_id" : "97",  
"\_version" : 3814,  
"\_score" : 1.0, "\_source" : {"event": "event1"}  
}

Here i use 3814 as counter.

But i would like to do a facet too. Like

{  
"version":  
true,  
"query" :  
{  
"match\_all":  
{ }  
},  
"facets":  
{  
"ms":  
{  
"terms\_stats":  
{  
"key\_field":  
"event",  
"value\_script":  
"doc.\_version"  
}  
}  
}  
}

I get  
Query Failed [Failed to execute main query]]; nested:  
PropertyAccessException[[Error: could not access: \_version; in class:  
org.elasticsearch.search.lookup.DocLookup]\n[Near : {...  
doc.\_version ....}]\n ^\n[Line: 1, Column: 1]]

How can i access version of a document in facet?

Thanks

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 9, 2011, 12:01pm UTC](https://discuss.elastic.co/t/doc--version-as-script-value/4370/2 "2011-05-09T12:01:26Z")

</div>

Version is not exposed as a "doc" value in scripts. Open an issue, can be added (though requires some thought, and if the realtime value should be exposed or the "last refresh" value).  
On Monday, May 9, 2011 at 12:04 PM, OT wrote:

> Hello,  
> I am tring to use versioning feature as increment counter. I got  
> documents like {"event":"event1"} and i put them when and event  
> happens, so every time i put version is incremented.
> 
> I can search that index and i use version as event counter.
> 
> One response is:  
> {  
> "\_index" : "events",  
> "\_type" : "counter",  
> "\_id" : "97",  
> "\_version" : 3814,  
> "\_score" : 1.0, "\_source" : {"event": "event1"}  
> }
> 
> Here i use 3814 as counter.
> 
> But i would like to do a facet too. Like
> 
> {  
> "version":  
> true,  
> "query" :  
> {  
> "match\_all":  
> { }  
> },  
> "facets":  
> {  
> "ms":  
> {  
> "terms\_stats":  
> {  
> "key\_field":  
> "event",  
> "value\_script":  
> "doc.\_version"  
> }  
> }  
> }  
> }
> 
> I get  
> Query Failed [Failed to execute main query]]; nested:  
> PropertyAccessException[[Error: could not access: \_version; in class:  
> org.elasticsearch.search.lookup.DocLookup]\n[Near : {...  
> doc.\_version ....}]\n ^\n[Line: 1, Column: 1]]
> 
> How can i access version of a document in facet?
> 
> Thanks

---

<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:** [July 6, 2017, 4:06am UTC](https://discuss.elastic.co/t/doc--version-as-script-value/4370/3 "2017-07-06T04:06:38Z")

</div>

Closed on July 6, 2017, 4:06am UTC


