- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to trim the last line from query
Hi ,
I am passing my search query in token using $job.search$, want to remove the last line from the query.
For example , my query is
index="idx2" report="ABC"
| table number,description,description,group,sev ,closurec, created, state, closed_date
| timechart count by state
So , I want to evaluate/pass only below in defined token
index="idx2" report="ABC"
| table number,description,description,group,sev ,closurec, created, state, closed_date
Please let me know , how to remove the line after last occurrence of pipe"|" and retain all things before it.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content


Try editing the token as part of the drilldown. Edit the source dashboard's source and you'll see something like this:
<drilldown>
<link target="_blank">search?q=$job.search$&earliest=$field1.earliest$&latest=$field1.latest$</link>
</drilldown>
A little-known feature of Simple XML is the ability to modify tokens before invoking the drilldown. I haven't done a lot with this feature, so I'm not sure of all it can do or even if it can do what is below. Experiment and let us know how it goes.
<drilldown>
<eval token="job_search">$job.search$</eval>
<eval token="srch">rex field=$job_search$ "(?<srch>.*)\|"</eval>
<link target="_blank">search?q=index=$srch$&earliest=$field1.earliest$&latest=$field1.latest$</link>
</drilldown>
If this reply helps you, Karma would be appreciated.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@richgalloway
Thank you for your response. It not worked. After using rex field, drilldown coming like below
rex field=search index="idx2" report="ABC" | table number,description,description,group,sev ,closurec, created, state, closed_date | timechart count by state "(?.*)|"
Please suggest.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content


What does your <drilldown>
paragraph look like?
If this reply helps you, Karma would be appreciated.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@richgalloway Please see below.
<search>
<query>index="idx2" report="ABC" | table
number,description,description,group,sev,closurec, created, state, closed_date
|stats count by state
</query>
<set token="job_search">$job.search$</set>
<set token="srch">rex field=$job_search$ "(?.*)\|"</set>
</search>
<option name="drilldown">cell</option>
<drilldown>
<link target="_blank">search?q=$srch$&earliest=$field1.earliest$&latest=$field1.latest$&form.sel_group=$sel_group$&;display.page.search.mode=smart&dispatch.sample_ratio=1%0A&workload_pool=&display.page.search.tab=statistics&display.general.type=statistics
</drilldown>
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content


Have you tried the code from my answer? The code that uses <eval token...
and not <set token...
? The eval
and set
options do different things.
If this reply helps you, Karma would be appreciated.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes , that also not worked. 😞
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adding to @richgalloway 's answer, the full regex would look like this:
| makeresults
| eval job.search="index=\"idx2\" report=\"ABC\" | table number,description,description,group,sev ,closurec, created, state, closed_date | timechart count by state"
| rex field=job.search "(?<search>.*)\s*\|[^\|]+"
(?<search>.*)\s*\|[^\|]+
(?<search>.*)
- Grab everything .*
in the job.search field and assign it to the new field search
\s*\|[^\|]+
- Match anything with any number of spaces \s
followed by a pipe |
followed by any number of non-pipe characters [^\|]+
. Since they are not within the parentheses, all matching characters are discarded.
You could also force it to match the timechart command:
| makeresults
| eval job.search="index=\"idx2\" report=\"ABC\" | table number,description,description,group,sev ,closurec, created, state, closed_date | timechart count by state"
| rex field=job.search "(?<search>.*)\s*\|\s*timechart[^\|]+"
Jacob
If you feel this response answered your question, please do not forget to mark it as such. If it did not, but you do have the answer, feel free to answer your own post and accept that as the answer.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content


It's not clear at what point you want to change $job.search$, but you may be able to use rex
.
... | eval search=$job.search$ | rex field=search "(?<token>.*)\|" | ...
If this reply helps you, Karma would be appreciated.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@richgalloway wanted this for drilldown to open in new window. For this I am passing whole search query in one token to drilldown. But facing challenge when query conatins stats/timechart at the end.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying something like this inside the search query, but Its not working
replace($job.search$,"\[|\]|\"","")
