1

I am trying to create custom mapping type in elasticsearch 7.3.2 using nodejs client!.But it's only creating default _doc type mapping.When I provide custom doc type it throws me an error that you should give include_type_name = true but in elasticsearch 7.3.2 mapping type has been deprecated!

I have already tried giving custom mapping type with include_type_name=true.

        var indexName = req.body.indexName;
        var mappingType = req.body.mappingType;
        const mapping = {
            properties: {
                name: {
                    type: "text",
                    analyzer: "autocomplete",
                    search_analyzer: "standard"
                },
                createdate: {
                    type: "date"
                }
            }
        }
        await esClient.indices.putMapping({
            index: indexName,
            type: mappingType,
            include_type_name:true,
            body: mapping
        }, (err: any, resp: any, status: any) => {
            if (err) {
                return res.status(400).json({ status, err });
            }
            res.status(200).json({ resp, status });
        })
    }

Expected:I am trying to create custom mapping type because when I ingest the data from Mongodb by using Transporter it takes the mapping type as the name of the collection and the mapping that I am creating which has a default _doc type mapping. Error:"Rejecting mapping update to [tag] as the final mapping would have more than 1 type: [_doc, tags]" tags(collection name

1 Answer 1

2

Yes, that's an expected behavior in ES 7 (onwards), only a single mapping type is supported and it's is called _doc by default.

As you've noticed, you can change that behavior in ES7 by adding include_type_name=true to your call. (That won't work in ES8 anymore, though).

The thing is that you can only do it at index creation time, i.e. you cannot modify the mapping type name after the index has been created. So, since you don't control the index creation from MongoDB, all you can do is to create an index template in ES that will kick in once your index will be created.

Run this in Kibana Dev Tools before the index creation:

PUT _template/tags?include_type_name=true
{
  "index_patterns": ["my-index*"],            <--- change this pattern to match yours
  "mappings": {
    "tags": {
      "properties": {
        "name": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "standard"
        },
        "createdate": {
          "type": "date"
        }
      }
    }
  }
}

That way, when the my-index index gets created, it will automatically get a mapping type called tags instead of the default _doc one.

Sign up to request clarification or add additional context in comments.

5 Comments

Thankyou so much.
when i am doing this with kibana its working properly but when i am doing the same with node program its showing mapper parser exception because include_type_name parameter is not available.Can you explain me how should I approach this problem.
Since this question is closed, please create a new question referencing this one.
The custom mapping is getting created but after running the functionality its still showing this error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.