# Is it possible to have fields of different type while using multi\_field?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-have-fields-of-different-type-while-using-multi-field/25455>\
**Category:** Elasticsearch\
**Created:** [July 13, 2015, 3:00pm UTC](https://discuss.elastic.co/t/is-it-possible-to-have-fields-of-different-type-while-using-multi-field/25455 "2015-07-13T15:00:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [July 13, 2015, 3:00pm UTC](https://discuss.elastic.co/t/is-it-possible-to-have-fields-of-different-type-while-using-multi-field/25455/1 "2015-07-13T15:00:27Z")

</div>

I am trying to index plain text as well as text from attachment.  
Following is the mapping that i use:

```
PUT /my-index/doc_set/_mapping
{
  "properties": {
    "doc_id": {
      "type": "string"
    },
    "text": {
      "type": "multi_field",
      "fields": {
        "text": {
          "type": "string",
          "store": true,
          "index": "analyzed"
        },
        "pdf": {
          "type": "attachment",
          "fields": {
            "pdf": {
              "type": "string",
              "store": true,
              "index": "analyzed"
            }
          }
        }
      }
    }
  }
}

```

How can I index `text` and `text.pdf`? `text` should accept plain text and `text.pdf` should index Base64. I try following indexing:

```
POST /my-index/doc_set/15
{
  "doc_id": "15",
  "text": "simple text for doc"
}

POST /my-index/doc_set/23
{
  "doc_id": "23",
  "text.pdf": "simplest text for doc"
}

```

The first document should not give any error but I get this:

```
{
   "error": "MapperParsingException[failed to parse]; nested: JsonParseException[Illegal white space character (code 0x20) as character #3 of 4-char base64 unit: can only used between units\n at [Source: [B@66b0738e; line: 3, column: 32]]; ",
   "status": 400
}

```

and second one is indexed without errors but a new field `text.pdf` is created.

How should I go about it?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [July 13, 2015, 3:13pm UTC](https://discuss.elastic.co/t/is-it-possible-to-have-fields-of-different-type-while-using-multi-field/25455/2 "2015-07-13T15:13:24Z")

</div>

In general it sure is. See the example here: [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-core-types.html#token\_count](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-core-types.html#token_count)

I don't know about your specific error though. Looks like the string type is trying to parse the pdf contents as a string maybe?

---

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [July 13, 2015, 3:46pm UTC](https://discuss.elastic.co/t/is-it-possible-to-have-fields-of-different-type-while-using-multi-field/25455/3 "2015-07-13T15:46:46Z")

</div>

Actually it should not as `attachment` type accepts Base62 encoded version of a string. So, `text.pdf` should throe an error and `text` should be accepted without any error.

I added to the mapping `dynamic: strict` and noticed that this raised error:

```
{
   "error": "StrictDynamicMappingException[mapping set to strict, dynamic introduction of [text.pdf] within [doc_set] is not allowed]",
   "status": 400
}

```

Am I accessing `pdf` and `text` field the wrong way??

---

<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, 12:01am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-fields-of-different-type-while-using-multi-field/25455/4 "2017-07-06T00:01:47Z")

</div>


