# ElasticSearch Search Query and Highlight on the Attachment not working as expected

**URL:** https://discuss.elastic.co/t/elasticsearch-search-query-and-highlight-on-the-attachment-not-working-as-expected/51034
**Category:** Elasticsearch
**Created:** [May 26, 2016, 8:58am UTC](https://discuss.elastic.co/t/elasticsearch-search-query-and-highlight-on-the-attachment-not-working-as-expected/51034 "2016-05-26T08:58:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![RameshDevarapu](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@RameshDevarapu](https://discuss.elastic.co/u/RameshDevarapu)
#### Post date: [May 26, 2016, 8:58am UTC](https://discuss.elastic.co/t/elasticsearch-search-query-and-highlight-on-the-attachment-not-working-as-expected/51034/1 "2016-05-26T08:58:04Z")

</div>

Hi,

I am New to ES, i am trying to index a complete text file in ES. i am using ElasticSearch 2.3.3 with attachment Plugin (mapper-attachement-2.3.3). i am able to index the document(of size 613KB) without any error.  
Below are code snippets

```
public class Document1
{
    public Document1()
    {

    }

    public string Title { get; set; }

    [Attachment(Name = "file")]
    public Attachment File { get; set; }    

```

}  
**Index creation:**

var mappingResponse = client.CreateIndex(index, c =\> c  
.Mappings(m =\> m  
.Map(mm =\> mm.AutoMap())  
)  
);

**indexing a File.**  
var attachment = new Attachment();  
attachment.Content = Convert.ToBase64String(File.ReadAllBytes(path));  
attachment.ContentType = "plain/txt";  
[attachment.Name](http://attachment.Name) = "XA121026\_2014\_06\_09\_AXIS\_ERR.txt";

```
        var doc = new Document1()
         {
             Title = "XA121026_2014_06_09_AXIS_ERR.txt",
             File = attachment
         };

         var i = client.Index<Document1>(doc);

```

**and the Mapping looks like**

"newindexnesttest":{"mappings":{"document1":{"properties":{"file":{"type":"attachment","fields":{"content":{"type":"string"},"author":{"type":"string"},"title":{"type":"string"},"name":{"type":"string"},"date":{"type":"date","format":"strict\_date\_optional\_time||epoch\_millis"},"keywords":{"type":"string"},"content\_type":{"type":"string"},"content\_length":{"type":"integer"},"language":{"type":"string"}}},"title":{"type":"string"}}}}}}

I have two issues.

1. I am able to search strings until certain part of the documents, for the strings in the middle and end of the documents returns ZERO hits.

2. Highlighting does not work for me.

The Search query is

```
          var queryString1 = "CapUpdateRequest";

            var searchRes = client.Search<Document1>(s => s
                .From(0)
                .Size(10000)
                .AllIndices()
                .AllTypes()
                .Query(qs => qs.QueryString(q => q.Query(queryString1)))
                .Highlight(h => h                        
                .PreTags("<b>")
                .PostTags("</b>")
                .Fields(
                f => f.Field(e => e.File)                    
                .PreTags("<em>")
                .PostTags("/em>")
                )
                )
                );  

```

Am i missing something, try to get a break from last couple of days.

---

<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, 10:48pm UTC](https://discuss.elastic.co/t/elasticsearch-search-query-and-highlight-on-the-attachment-not-working-as-expected/51034/2 "2017-07-05T22:48:53Z")

</div>


