Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't create two Types to same index elasticsearch & Kibana

I'm new in elasticsearch and kibana

I'm doing some exercices with elasticsearch (create index,types and documents..)

I created an index 'business' with type 'building'

put /business/building/217 {   "adresse":"11 Pen Ave",   "floors":5,   "offices":7,   "loc":{     "lat":40.693479,     "lon":-73.983854   } } 

it works funny but when I tried to create another type like this

put /business/employee/330 {   "name":"Richard Bell",   "title":"Senior Accountant",   "salar_usd":115000.00,   "hiredate":"Jan 19, 2013" } 

then I got this error

{   "error": {     "root_cause": [       {         "type": "illegal_argument_exception",         "reason": "Rejecting mapping update to [business] as the final mapping would have more than 1 type: [employee, building]"       }     ],     "type": "illegal_argument_exception",     "reason": "Rejecting mapping update to [business] as the final mapping would have more than 1 type: [employee, building]"   },   "status": 400 } 
like image 598
YK mar Avatar asked Dec 04 '17 11:12

YK mar


People also ask

Can we have multiple type in single Elasticsearch index?

You can't. One type per index only.

Can index have multiple types?

No you cannot have several types within a single index as of ES 6.0.

How do you create multiple indices in Elasticsearch?

Elasticsearch provides bulk api but it only supports index , create , delete and update operations over already created indexes. We cannot create multiple new indexes at once.

What is the difference between index and type in Elasticsearch?

In RDBMS terms, index is a database and type can be a table which contains many rows( document in elasticsearch).


2 Answers

You're probably running Elasticsearch version 6 and as of that version ES doesn't allow you to create more than one type in any given index.

You need to store each of your document type inside a dedicated index, e.g.

PUT /business/building/217 {   "adresse":"11 Pen Ave",   "floors":5,   "offices":7,   "loc":{     "lat":40.693479,     "lon":-73.983854   } }  PUT /employees/employee/330 {   "name":"Richard Bell",   "title":"Senior Accountant",   "salar_usd":115000.00,   "hiredate":"Jan 19, 2013" } 
like image 140
Val Avatar answered Oct 02 '22 17:10

Val


see https://www.elastic.co/guide/en/elasticsearch/reference/6.2/removal-of-types.html for more.

Elasticsearch 6.x Indices created in 6.x only allow a single-type per index. Any name can be used for the type, but there can be only one. The preferred type name is _doc, so that index APIs have the same path as they will have in 7.0: PUT {index}/_doc/{id} and POST {index}/_doc

like image 39
Richard Avatar answered Oct 02 '22 17:10

Richard