# Weird Behavior of Elastic Search

**URL:** <https://discuss.elastic.co/t/weird-behavior-of-elastic-search/16722>\
**Category:** Elasticsearch\
**Created:** [March 31, 2014, 7:37pm UTC](https://discuss.elastic.co/t/weird-behavior-of-elastic-search/16722 "2014-03-31T19:37:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajeev\_reddy](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@rajeev\_reddy](https://discuss.elastic.co/u/rajeev_reddy)\
**Post date:** [March 31, 2014, 7:37pm UTC](https://discuss.elastic.co/t/weird-behavior-of-elastic-search/16722/1 "2014-03-31T19:37:23Z")

</div>

Hi All,

Elastic search mapper attachment for attaching pdf and docx files into  
ElasticSearch. When i am searching ElastiSearch for particular string the  
search results are giving zero. If i am giving single character, the search  
is giving results.

ElasticSearch Version: 1.1.0  
Mapper Attachment version: 2.0.0

Machine Details: Windows 2008 Server R2 Service pack1  
Java run Time: Java 7 update 1

I also attached the pdf file which i indexed into Elastic Search. The pdf  
file has word called Sample.

Any help is greatly appreciated. I am stuck here. Please help me.

Here is my search queries:

1. _POST /cg\_attachments/IncidentRequest/\_search?pretty=true_  
_{"query":{"query\_string":{"fields":["attachmentFullpath","attachmentContenttype"],"query":"Sample"}},"fields":["attachmentParentId"]}_

Elastic Search Response:  
{  
"took": 45,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"failed": 0  
},  
"hits": {  
"total": 0,  
"max\_score": null,  
"hits": []  
}  
}

1. _POST /cg\_attachments/IncidentRequest/\_search?pretty=true_  
_{"query":{"query\_string":{"fields":["attachmentFullpath","attachmentContenttype"],"query":"c"}},"fields":["attachmentParentId"]}_

Response from elasticSearch:  
{  
"took": 453,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"failed": 0  
},  
"hits": {  
"total": 6,  
"max\_score": 0.061956294,  
"hits": [  
{  
"\_index": "cg\_attachments",  
"\_type": "IncidentRequest",  
"\_id": "39",  
"\_score": 0.061956294,  
"fields": {  
"attachmentParentId": [  
52  
]  
}  
},  
{  
"\_index": "cg\_attachments",  
"\_type": "IncidentRequest",  
"\_id": "40",  
"\_score": 0.061956294,  
"fields": {  
"attachmentParentId": [  
53  
]  
}  
},  
{  
"\_index": "cg\_attachments",  
"\_type": "IncidentRequest",  
"\_id": "41",  
"\_score": 0.061956294,  
"fields": {  
"attachmentParentId": [  
53  
]  
}  
},  
{  
"\_index": "cg\_attachments",  
"\_type": "IncidentRequest",  
"\_id": "42",  
"\_score": 0.061956294,  
"fields": {  
"attachmentParentId": [  
54  
]  
}  
},  
{  
"\_index": "cg\_attachments",  
"\_type": "IncidentRequest",  
"\_id": "43",  
"\_score": 0.061956294,  
"fields": {  
"attachmentParentId": [  
55  
]  
}  
},  
{  
"\_index": "cg\_attachments",  
"\_type": "IncidentRequest",  
"\_id": "44",  
"\_score": 0.061956294,  
"fields": {  
"attachmentParentId": [  
55  
]  
}  
}  
]  
}  
}

3.\* GET /cg\_attachments/IncidentRequest/42\*  
working correctly. Getting correct response.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/cf8b84ad-1bde-4f78-a798-ccd898ada2d7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cf8b84ad-1bde-4f78-a798-ccd898ada2d7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [March 31, 2014, 7:42pm UTC](https://discuss.elastic.co/t/weird-behavior-of-elastic-search/16722/2 "2014-03-31T19:42:58Z")

</div>

Can you show the code of how you index the pdf as well as the mapping?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/babcf89c-c808-4787-a6e0-69e5c5967328%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/babcf89c-c808-4787-a6e0-69e5c5967328%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![rajeev\_reddy](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@rajeev\_reddy](https://discuss.elastic.co/u/rajeev_reddy)\
**Post date:** [March 31, 2014, 7:48pm UTC](https://discuss.elastic.co/t/weird-behavior-of-elastic-search/16722/3 "2014-03-31T19:48:07Z")

</div>

I used NEST for indexing documents to Elasticsearch. Here is the code  
snippet.

```
        try
        {

            Task<IBulkResponse> bulkResponse;
            foreach (string currentItem in files)
            {
                log.Info("Started indexing information into

```

elasticSearch" + currentItem);  
byte fileArray = File.ReadAllBytes(currentItem);

```
                int entityId = IndexerHelper.GetEntityId(currentItem);
                string myType = IndexerHelper.GetTypeName(currentItem);
                bulkRequest.Index<Attachments>(m => m.Object(new

```

Attachments  
{  
AttachmentContenttype =  
IndexerHelper.GetContentType(currentItem),  
AttachmentEncodedfile =  
Convert.ToBase64String(fileArray, 0,  
fileArray.Length,Base64FormattingOptions.InsertLineBreaks),  
AttachmentFullpath = currentItem,  
AttachmentLastmodified =  
File.GetLastWriteTime(currentItem),  
AttachmentParentId =  
IndexerHelper.GetParentId(currentItem)  
})  
.Index(indexName)  
.Type(myType)  
.Id(entityId)  
);  
bulkCount++;  
if (bulkRequestSize == bulkCount)  
{  
bulkResponse = esBulkClient.BulkAsync(bulkRequest);  
bulkCount = 0;  
bulkRequest = new BulkDescriptor();  
}  
fileArray = null;  
}

