how to force indexing over calculated number field

Hi,

I have created a Calculated number field that calculates the number of working days since the issue is last updated. The field works well but the issue is that to be able to search that field, the issues must be indexed. Normally an issue is indexed at any update over it but in my case there will be no updates. So the field won't be searchable until you perform a manual re-indexing. Is there is a way to enforce the indexing of an issue when the field is calculated? Or there is a better way to search for issues that are not updated since more than 3 working days?

1 answer

0 votes

>but in my case there will be no updates.

That stands out to me as being wrong.  Why will there be no updates?  What is your field calculating?  If there's no updates to the issue, then it suggests you're calculating from dynamic or non-JIRA data, which means a scripted field is not the right approach.

Hi @Nic Brough [Adaptavist],

The field is calculating the number of working days since the last updated date.

When I search for this field in JQL(e.g. "field">3) it doesn't return a value but the value is there. After I perform an indexing the issues are retrieved through the JQL query.

Ok, that makes sense.

The problem here is that you've defined a data item that is not static.  Think of it this way - when should the field be calculated?  The underlying information of "time since x" is variable - it's a different answer now from what it was when I first answered, when I got up and read the response, when I started typing.  JIRA stores time data in milliseconds, so that's the highest granularity you could use and means you could really be asking to index the field 1000 times a second.  In real life, you've probably got a granularity of an hour or a day or something more sane, but the problem is the same - you're going to need to calculate and re-index your entire system on every "grain" of time.

A better answer would be "calculate on display".  Take a fixed time from the issue (last updated date) and make the system displaying it show "elapsed time".  I don't know how to do it myself, but some javascript for "show me time elapsed since updated date" that runs on issue view solves the display problem (of all my Atlassian related skills, javascript is the weakest).  For searching, use the relative times and the raw updated date.

@Nic Brough [Adaptavist], my problem is not with the display. The field is displayed correctly whenever I check the request but my problem is with being able to query it. Before the indexing the value is considered as null but you can see the value of the field which is correct.

I think you've missed the point.  Your design is broken because your search is for a value that changes 1,000 times a second.  Storing "elapsed time" in the scripted field is inaccurate even before the write cycle is finished.

What you need to do is re-phrase the search in useful terms.  For example, instead of "time elapsed since update is over seven days", use "updated more than seven days ago".  When you rewrite the question with the dynamic value being "now" instead of "elapsed time", the problem goes away.

@Nic Brough [Adaptavist], my field gets the difference between the "update" date and "now" and tweaks it to remove the weekends.

Ok, there's an additional calculation to be done, that's fine.

But, again, it's still changing 1,000 times a second during the working day.  You still need to change your approach from "elapsed" to "time since"

Suggest an answer

Log in or Sign up to answer
Community showcase
Asked Thursday in Jira Ops

I'm John Allspaw, Ask Me Anything about incident analysis and postmortems

I'm John Allspaw, co-founder of   Adaptive Capacity Labs, where we help teams use their incidents to learn and improve. We bring research-driven methods and approaches to drive effective inciden...

751 views 7 7
View question

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you