Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I filter the counter less than a parameter in Kibana?

I have a question similar to this: How can I filter a field greater than a counter on Kibana? https://github.com/elastic/kibana/issues/9684

On this link there is a perfect answer: You need use "{'min_doc_count': X}" on your Json Input Advanced Bucket Option. Perfect, It runs exactly like I want, except because I want the oposite, something like "max_doc_count".

For my surprise, this options doesn't existis... Some one knows what would be the "max_doc_count" equivalent of?

In SQL would be something like: GROUP BY my_field HAVING COUNT(*) < 3

Thanks.

like image 868
Doglas Avatar asked Jul 31 '18 22:07

Doglas


People also ask

How do I filter logs in Kibana dashboard?

Use the Logs app in Kibana to explore and filter your logs in real time. You can customize the output to focus on the data you want to see and to control how you see it. You can also view related application traces or uptime information where available.

How do I use the not operator in Kibana?

The NOT operator negates the search term. For example, search for any response keyword except 404: Alternatively, use - or ! before the search term to denote negation. The Kibana filter helps exclude or include fields in the search queries. 1. Create a filter by clicking the +Add filter link.

How to use the Kibana filter?

The Kibana filter helps exclude or include fields in the search queries. 1. Create a filter by clicking the +Add filter link. A dialog box appears to create the filter. 2. Select a Field from the dropdown menu or start searching to get autosuggestions. 3.

How do I search for specific fields in Kibana?

To match an exact string, use quotation marks. For example, "get elasticsearch" queries the whole string. Kibana allows searching individual fields. Check all available fields on the bottom left menu pane under Available fields: To perform a search in a specific field, use the following syntax: The query syntax depends on the field type.

What is the use of Kibana in Elasticsearch?

Kibana is an open source analytics and visualization platform designed to work with Elasticsearch. Kibana can be used to search, view and interact with data stored in Elasticsearch indices. However — Kibana UI is so robust and exhaustive that there are multiple options to customize, filter (KQL vs Lucene vs DSL), share & save


1 Answers

The correct way of doing this in ES is to use a bucket_selector pipeline aggregation with the special _count path.

POST /_search
{
  "size": 0,
  "aggs": {
    "my_terms": {
      "terms": {
        "field": "my_field.keyword"
      },
      "aggs": {
        "max_doc_count": {
          "bucket_selector": {
            "buckets_path": {
              "count": "_count"
            },
            "script": {
              "source": "params.count < 3"
            }
          }
        }
      }
    }
  }
}

In the results, the my_terms aggregations will only contain buckets where the document count is < 3. No need to order anything or to program your application to ignore anything.

like image 97
Val Avatar answered Oct 09 '22 11:10

Val