Hit counts within a document - with wildcards


As a follow up to this question:

[hit counts within a document][1]
[1]: Hit Counts within a Document

I would like to be able to do hit counts within a document, but also include hits on wildcards. I've gotten about as far as:

    "query": {
        "wildcard": {
            "MyField": "MySearchTerm*"
    "script_fields": {
        "tf": {
            "script": "_index['MyField']['MySearchTerm'].tf()"

Which will return hits, but the "tf" score for documents which match the wildcard but not the term itself will be zero.
There is a suggestion from vineeth_mohan_2 to accomplish something similar in the above discussion, specifically with stemming but I believe the case of wildcards would be similar:

The approach there is to use multi fields.
One field , keep the raw data by declaring the analyzer as not_analyzed.
Example is sited in this link -

How would this look? I have read the link, but am not sure how to properly implement this.

Thank you,

--edited for formatting.

(system) #2