Hi,
Do you have any idea how I could obtain from:
{"timestamp": "random_date", "tag":"red", "counter": "3"} 
{"timestamp": "random_date", "tag":"blue", "counter": "2"} 
{"timestamp": "random_date", "tag":"red", "counter":"7"}
a facet that would show: 
tag: red 
count: 10
tag: blue 
count: 2
aka do the sum for the counter for each tag in only one request ?
Thank you,
Cristian
--
             
            
               
               
               
            
            
           
          
            
              
                Ivan  
                (Ivan Brusic)
               
              
                  
                    November 14, 2012,  5:58pm
                   
                   
              2 
               
             
            
              Never tried, but perhaps the terms stat facet using the counter field as 
the value field? It will return too many stats, but one of them will be the 
sum of all values.
Cheers,
Ivan
On Wed, Nov 14, 2012 at 6:10 AM, Cristian Toader ticosan@gmail.com  wrote:
Hi,
Do you have any idea how I could obtain from:
{"timestamp": "random_date", "tag":"red", "counter": "3"} 
{"timestamp": "random_date", "tag":"blue", "counter": "2"} 
{"timestamp": "random_date", "tag":"red", "counter":"7"}
a facet that would show: 
tag: red 
count: 10
tag: blue 
count: 2
aka do the sum for the counter for each tag in only one request ?
Thank you,
Cristian
--
 
--
             
            
               
               
               
            
            
           
          
            
            
              Hi Cristi 
Yep, terms stats should do the trick:
  
  
    
  terms_facet.sh 
  curl -XDELETE localhost:9200/test
#{"ok":true,"acknowledged":true}
curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"red", "counter": 3}'
#{"ok":true,"_index":"test","_type":"test","_id":"MLv-xERyTFaIdkQeaxoiaw","_version":1}
curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"red", "counter": 7}'
#{"ok":true,"_index":"test","_type":"test","_id":"JaMQIZpbQaKrgdTOtaEEcg","_version":1}
curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"blue", "counter": 5}' 
    This file has been truncated. show original 
   
  
    
    
  
  
 
But please note that the "counter" field needs to be numeric. If you 
index it as a string it won't work:
  
  
    
  terms_facet_fail 
  $ curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"blue", "counter": "5"}'
{"ok":true,"_index":"test","_type":"test","_id":"qVmyc9otSqWqUOKWoteM5Q","_version":1}
$ curl -XGET localhost:9200/test/test/_mapping?pretty=true
{
  "test" : {
    "properties" : {
      "counter" : {
        "type" : "string"
      }, 
    This file has been truncated. show original 
   
  
    
    
  
  
 
 Best regards, 
Radu 
http://sematext.com/  -- Elasticsearch -- Solr -- Lucene
On Wed, Nov 14, 2012 at 4:10 PM, Cristian Toader ticosan@gmail.com  wrote:
Hi,
Do you have any idea how I could obtain from:
{"timestamp": "random_date", "tag":"red", "counter": "3"} 
{"timestamp": "random_date", "tag":"blue", "counter": "2"} 
{"timestamp": "random_date", "tag":"red", "counter":"7"}
a facet that would show: 
tag: red 
count: 10
tag: blue 
count: 2
aka do the sum for the counter for each tag in only one request ?
Thank you,
Cristian
 
--
             
            
               
               
               
            
            
           
          
            
            
              Thank you both for the answer 
I had to do some tweaking in the after code, since the facet results are 
ordered by count and not by the stat I need. I'd which to be able to sort 
such facet by any of its component stats ;).
Cristian
On Thursday, November 15, 2012 9:57:24 AM UTC+2, Radu Gheorghe wrote:
Hi Cristi 
Yep, terms stats should do the trick: 
Elasticsearch terms facet · GitHub 
But please note that the "counter" field needs to be numeric. If you 
index it as a string it won't work: 
Elasticsearch terms facet string · GitHub 
Best regards, 
Radu 
http://sematext.com/  -- Elasticsearch -- Solr -- Lucene
On Wed, Nov 14, 2012 at 4:10 PM, Cristian Toader <tic...@gmail.com <javascript:>> 
wrote:
Hi,
Do you have any idea how I could obtain from:
{"timestamp": "random_date", "tag":"red", "counter": "3"} 
{"timestamp": "random_date", "tag":"blue", "counter": "2"} 
{"timestamp": "random_date", "tag":"red", "counter":"7"}
a facet that would show: 
tag: red 
count: 10
tag: blue 
count: 2
aka do the sum for the counter for each tag in only one request ?
Thank you,
Cristian
 
 
--