# Hit counts within a document - with wildcards

**URL:** https://discuss.elastic.co/t/hit-counts-within-a-document-with-wildcards/31561
**Category:** Elasticsearch
**Created:** [October 2, 2015, 5:58pm UTC](https://discuss.elastic.co/t/hit-counts-within-a-document-with-wildcards/31561 "2015-10-02T17:58:36Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JesseZ](https://avatars.discourse-cdn.com/v4/letter/j/8dc957/32.png) [@JesseZ](https://discuss.elastic.co/u/JesseZ)
#### Post date: [October 2, 2015, 5:58pm UTC](https://discuss.elastic.co/t/hit-counts-within-a-document-with-wildcards/31561/1 "2015-10-02T17:58:36Z")

</div>

As a follow up to this question:

[hit counts within a document][1]  
[1]: [Hit Counts within a Document](https://discuss.elastic.co/t/hit-counts-within-a-document/19643)

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 -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#_multi_fields_3)

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

Thank you,

--edited for formatting.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 11:46pm UTC](https://discuss.elastic.co/t/hit-counts-within-a-document-with-wildcards/31561/2 "2017-07-05T23:46:40Z")

</div>


