1
votes

I am new to elasticsearch and want to use the official Python API. I have below code:

from elasticsearch import Elasticsearch

es = Elasticsearch(timeout=60)
es.indices.create(index='test')

mapping={
          "mappings": {
            "user": {
              "properties": {
                "name": { "type": "text" },
                "user_name": { "type": "keyword" },
                "email": { "type": "keyword" }
              }
            },
            "tweet": {
              "properties": {
                "content": { "type": "text" },
                "user_name": { "type": "keyword" },
                "tweeted_at": { "type": "date" }
              }
            }
          }
        }
es.indices.put_mapping(index='test',body=mapping)

However I got below error:

RequestError: RequestError(400, 'mapper_parsing_exception', 'Root mapping definition has unsupported parameters: [mappings : {tweet={properties={tweeted_at={type=date}, user_name={type=keyword}, content={type=text}}}, user={properties={user_name={type=keyword}, name={type=text}, email={type=keyword}}}}]')

This mapping is copied from:https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html

Could anyone help figure out what was wrong here?

Many thanks

1
Elasticsearch version?Nishant

1 Answers

0
votes

The error is telling you that something is wrong in the mapping format you are using.

What is wrong?

  1. The format is not valid for ES 7.x (typeless API: you should not specify any doc type in the mapping)
  2. This mapping defines two type of document which is not support since ES 6.0

If you are working with ES 7 (which seems the case looking at the error message) you should use this mapping:

PUT twitter
{
  "mappings": {
    "properties": {
      "type": { "type": "keyword" }, 
      "name": { "type": "text" },
      "user_name": { "type": "keyword" },
      "email": { "type": "keyword" },
      "content": { "type": "text" },
      "tweeted_at": { "type": "date" }
    }
  }
}

Or use two different index, one for the user, and another for the tweet.

PUT user
{
  "mappings": {
    "properties": {
      "name": { "type": "text" },
      "user_name": { "type": "keyword" },
      "email": { "type": "keyword" }
    }
  }
}
PUT tweet
{
  "mappings": {
    "properties": {
      "user_name": { "type": "keyword" },
      "content": { "type": "text" },
      "tweeted_at": { "type": "date" }
    }
  }
}