Refine your search:

We have a timechart that plots the number of entries of a specific type per day. The types are numerical (2, 3, 4...10, 11 at the moment).

Right now, doing a "timechart count by type" produces the type of chart we want, except that the first two series are 10 and 11 (so it is being ordered 10, 11, 2, 3, 4, 5, etc...)

How do I reorder the search so that the series emerge in numerical order instead of lexicographical?

asked 25 Oct '10, 19:20

simumichaelm's gravatar image

simumichaelm
11
accept rate: 0%

edited 20 Apr '11, 16:37

piebob's gravatar image

piebob ♦♦
4.6k41023


4 Answers:

Have you tried this route?: timechart count by type | sort num(type)

(From: http://www.splunk.com/base/Documentation/latest/SearchReference/Sort )

link

answered 25 Oct '10, 22:26

David's gravatar image

David
2.2k1320
accept rate: 46%

edited 25 Oct '10, 22:46

the sort command will sort the rows by a field called 'type', but in a split-by clause like this the type values are columns. So this question is really about sorting columns not rows.

(21 Apr '11, 00:33) sideview ♦

1) If the numbers really are quite small it's probably best to just use the fields command to reorder them.

<your search> | fields _time 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

2) or you could look into the transpose command. You could in theory transpose, sort and then transepose again. However transpose has some strange characteristics and you'd have to use a lot of eval contortions to end up with what you want....

3) if the numbers are NOT small, you dont want to have a fields command that lists every integer, and you dont mind bucketing the split-by field a little, you can use this:

<your search> | timechart count by date_second bins=10

Not many people know this, but if you put a bins argument after a split-by term, it actually buckets the split-by term.... So you end up with column values like "10-20", "20-30", "30-40", "40-50" etc... This may not be what you're looking for, but it has the nice side effect of sorting the buckets numerically.

link

answered 18 Jan '11, 04:28

sideview's gravatar image

sideview ♦
25.6k4543
accept rate: 46%

Or prefix type with zero.

... | eval type=if(type<10,"0"+type,type) | timechart ...

link

answered 20 Apr '11, 17:55

vbumgarner's gravatar image

vbumgarner
2.0k2419
accept rate: 26%

The way we found to do this was with a subsearch and return $field.

  • get your sorting criteria (we ran stats on a subset of the source data)
  • sort the results
  • use fields to pull only the field used for your series
  • mvcombine to turn all the records into a single one
  • then eval with mvjoin to make it into a comma or space-delimited string
  • output with return $<your list field> (the $ returns only the field's value)

Probably a more efficient way out there, but this seems to work.

link

answered 06 Nov '12, 15:22

jpreve's gravatar image

jpreve
11
accept rate: 0%

Post your answer
toggle preview

Follow this question

Log In to enable email subscriptions

RSS:

Answers

Answers + Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×288
×55

Asked: 25 Oct '10, 19:20

Seen: 1,815 times

Last updated: 06 Nov '12, 15:22

Copyright © 2005-2012 Splunk Inc. All rights reserved.