I need to count the number of failed (status != 202) '/orders' requests. But I can't figure out how to write a query.
I grouped requests-responses by request_id but then couldn't find out how to filter aggregation results by request's path and response's status. Also, I tried to find something in Pipeline Aggregation. There is a Bucket Selector Aggregation in docs, but the problem is that it works only with numeric metrics. So, I'm stuck(
Is it possible to achieve my goal at all? If so, can you give me a direction, please?
Or maybe it would be better to reconsider index design?
You can use a Boolean query. must_not section to eliminate status=202, filter section to match message=response and path=/orders.
Since you only want count, you can hit the _count endpoint instead of _search.
Hello, Glen. Thank you for the response. I appreciate your help! If I get your suggestion correctly, then I can't apply it to my problem. Let me explain why.
My task is to count failed transactions for a specific path. One transaction produces two log entries: request and response. A request entry contains :path field and response has :status field. Because these fields are placed in separate entities, I can't simultaneously filter section with match message=response and path=/orders. I need to aggregate it first. But when I aggregate requests and responses into buckets by request_id (one bucket == one transaction) I lose immediate access to :path and :status fields.
I've recently *tried to achieve a part of desired result with next steps:
Aggregate requests and responses into buckets by :request_id
Add :path attribute to newly formed buckets using scripted_metric
Filter resulted buckets using Bucket Selector Aggregation
But this didn't work out. Resulting response contained empty :buckets field.
So, my questions are still stand:
Is it possible to achieve my goal at all?
Maybe I should reconsider index design? Merge request and responses into single entity, for example.
Sorry, yeah, I should have noticed the requests and responses are in distinct docs.
(The detail and clarity - "verbosity" - is always much appreciated.)
Yes, it would be a very good idea to merge these into a single document. The scenario you're trying to accomplish is resounding testimony to the benefit. Elasticsearch's join-like capabilities are limited to nested documents and parent/child; with this data set, just merging the response into the request document is sufficient.
If you stand up a Kibana instance, you can load sample data. One of the sample data sets is Web Logs, which you'll find is supported by a single index, in which the documents contain all the request info plus the response.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.