# Getting on the "total" of a term

**URL:** <https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024>\
**Category:** Elasticsearch\
**Created:** [March 26, 2017, 7:17am UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024 "2017-03-26T07:17:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)\
**Post date:** [March 26, 2017, 7:17am UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/1 "2017-03-26T07:17:53Z")

</div>

Hi,

When I type in:

```
GET filebeat-*/log/_search
{
  "query": {

        "term" : {"terminationCause": "SUCCESS"}
    }
  }

```

I get:

```
{
  "took": 25,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 96,
    "max_score": 3.1475947,
    "hits": [
      {
        "_index": "filebeat-2017.03.19",

```

etc,

Now I want only to get the "total" field only to get the number 96.

I will be happy for any help 😀

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [March 26, 2017, 7:57am UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/2 "2017-03-26T07:57:02Z")

</div>

Hello, exist different json parsers, one of them: [Redirecting to jqlang.github.io](https://stedolan.github.io/jq/)  
jq '.hits' find necesary json param, then with grep and tr we will take total result:

> 

curl -s localhost:9200/twitte/\_search?q=_:_ | jq '.hits' |grep total |tr -cd '[[:digit:]]'

i don't sure that this method is optimized, so you should found another solution.  
But this - return correct result.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2017, 10:07am UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/3 "2017-03-26T10:07:03Z")

</div>

Set size: 0 to reduce the returned JSON.

There is also [https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#common-options-response-filtering](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#common-options-response-filtering)

---

<div class="post-metadata">

**Author:** ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)\
**Post date:** [March 26, 2017, 10:27am UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/4 "2017-03-26T10:27:22Z")

</div>

Thanks for the reply,

I tried your solution and I got:

 ![](https://us1.discourse-cdn.com/elastic/original/3X/9/9/99725ebcd67c24f3bc6b3a62e851bf4581694b25.png)

I dont really understand this result.

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [March 26, 2017, 11:20am UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/5 "2017-03-26T11:20:34Z")

</div>

Add -s param to curl , and try to use without pretty

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [March 26, 2017, 11:41am UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/6 "2017-03-26T11:41:00Z")

</div>

Tomer you should use this solution:

> curl -s localhost:9200/twitte/\_search?filter\_path=hits.total | tr -cd '[[:digit:]]'

---

<div class="post-metadata">

**Author:** ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)\
**Post date:** [March 26, 2017, 11:42am UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/7 "2017-03-26T11:42:34Z")

</div>

Yes,

It did work with jq

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2017, 11:52am UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/8 "2017-03-26T11:52:34Z")

</div>

Add size=0 to have better response time

---

<div class="post-metadata">

**Author:** ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)\
**Post date:** [March 26, 2017, 1:43pm UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/9 "2017-03-26T13:43:22Z")

</div>

Thx, it does take sometime, where should I add this?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 26, 2017, 3:18pm UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/10 "2017-03-26T15:18:22Z")

</div>

```
curl -s "localhost:9200/twitter/_search?filter_path=hits.total&size=0" | tr -cd '[[:digit:]]'
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 23, 2017, 3:18pm UTC](https://discuss.elastic.co/t/getting-on-the-total-of-a-term/80024/11 "2017-04-23T15:18:26Z")

</div>

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