symfony - Elasticsearch - Count distinct -
i have basic index logs
some logs visit of user1 user2
i managed count total of visits user has received, don't know how count total of distinct users user has received
this giving me logs user
{ "post_filter":{ "bool":{ "must":[ { "term":{ "message":"visit" } }, { "term":{ "ctxt_user2":"733264" } } ] } }, "query":{ "match_all":{} } }
actually, i'm using foselasticabundle symfony2
$filter->addmust((new term())->setterm('message', 'visit')); $filter->addmust((new term())->setterm('ctxt_user2', $this->search->getvisit()));
i read pages in es doc aggregator, never managed want
convert sql, need
select count(discting ctxt_user1) logs ctxt_user2 = 733264
edit:
cardinality seams need. need find how use foselasticabundle
"aggs": { "yourdistinctcount": { "cardinality": { "field": "ctxt_user1" } } }
try query ( not tested...):
{ "query" : { "bool":{ "must":[ { "term":{ "message":"visit" } }, { "term":{ "ctxt_user2":"733264" } } ] } }, "aggs": { "yourdistinctcount": { "terms": { "field": "ctxt_user1" } } } }
the post_filter
query cannot used in case. write on elastic.co website: post_filter
applied search hits @ end of search request, after aggregations have been calculated.`
hth,
Comments
Post a Comment