Scripted fields for match(regex)

How to use scripted fields to find count of match a number several digits at the beginning of a value in a field with a string type?
For example, there is
doc1 with a text field = 12345
doc2 with text = 12678
doc3 with text = 12809
doc4 with text = 13098
It is necessary to find the number of documents for which the field contains '12'

This can be done easily without using scripted fields.
Just create a Metric visualization, with "Count" as the metric and then in the query bar write:
<name of the field>:12*

Thanks for the answer. But I need to create a new script field for further calculations.
Only for this value.

Unfortunately, scripted fields work only on values within each individual doc. So if a doc had 3 numeric fields you could use a scripted field to add them together, or average them, or find the min, max, etc. But not across all docs or a set of docs.
But you can also use some scripting within Visualizations in the Advanced JSON field, not sure how much it would help you as I don't know what you need to do with the value after.
Here's an example:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.