Reader small image

You're reading from  ElasticSearch Cookbook

Product typeBook
Published inDec 2013
Reading LevelBeginner
PublisherPackt
ISBN-139781782166627
Edition1st Edition
Languages
Right arrow
Author (1)
Alberto Paro
Alberto Paro
author image
Alberto Paro

Alberto Paro is an engineer, manager, and software developer. He currently works as technology architecture delivery associate director of the Accenture Cloud First data and AI team in Italy. He loves to study emerging solutions and applications, mainly related to cloud and big data processing, NoSQL, Natural language processing (NLP), software development, and machine learning. In 2000, he graduated in computer science engineering from Politecnico di Milano. Then, he worked with many companies, mainly using Scala/Java and Python on knowledge management solutions and advanced data mining products, using state-of-the-art big data software. A lot of his time is spent teaching how to effectively use big data solutions, NoSQL data stores, and related technologies.
Read more about Alberto Paro

Right arrow

Counting


It is often required to return only the count of the matched results and not the results themselves.

There are a lot of scenarios involving counting, some of them are as follows:

  • To return a number (for example, how many posts for a blog, how many comments for a post)

  • Validating if some items are available: are there posts? are there comments?

Getting ready

You need a working ElasticSearch cluster and an index populated with the script available in online code.

How to do it...

For executing a counting query, we need to perform the following steps:

  1. From command line, we will execute the following count query:

    curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_count' -d '{"match_all":{}}'
    
  2. The result returned by ElasticSearch, if everything is all right, should be as follows:

    {
      "count" : 3,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
      }
    }

The result is composed by the count result (a long type) and the shards status at the time of the query.

How it works.....

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
ElasticSearch Cookbook
Published in: Dec 2013Publisher: PacktISBN-13: 9781782166627

Author (1)

author image
Alberto Paro

Alberto Paro is an engineer, manager, and software developer. He currently works as technology architecture delivery associate director of the Accenture Cloud First data and AI team in Italy. He loves to study emerging solutions and applications, mainly related to cloud and big data processing, NoSQL, Natural language processing (NLP), software development, and machine learning. In 2000, he graduated in computer science engineering from Politecnico di Milano. Then, he worked with many companies, mainly using Scala/Java and Python on knowledge management solutions and advanced data mining products, using state-of-the-art big data software. A lot of his time is spent teaching how to effectively use big data solutions, NoSQL data stores, and related technologies.
Read more about Alberto Paro