# Search by file content

**URL:** <https://discuss.elastic.co/t/search-by-file-content/33138>\
**Category:** Elasticsearch\
**Created:** [October 28, 2015, 9:48am UTC](https://discuss.elastic.co/t/search-by-file-content/33138 "2015-10-28T09:48:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![emolla](https://avatars.discourse-cdn.com/v4/letter/e/7ea924/32.png) [@emolla](https://discuss.elastic.co/u/emolla)\
**Post date:** [October 28, 2015, 9:48am UTC](https://discuss.elastic.co/t/search-by-file-content/33138/1 "2015-10-28T09:48:42Z")

</div>

Hi,

I'm trying to implement my first Elasticsearch not get it to work and search for content of a file. I used an example found on the web .

First I created the mapping :

```
PUT /attachment_sample1
{
  "mappings": {
    "files": { 
      "properties": {
        "my_attachments" : { "type": "attachment" },
        "title": { "type": "string" }
      }
    }
  }
}

```

Then I added a file in B64 :

```
PUT /attachment_sample1/files/1
{
  "title": "title",
  "my_attachments" : ".... b64 ...."
}

```

And then I try to search for the file contents :

```
POST /attachment_sample1/files/_search
{
  "query": {
    "term": {
      "my_attachments": "String"
    }
  }
}

```

If I search for the title , siq ue is my record, but not content .

```
POST /attachment_sample1/files/_search
{
  "query": {
    "term": {
      "title": "String"
    }
  }
}

```

I have the plugins installed and that is not what I wrong .  
Please , you can help me? Thank you.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 28, 2015, 9:59am UTC](https://discuss.elastic.co/t/search-by-file-content/33138/2 "2015-10-28T09:59:55Z")

</div>

use a `match` query instead of `term`

---

<div class="post-metadata">

**Author:** ![emolla](https://avatars.discourse-cdn.com/v4/letter/e/7ea924/32.png) [@emolla](https://discuss.elastic.co/u/emolla)\
**Post date:** [October 28, 2015, 10:30am UTC](https://discuss.elastic.co/t/search-by-file-content/33138/3 "2015-10-28T10:30:42Z")

</div>

Thank you very much for the reply! I get results.

On the other hand, you can search for partial words? As for example

```
POST /attachment_sample1/files/_search
{
  "query": {
    "match": {
      "my_attachments": "*Part of string*"
    }
  }
}

```

Thank you.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 28, 2015, 11:42am UTC](https://discuss.elastic.co/t/search-by-file-content/33138/4 "2015-10-28T11:42:56Z")

</div>

Change your mapping and may be use ngrams

---

<div class="post-metadata">

**Author:** ![emolla](https://avatars.discourse-cdn.com/v4/letter/e/7ea924/32.png) [@emolla](https://discuss.elastic.co/u/emolla)\
**Post date:** [October 28, 2015, 2:04pm UTC](https://discuss.elastic.co/t/search-by-file-content/33138/5 "2015-10-28T14:04:56Z")

</div>

Ok! Thank you! Already he is working

---

<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:42pm UTC](https://discuss.elastic.co/t/search-by-file-content/33138/6 "2017-07-05T23:42:09Z")

</div>


