Hey: I figured out a way to do what I want:
GET /articles/_search
{
"query" : {
"match_all" : {}
},
"sort" : {
"_script" : {
"script" : "doc['tags'].values.length",
"type" : "number",
"order" : "desc"
}
}
}
On Tuesday, April 29, 2014 10:27:51 PM UTC+1, [email protected] wrote:
>
> Me again;)
>
> This looks like what I need but can't get it to work...
>
> Here's the query:
>
> GET /articles/_search
> {
> "aggs": {
> "group_by_id": {
> "terms": {
> "field": "id",
> "size":0
> },
> "aggs": {
> "sum_count": {
> "value_count": {
> "field": "tags"
> }
> }
> }
> }
> }
> }
>
> Here's the data:
>
> POST /articles/article
> {"title" : "One", "tags" : ["foo"]}
> POST /articles/article
> {"title" : "Two", "tags" : ["foo", "bar"]}
> POST /articles/article
> {"title" : "Three", "tags" : ["foo", "bar", "baz"]}
>
> And what I hope to achieve is
> id1, 1
> id2, 2
> id3,3
>
> in other words the count of tags in the list.
>
> Thanks.
>
> On Tuesday, April 29, 2014 9:25:17 PM UTC+1, [email protected] wrote:
>>
>> Folks
>>
>> Apologies about the multiple posts yesterday. A problem with the mobile
>> device I borrowed, (not android).
>>
>> Anyway what I was getting at is lets say you have rows in a database
>>
>> Then what I want to do is:
>> select col1, count(col2) group by col1
>>
>> Is this an option in Elasticsearch ?
>>
>> If I have to do something like: create index2 as select col1, count(col2)
>> group by col1 then okay I will do that in Elasticsearch.....
>>
>> How do I get these statistics on the data?
>>
>> Thanks.
>>
>> On Tuesday, April 29, 2014 12:11:58 AM UTC+1, [email protected] wrote:
>>>
>>> Yes you're right I thought of that.
>>>
>>> But I just want to get some counts
>>>
>>> Not a permanent count. Not a development change. I might want to get
>>> other counts another day.
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/fb955f0a-ff85-4869-b845-a58f321fcbf0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.