# Custom Type Field Causes Multiple Types Error

**URL:** <https://discuss.elastic.co/t/custom-type-field-causes-multiple-types-error/138107>\
**Category:** Elasticsearch\
**Created:** [July 2, 2018, 12:36am UTC](https://discuss.elastic.co/t/custom-type-field-causes-multiple-types-error/138107 "2018-07-02T00:36:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darin\_Hensley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/darin_hensley/32/32794_2.png) [@Darin\_Hensley](https://discuss.elastic.co/u/Darin_Hensley)\
**Post date:** [July 2, 2018, 12:36am UTC](https://discuss.elastic.co/t/custom-type-field-causes-multiple-types-error/138107/1 "2018-07-02T00:36:20Z")

</div>

I am new to Elastic search. Following the article [https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html#\_custom\_type\_field](https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html#_custom_type_field) I made a index that could have multiple types using the `type` keyword.

Here is my song index:

```
% curl -X GET "localhost:9200/_all/_mapping?pretty=true"
{
  "song" : {
    "mappings" : {
      "_doc" : {
        "properties" : {
          "album" : {
            "type" : "text"
          },
          "artist" : {
            "type" : "text"
          },
          "date" : {
            "type" : "date"
          },
          "deleted" : {
            "type" : "boolean"
          },
          "filepath" : {
            "type" : "text"
          },
          "genre" : {
            "type" : "text"
          },
          "liked" : {
            "type" : "boolean"
          },
          "playlist" : {
            "type" : "text"
          },
          "title" : {
            "type" : "text"
          },
          "trackNumber" : {
            "type" : "text"
          },
          "type" : {
            "type" : "keyword"
          }
        }
      }
    }
  }
}

```

Use the elastic search node.js library, I tried inserting a artist with:

```
const { client } = require('../app/init-db');

const upsertArtist = (artist) => {
  var doc = {
    index: 'song',
    type: 'artist',
    body: {
      artist: artist
    }
  };

  return client.index(doc);
};

upsertArtist(tags[0].artist).catch(e => console.log(e))

```

But I get this error:

```
{ Error: [illegal_argument_exception] Rejecting mapping update to [song] as the final mapping would have more than 1 type: [_doc, artist]
    at respond (/home/one/gitlab/echo-music-player/node_modules/elasticsearch/src/lib/transport.js:308:15)
    at checkRespForFailure (/home/one/gitlab/echo-music-player/node_modules/elasticsearch/src/lib/transport.js:267:7)
    at HttpConnector.<anonymous> (/home/one/gitlab/echo-music-player/node_modules/elasticsearch/src/lib/connectors/http.js:165:7)
    at IncomingMessage.wrapper (/home/one/gitlab/echo-music-player/node_modules/elasticsearch/node_modules/lodash/lodash.js:4949:19)
    at IncomingMessage.emit (events.js:165:20)
    at endReadableNT (_stream_readable.js:1101:12)
    at process._tickCallback (internal/process/next_tick.js:152:19)
  status: 400,
  displayName: 'BadRequest',
  message: '[illegal_argument_exception] Rejecting mapping update to [song] as the final mapping would have more than 1 type: [_doc, artist]',
  path: '/song/artist',
  query: {},
  body: 
   { error: 
      { root_cause: [Array],
        type: 'illegal_argument_exception',
        reason: 'Rejecting mapping update to [song] as the final mapping would have more than 1 type: [_doc, artist]' },
     status: 400 },
  statusCode: 400,
  response: '{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [song] as the final mapping would have more than 1 type: [_doc, artist]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [song] as the final mapping would have more than 1 type: [_doc, artist]"},"status":400}',
  toString: [Function],
  toJSON: [Function] }

```

I followed the example on custom types for the new way of doing multiple types. Why is it saying there would be two types? As far as I see, I did it exactly like the example.

---

<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:** [July 2, 2018, 7:12am UTC](https://discuss.elastic.co/t/custom-type-field-causes-multiple-types-error/138107/2 "2018-07-02T07:12:12Z")

</div>

You should write this I think:

```auto
const upsertArtist = (artist) => {
  var doc = {
    index: 'song',
    type: '_doc',
    body: artist
  };

  return client.index(doc);
};

```

---

<div class="post-metadata">

**Author:** ![Darin\_Hensley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/darin_hensley/32/32794_2.png) [@Darin\_Hensley](https://discuss.elastic.co/u/Darin_Hensley)\
**Post date:** [July 2, 2018, 2:34pm UTC](https://discuss.elastic.co/t/custom-type-field-causes-multiple-types-error/138107/3 "2018-07-02T14:34:11Z")

</div>

Thank you, but this would not be using the custom types. From the article linked they do:

```
PUT twitter/_doc/user-kimchy
{
  "type": "user", 
  "name": "Shay Banon",
  "user_name": "kimchy",
  "email": "shay@kimchy.com"
}

PUT twitter/_doc/tweet-1
{
  "type": "tweet", 
  "user_name": "kimchy",
  "tweeted_at": "2017-10-24T09:00:00Z",
  "content": "Types are going away"
}

```

I see that they include `_doc` in the url ... twitter/\_doc/user-kimchy. Could that be why? How would I control that with the Elasticsearch node.js api?

---

<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:** [July 2, 2018, 2:46pm UTC](https://discuss.elastic.co/t/custom-type-field-causes-multiple-types-error/138107/4 "2018-07-02T14:46:45Z")

</div>

> Could that be why?

Yes. That's why my proposal fixes that.

> but this would not be using the custom types.

I think I see what you mean. try this then.

```auto
const upsertArtist = (artist) => {
  var doc = {
    index: 'song',
    type: '_doc',
    body: {
      type: 'artist',
      artist: artist
    }
  };

  return client.index(doc);
};

```

---

<div class="post-metadata">

**Author:** ![Darin\_Hensley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/darin_hensley/32/32794_2.png) [@Darin\_Hensley](https://discuss.elastic.co/u/Darin_Hensley)\
**Post date:** [July 14, 2018, 2:10am UTC](https://discuss.elastic.co/t/custom-type-field-causes-multiple-types-error/138107/5 "2018-07-14T02:10:31Z")

</div>

Thank you, this worked!

---

<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:** [August 11, 2018, 2:10am UTC](https://discuss.elastic.co/t/custom-type-field-causes-multiple-types-error/138107/6 "2018-08-11T02:10:32Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
