# How to get only one log per transaction that fits a match

**URL:** <https://discuss.elastic.co/t/how-to-get-only-one-log-per-transaction-that-fits-a-match/101997>\
**Category:** Elasticsearch\
**Created:** [September 27, 2017, 2:18pm UTC](https://discuss.elastic.co/t/how-to-get-only-one-log-per-transaction-that-fits-a-match/101997 "2017-09-27T14:18:17Z")\
**Posts on this page:** 5\
**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:** [September 27, 2017, 2:18pm UTC](https://discuss.elastic.co/t/how-to-get-only-one-log-per-transaction-that-fits-a-match/101997/1 "2017-09-27T14:18:17Z")

</div>

Hi,

I want to know how many transactions have fields value between 0 and 3. For this the following query is good:

```
POST /filebeat-*/log/_search?scroll=1m&pretty
{
    "size": 100,
   "query": {
    
   "bool":{ 

      "must": [
        
		{ "match": {"concatenated": "FALSE"}},
        { "range": 
          { 
            "delay": 
              {
                "gte": 0,
                "lt": 3
              } 
          }
        },
        { "range": 
          { 
            "eventTimestamp.raw": 
              {
                "gte" : "now-999m/m",
                "lt" : "now/m"
              } 
          }
        }
      ]
   }
  }
} 

```

The problem is that every transaction has around 5 logs, therefore, I will get: (around 5)\*(the real amount of transactions have fields value between 0 and 3).

How can I get the exact amount of transactions have fields value between 0 and 3, every transaction has a field called transactionId and all of its logs have the same transactionId .

I saw that in the past I could've use [this](https://stackoverflow.com/questions/29016271/how-to-get-latest-values-for-each-group-with-an-elasticsearch-query), but today there is no "[search\_type=count](https://discuss.elastic.co/t/no-search-type-for-count/101994)" so this does not work for me.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [September 27, 2017, 6:11pm UTC](https://discuss.elastic.co/t/how-to-get-only-one-log-per-transaction-that-fits-a-match/101997/2 "2017-09-27T18:11:05Z")

</div>

Maybe use the 'cardinality' aggregation on your transaction field ?

---

<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:** [September 28, 2017, 1:01pm UTC](https://discuss.elastic.co/t/how-to-get-only-one-log-per-transaction-that-fits-a-match/101997/3 "2017-09-28T13:01:47Z")

</div>

You mean something like this:

POST /filebeat-\*/log/\_search?scroll=1m&pretty  
{  
"size": 999,  
"query": {

```
   "bool":{ 

      "must": [
        
		{ "match": {"concatenated": "FALSE"}},
        { "range": 
          { 
            "delay": 
              {
                "gte": 0,
                "lt": 3
              } 
          }
        },
        { "range": 
          { 
            "eventTimestamp.raw": 
              {
                "gte" : "now-99999m/m",
                "lt" : "now/m"
              } 
          }
        }
      ]
   }
  }
}
?
```

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [September 28, 2017, 1:03pm UTC](https://discuss.elastic.co/t/how-to-get-only-one-log-per-transaction-that-fits-a-match/101997/4 "2017-09-28T13:03:58Z")

</div>

See [cardinality aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-cardinality-aggregation.html)

---

<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:** [October 26, 2017, 1:04pm UTC](https://discuss.elastic.co/t/how-to-get-only-one-log-per-transaction-that-fits-a-match/101997/5 "2017-10-26T13:04:08Z")

</div>

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