Maximum ID from tweets of a specific user

Dear all,

I am storing the tweets from twitter into elasticsearch & I want to get the maximum value of a field {id} for a specific user ID {user.screen_name}. Please help me with the elasticsearch query part. Right Now i am using this query.

POST /twitter/_search?size=0
{
"aggs" : {
"max_id" : { "max" : { "field" : "id" } }
}
}
Thanks in Advance.

Regards
Pankaj

Do you mean:

  1. You want the max id for a single specified name
    -- You need a query_string or terms filter like
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "user.screen_name: TARGETNAME",
            "analyze_wildcard": true
          }
        }
  1. You want the max id for every unique name
    -- You do a terms aggregation by name before you do the max aggregation by id
"aggs": {
    "uniquenames": {
      "terms": {
        "field": "screen_name",
         "order": {
          "maxpost": "asc"
        }
      },
      "aggs": {
        "maxpost": {
          "max": {
            "field": "id"
          }
        }
      }

I am using this query. But this is not returning desired result. I want to query elasticsearch using a specific username from field {user.screen_name} and return the maximum value of field {id}.

POST /twitter/_search
{
"aggs": {
"uniquenames": {
"terms": {
"field": "user.screen_name.keyword",
"order": {
"maxpost": "desc"
}
},
"aggs": {
"maxpost": {
"max": {
"field": "id"
}
}
}
}
}
}

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