# Particular word count in particular file

**URL:** <https://discuss.elastic.co/t/particular-word-count-in-particular-file/326181>\
**Category:** Elasticsearch\
**Created:** [February 22, 2023, 12:59pm UTC](https://discuss.elastic.co/t/particular-word-count-in-particular-file/326181 "2023-02-22T12:59:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![smitak](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@smitak](https://discuss.elastic.co/u/smitak)\
**Post date:** [February 22, 2023, 12:59pm UTC](https://discuss.elastic.co/t/particular-word-count-in-particular-file/326181/1 "2023-02-22T12:59:43Z")

</div>

Hello Sir,  
I want count of keyword occurance in a particular file in elaticsearch .

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [February 22, 2023, 4:33pm UTC](https://discuss.elastic.co/t/particular-word-count-in-particular-file/326181/2 "2023-02-22T16:33:36Z")

</div>

Hi @smitak

I think you can do this with [Term Vectors](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html).

---

<div class="post-metadata">

**Author:** ![smitak](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@smitak](https://discuss.elastic.co/u/smitak)\
**Post date:** [February 24, 2023, 12:13pm UTC](https://discuss.elastic.co/t/particular-word-count-in-particular-file/326181/3 "2023-02-24T12:13:02Z")

</div>

ok Sir thaks for the reply i will check.

---

<div class="post-metadata">

**Author:** ![smitak](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@smitak](https://discuss.elastic.co/u/smitak)\
**Post date:** [February 24, 2023, 1:14pm UTC](https://discuss.elastic.co/t/particular-word-count-in-particular-file/326181/4 "2023-02-24T13:14:50Z")

</div>

I have used below query

```auto
GET index_name/_mtermvectors
{
  "ids" : ["1", "2"],
  "parameters": {
      "fields": ["file.filename"],
      "term_statistics": true,
      "offsets":false,
      "payloads":false,
      "positions":false
  }
}

```

But giving found false. Can you please share any example .  
I want to count a particular word occur means "php" how many times in a particular filea.pdf like.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [February 24, 2023, 2:41pm UTC](https://discuss.elastic.co/t/particular-word-count-in-particular-file/326181/5 "2023-02-24T14:41:21Z")

</div>

Look this example:

```auto
POST idx_test/_doc/1
{
  "text":{
    "file": "I read and read a text english"
  }
}

```

```auto
GET idx_test/_mtermvectors
{
  "ids": [
    "1"
  ],
  "parameters": {
    "fields": [
      "text.file"
    ]
  }
}

```

Output

```auto
{
  "docs" : [
    {
      "_index" : "idx_test",
      "_type" : "_doc",
      "_id" : "1",
      "_version" : 1,
      "found" : true,
      "took" : 458,
      "term_vectors" : {
        "text.file" : {
          "field_statistics" : {
            "sum_doc_freq" : 6,
            "doc_count" : 1,
            "sum_ttf" : 7
          },
          "terms" : {
            "a" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 4,
                  "start_offset" : 16,
                  "end_offset" : 17
                }
              ]
            },
            "and" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 2,
                  "start_offset" : 7,
                  "end_offset" : 10
                }
              ]
            },
            "english" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 6,
                  "start_offset" : 23,
                  "end_offset" : 30
                }
              ]
            },
            "i" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 0,
                  "start_offset" : 0,
                  "end_offset" : 1
                }
              ]
            },
            "read" : {
              "term_freq" : 2,
              "tokens" : [
                {
                  "position" : 1,
                  "start_offset" : 2,
                  "end_offset" : 6
                },
                {
                  "position" : 3,
                  "start_offset" : 11,
                  "end_offset" : 15
                }
              ]
            },
            "text" : {
              "term_freq" : 1,
              "tokens" : [
                {
                  "position" : 5,
                  "start_offset" : 18,
                  "end_offset" : 22
                }
              ]
            }
          }
        }
      }
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![smitak](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@smitak](https://discuss.elastic.co/u/smitak)\
**Post date:** [February 27, 2023, 7:10am UTC](https://discuss.elastic.co/t/particular-word-count-in-particular-file/326181/6 "2023-02-27T07:10:50Z")

</div>

okay sir. Thank you so much I will try.

---

<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:** [March 27, 2023, 7:11am UTC](https://discuss.elastic.co/t/particular-word-count-in-particular-file/326181/7 "2023-03-27T07:11:30Z")

</div>

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