```
            bulkResponse = esBulkClient.BulkAsync(bulkRequest);

            foreach (BulkOperationResponseItem item in

```

bulkResponse.Result.Items)  
{  
if (item.OK == false && item.Error != null)  
{  
log.Error("Not indexed ID:" + item.Id + " of Type:"

- item.Type);  
log.Error(" Error is:" + item.Error);  
}  
}

On Mon, Mar 31, 2014 at 3:42 PM, Binh Ly [binhly\_es@yahoo.com](mailto:binhly_es@yahoo.com) wrote:

> Can you show the code of how you index the pdf as well as the mapping?
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/RU5a2wSZCYc/unsubscribe](https://groups.google.com/d/topic/elasticsearch/RU5a2wSZCYc/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/babcf89c-c808-4787-a6e0-69e5c5967328%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/babcf89c-c808-4787-a6e0-69e5c5967328%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/babcf89c-c808-4787-a6e0-69e5c5967328%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/babcf89c-c808-4787-a6e0-69e5c5967328%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
R R R

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAOLrPN7JFp1wwKmktk%3Dqn-Tm7oNgBVQ%3DmtM6E0MdVFDSu0bn6g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOLrPN7JFp1wwKmktk%3Dqn-Tm7oNgBVQ%3DmtM6E0MdVFDSu0bn6g%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [April 1, 2014, 8:29pm UTC](https://discuss.elastic.co/t/weird-behavior-of-elastic-search/16722/4 "2014-04-01T20:29:23Z")

</div>

Attachments require a specific mapping. It is likely that your mapping is  
not correct. Here is a simple example of how to index a PDF with the proper  
attachment type:

```
    class T1
    {
    }

    private static void IndexPdf()
    {
        var settings = new ConnectionSettings(new 

```

Uri("[http://localhost:9200](http://localhost:9200)"), "\_all");  
var client = new ElasticClient(settings);

```
        client.CreateIndex("foo", c => c
            .AddMapping<T1>(m => m
                .Properties(props => props
                    .Attachment(s => s
                        .Name("file")
                        .FileField(fs => fs.Store())
                    )
                )
            )
        );

        var doc = new { file = new {
            content = 

```

Convert.ToBase64String(File.ReadAllBytes(@"C:\ESData\pdf\fn6742.pdf")),  
\_indexed\_chars = -1  
}};

```
        client.Index(doc, i => i.Index("foo").Type("t1"));
    }

```

Then after that you can run a search like this:

POST localhost:9200/foo/t1/\_search  
{  
"fields": "file",  
"query": {  
"match": {  
"file": "blah bah"  
}  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9b3a7cf5-f3b7-45d7-881e-099c803f7bdc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9b3a7cf5-f3b7-45d7-881e-099c803f7bdc%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![rajeev\_reddy](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@rajeev\_reddy](https://discuss.elastic.co/u/rajeev_reddy)\
**Post date:** [April 1, 2014, 9:26pm UTC](https://discuss.elastic.co/t/weird-behavior-of-elastic-search/16722/5 "2014-04-01T21:26:08Z")

</div>

I am indexing it the same way as you suggested.

I am able to properly index into elasticsearch. But the search  
functionality only not working. With the same code in other machine i am  
able to index and able to search also.

On Tue, Apr 1, 2014 at 4:29 PM, Binh Ly [binhly\_es@yahoo.com](mailto:binhly_es@yahoo.com) wrote:

> Attachments require a specific mapping. It is likely that your mapping is  
> not correct. Here is a simple example of how to index a PDF with the proper  
> attachment type:
> 
> ```
> class T1
> {
> }
> 
> private static void IndexPdf()
> {
> var settings = new ConnectionSettings(new Uri("
> 
> ```
> 
> [http://localhost:9200](http://localhost:9200)"), "\_all");  
> var client = new ElasticClient(settings);
> 
> ```
> client.CreateIndex("foo", c => c
> .AddMapping<T1>(m => m
> .Properties(props => props
> .Attachment(s => s
> .Name("file")
> .FileField(fs => fs.Store())
> )
> )
> )
> );
> 
> var doc = new { file = new {
> content =
> 
> ```
> 
> Convert.ToBase64String(File.ReadAllBytes(@"C:\ESData\pdf\fn6742.pdf")),  
> \_indexed\_chars = -1  
> }};
> 
> ```
> client.Index(doc, i => i.Index("foo").Type("t1"));
> }
> 
> ```
> 
> Then after that you can run a search like this:
> 
> POST localhost:9200/foo/t1/\_search  
> {  
> "fields": "file",  
> "query": {  
> "match": {  
> "file": "blah bah"  
> }  
> }  
> }
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/RU5a2wSZCYc/unsubscribe](https://groups.google.com/d/topic/elasticsearch/RU5a2wSZCYc/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/9b3a7cf5-f3b7-45d7-881e-099c803f7bdc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9b3a7cf5-f3b7-45d7-881e-099c803f7bdc%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/9b3a7cf5-f3b7-45d7-881e-099c803f7bdc%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9b3a7cf5-f3b7-45d7-881e-099c803f7bdc%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
R R R

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAOLrPN6zfu6D1w4Sp-5w5OKaJ3B63yNXzJ7zamMFjFEv3\_mAHg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAOLrPN6zfu6D1w4Sp-5w5OKaJ3B63yNXzJ7zamMFjFEv3_mAHg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:38am UTC](https://discuss.elastic.co/t/weird-behavior-of-elastic-search/16722/6 "2017-07-06T01:38:54Z")

</div>


