# Save base64 file ------mapper-attachments

**URL:** <https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290>\
**Category:** Elasticsearch\
**Created:** [June 20, 2016, 9:05am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290 "2016-06-20T09:05:07Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![xuzhou2020](https://avatars.discourse-cdn.com/v4/letter/x/898d66/32.png) [@xuzhou2020](https://discuss.elastic.co/u/xuzhou2020)\
**Post date:** [June 20, 2016, 9:05am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/1 "2016-06-20T09:05:07Z")

</div>

Hi, everyone.  
as you know, English is not my native language. I just know a little.

elastic version 2.2.1  
windows 7 OS  
jdk 1.8

=================  
my problem is :  
when I install mapper-attachments, restart elasticserach,

1. create mapping
2. post a record , then errors as followed.  
(if you use http client, such as RestClient of Firefox , errors are the same)

Exception in thread "main" MapperParsingException[failed to parse]; nested: NotSerializableExceptionWrapper[json\_parse\_exception: Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')  
at [Source: org.elasticsearch.common.io.stream.InputStreamStreamInput@14324dcf; line: 1, column: 27]];  
at org.elasticsearch.index.mapper.DocumentParser.innerParseDocument(DocumentParser.java:163)  
at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:79)  
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:304)  
at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:580)  
at org.elasticsearch.index.shard.IndexShard.prepareIndexOnPrimary(IndexShard.java:559)  
at org.elasticsearch.action.index.TransportIndexAction.prepareIndexOperationOnPrimary(TransportIndexAction.java:211)  
at org.elasticsearch.action.index.TransportIndexAction.executeIndexRequestOnPrimary(TransportIndexAction.java:223)  
at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:157)  
at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:65)  
at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryPhase.doRun(TransportReplicationAction.java:595)  
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)  
at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:263)  
at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:260)  
at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:350)  
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  
at java.lang.Thread.run(Thread.java:745)  
Caused by: NotSerializableExceptionWrapper[json\_parse\_exception: Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')  
at [Source: org.elasticsearch.common.io.stream.InputStreamStreamInput@14324dcf; line: 1, column: 27]]  
at com.fasterxml.jackson.core.JsonParser.\_constructError(JsonParser.java:1581)  
at com.fasterxml.jackson.core.base.ParserMinimalBase.\_reportError(ParserMinimalBase.java:533)  
at com.fasterxml.jackson.core.base.ParserMinimalBase.\_reportUnexpectedChar(ParserMinimalBase.java:462)  
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.\_handleUnexpectedValue(UTF8StreamJsonParser.java:2610)  
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:795)  
at org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:53)  
at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:273)  
at org.elasticsearch.index.mapper.DocumentParser.innerParseDocument(DocumentParser.java:131)

---

<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:** [June 20, 2016, 10:35am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/2 "2016-06-20T10:35:29Z")

</div>

Can you run `GET yourindex/yourtype/_mapping` (replace `yourindex` and `yourtype`)  
Can you post the exact request you sent?

---

<div class="post-metadata">

