0

I have an index with a host field. I am trying to retrieve the count of documents by distinct host name.

IE:

Host1: 
    Count: 72
Host2:
    Count: 33
Host3:
    Count: 153

Each document has a host field and it is a string. I assume I need to do something involving terms and cardinality, but I can't quite nail the syntax.

1

1 Answer 1

1

How to get all possible values for field host?

curl -XGET  http://localhost:9200/articles/_search?pretty -d '
{
    "aggs" : {
        "whatever_you_like_here" : {
            "terms" : { "field" : "host", "size":10000 }
        }
    },
    "size" : 0
}'

Note

  • The result will contain a doc_count for each unique value

  • "size":10000 Get at most 10000 unique values. Default is 10.

  • "size":0 By default, "hits" contains 10 documents. We don't need them.

  • By default, the buckets are ordered by the doc_count in decreasing order.


Reference: bucket terms aggregation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.