Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple elasticsearch input - Rejecting mapping update final mapping would have more than 1 type: [_doc, doc]

I'm trying to send data to elasticsearch but running into an issue where my number field only comes up as a string. These are the steps I took.

Step 1. Add index & map

PUT http://123.com:5101/core_060619/

{
  "mappings": {
    "properties": {
      "date": {
        "type":   "date",
        "format": "HH:mm yyyy-MM-dd"
      },
        "data": {
        "type":   "integer"
      }
    }
  }
}

Result:

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "core_060619"
}

Step 2. Add data

PUT http://123.com:5101/core_060619/doc/1

{
  "test" : [ {
    "data" : "119050300",
    "date" : "00:00 2019-06-03"
  } ]
}

Result:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Rejecting mapping update to [zyxnewcoreyxbl_060619] as the final mapping would have more than 1 type: [_doc, doc]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [zyxnewcoreyxbl_060619] as the final mapping would have more than 1 type: [_doc, doc]"
    },
    "status": 400
}
like image 912
Jimmy Avatar asked Jan 27 '23 05:01

Jimmy


1 Answers

You can not have more than one type of document in Elasticsearch 6.0.0+. If you set your document type to doc, then you can add another document by simply PUT http://123.com:5101/core_060619/doc/1, PUT http://123.com:5101/core_060619/doc/2 etc.

Elasticsearch 6.+

PUT core_060619/
{
  "mappings": {
    "doc": {     //type of documents in index is 'doc'
     "properties": {
        "date": {
          "type":   "date",
          "format": "HH:mm yyyy-MM-dd"
        },
          "data": {
          "type":   "integer"
        }
      }
    }
  }
}

Since we created mapping to have doc type of documents, now we can add new documents by simply adding /doc/_id:

PUT core_060619/doc/1
{
  "test" : [ {
    "data" : "119050300",
    "date" : "00:00 2019-06-03"
  } ]
}


PUT core_060619/doc/2
{
  "test" : [ {
    "data" : "111120300",
    "date" : "10:15 2019-06-02"
  } ]
}  

Elasticsearch 7.+

Types are removed, but you can use custom like field(s):

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

PUT twitter/_doc/user-kimchy
{
  "type": "user", 
  "name": "Shay Banon",
  "user_name": "kimchy",
  "email": "[email protected]"
}

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

GET twitter/_search
{
  "query": {
    "bool": {
      "must": {
        "match": {
          "user_name": "kimchy"
        }
      },
      "filter": {
        "match": {
          "type": "tweet" 
        }
      }
    }
  }
}

Removal of mapping types

like image 55
dejanmarich Avatar answered Jun 01 '23 22:06

dejanmarich