**Author:** ![xuzhou2020](https://avatars.discourse-cdn.com/v4/letter/x/898d66/32.png) [@xuzhou2020](https://discuss.elastic.co/u/xuzhou2020)\
**Post date:** [June 20, 2016, 10:43am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/3 "2016-06-20T10:43:55Z")

</div>

I am sorry to bother you ..

==============================

```
{
    "op":
    {
        "mappings":
        {
            "atta":
            {
                "properties":
                {
                    "atta":
                    {
                        "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"
                            }
                        }
                    },
                    "id":
                    {
                        "type": "string"
                    },
                    "logtime":
                    {
                        "type": "string"
                    },
                    "title":
                    {
                        "type": "string",
                        "analyzer": "ik",
                        "include_in_all": false
                    }
                }
            }
        }
    }
}
```

---

<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:** [June 20, 2016, 12:19pm UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/4 "2016-06-20T12:19:11Z")

</div>

Can you copy here the PUT/POST request you are sending to Elasticsearch?

---

<div class="post-metadata">

**Author:** ![xuzhou2020](https://avatars.discourse-cdn.com/v4/letter/x/898d66/32.png) [@xuzhou2020](https://discuss.elastic.co/u/xuzhou2020)\
**Post date:** [June 21, 2016, 1:38am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/5 "2016-06-21T01:38:02Z")

</div>

method : post  
url : [http://localhost:9200/op/atta/1](http://localhost:9200/op/atta/1)  
body  
{  
"id":"at001",  
"logtime":'2016-06-20 10:30:00",  
"title":"上传附件测试",  
"attach":"6IOM5pmv6Imy5piv57qi6Imy55qELOiuoeeul+acuuaKgOacr+eahOWPkeWxlSzlhZrnmoQxM+Wkp+W3sue7j+WPrOW8gC5ramxpbmvpnIDopoHmi5vogZjmlrDlkZjlt6XkuoblkJc/Cg=="

}

errors as followed:

```
{
    "error":
    {
        "root_cause":
        [
            {
                "type": "mapper_parsing_exception",
                "reason": "failed to parse"
            }
        ],
        "type": "mapper_parsing_exception",
        "reason": "failed to parse",
        "caused_by":
        {
            "type": "json_parse_exception",
            "reason": "Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: org.elasticsearch.common.io.stream.InputStreamStreamInput@2efeea1b; line: 3, column: 12]"
        }
    },
    "status": 400
}
```

---

<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:** [June 21, 2016, 3:40am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/6 "2016-06-21T03:40:06Z")

</div>

```
"logtime":'2016-06-20 10:30:00"

```

Should be:

```
"logtime":"2016-06-20 10:30:00"
```

---

<div class="post-metadata">

**Author:** ![xuzhou2020](https://avatars.discourse-cdn.com/v4/letter/x/898d66/32.png) [@xuzhou2020](https://discuss.elastic.co/u/xuzhou2020)\
**Post date:** [June 21, 2016, 3:49am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/7 "2016-06-21T03:49:23Z")

</div>

Thank you. Thank God.  
It is the problem.

---

<div class="post-metadata">

**Author:** ![xuzhou2020](https://avatars.discourse-cdn.com/v4/letter/x/898d66/32.png) [@xuzhou2020](https://discuss.elastic.co/u/xuzhou2020)\
**Post date:** [June 21, 2016, 6:14am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/8 "2016-06-21T06:14:12Z")

</div>

## Hi: some new problems;

I post a data

but I can not search the attament

1. get the data:

[http://localhost:9200/op/atta/1](http://localhost:9200/op/atta/1)

{"\_index":"op","\_type":"atta","\_id":"1","\_version":1,"found":true,"\_source":{  
"id":"at001",  
"logtime":"2016-06-20 10:30:00",  
"title":"上传附件测试",  
"attach":"6IOM5pmv6Imy5piv57qi6Imy55qELOiuoeeul+acuuaKgOacr+eahOWPkeWxlSzlhZrnmoQxM+Wkp+W3sue7j+WPrOW8gC5ramxpbmvpnIDopoHmi5vogZjmlrDlkZjlt6XkuoblkJc/Cg=="

}}

1. search it

[http://localhost:9200/op/atta/\_search?size=100&pretty&q=attach:kjlink](http://localhost:9200/op/atta/_search?size=100&pretty&q=attach:kjlink)

{  
"took" : 5,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

the attachment  
6IOM5pmv6Imy5piv57qi6Imy55qELOiuoeeul+acuuaKgOacr+eahOWPkeWxlSzlhZrnmoQxM+Wkp+W3sue7j+WPrOW8gC5ramxpbmvpnIDopoHmi5vogZjmlrDlkZjlt6XkuoblkJc/Cg==

base64 decode is:

背景色是红色的,计算机技术的发展,党的13大已经召开.kjlink需要招聘新员工了吗?

so, if I search the key word, it should appear.  
but no result returned.

---

<div class="post-metadata">

**Author:** ![ajoealex](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ajoealex](https://discuss.elastic.co/u/ajoealex)\
**Post date:** [June 21, 2016, 6:35am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/9 "2016-06-21T06:35:13Z")

</div>

Try

```
 http://localhost:9200/op/atta/_search?size=100&pretty&q=atta.attach:kjlink
```

---

<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:** [June 21, 2016, 6:38am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/10 "2016-06-21T06:38:39Z")

</div>

Try first without the mapper attachment plugin. Just index text and try to search for terms you wish.

If it doesn't work you need to adjust the mapping and define the right analyzer for your language.

---

<div class="post-metadata">

**Author:** ![xuzhou2020](https://avatars.discourse-cdn.com/v4/letter/x/898d66/32.png) [@xuzhou2020](https://discuss.elastic.co/u/xuzhou2020)\
**Post date:** [June 21, 2016, 7:36am UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/11 "2016-06-21T07:36:57Z")

</div>

1. If I search other field, e.g. tilte that'll be ok.
2. if I define the mapping like this:

{  
"atta": {  
"properties": {  
"id": {  
"type": "string"  
},  
"logtime": {  
"type": "string"  
},  
"title": {  
"type": "string",  
"analyzer": "ik",  
"include\_in\_all": false  
},  
"atta": {  
"type": "attachment",  
**"analyzer": "ik"**  
}  
}  
}  
}

then wrong msg:

{"error":{"root\_cause":[{"type":"mapper\_parsing\_exception","reason":"Mapping definition for [atta] has unsupported parameters: [analyzer : ik]"}],"type":"mapper\_parsing\_exception","reason":"Mapping definition for [atta] has unsupported parameters: [analyzer : ik]"},"status":400}

---

<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:41pm UTC](https://discuss.elastic.co/t/save-base64-file-mapper-attachments/53290/12 "2017-07-05T22:41:50Z")

</div>


