An error is thrown when I try to create an index with no type
Elasticsearch\Common\Exceptions\RuntimeException: type is required for Index in /var/www/predelanet/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/Index.php:61
$data = [
'body' => [
'brand' => $product->brand,
'model' => $product->model,
'full_name' => $product->brand .' '. $product->model,
'text' => strip_tags($product->text),
'stext' => strip_tags($product->stext)
],
'index' => 'products',
//'type' => 'my_type',
'id' => 'my_id',
];
What's the sense to demand the _type_ when it is declared _deprecated_ according to the official docs?
Thank you!
What's the sense to demand the type when it is declared deprecated according to the official docs?
It's a good question. Unfortunately despite being deprecated, it's still a required component of the URL. Elasticsearch 6.x allows _any_ type name so long as there is only one type per index, but doesn't actually provide a default. E.g. if you try create a document with PUT /foo/1 it will fail because there is no type.
The 6.x docs tend to use the type "_doc" as the convention because the 7.x syntax will be PUT /{index_name}/_doc/{id} so it will match the new version nicely. But technically you can set it to anything you want (foo, my_type, etc). See: https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html#_schedule_for_removal_of_mapping_types
Because of those two points we still require the type to be specified since it's technically still required.
I suppose we could set a default in the client (_doc like the documentation suggests)... but we try to keep the client opinion-less and that injects at least a temporary opinion on how your data is structured in 6.x.
Let me poke a few other client authors and see what they're thoughts on defaulting to _doc are. Setting a default seems reasonable to me, thanks for the ticket!
I support the proposal to add a default type = '_doc'. However, this fails in my copy of ES version 5.6
'{"error":{"root_cause":[{"type":"invalid_type_name_exception","reason":"Document mapping type name can't start with '_', found: [_doc]"}],"type":"invalid_type_name_exception","reason":"Document mapping type name can't start with '_', found: [_doc]"},"status":400}'
Solved by @polyfractal in this comment.
More than 1 year later, this issue still up to date..
@BenGrandin this is not an issue from elasticsearch-php 7.0, we added _doc type as default: https://github.com/elastic/elasticsearch-php/blob/v7.0.0/src/Elasticsearch/Endpoints/Index.php#L42
Are you still using elasticsearch-php 6.x?
@ezimuel You were right. Even if my composer.json had elastic dependency to 7.*, I hadn't the correct version.
I remove my vendor folder and uninstall elastic then re-install. Now that's works !
Thank you for your time,
Ps : I am using docker, and new into Symfony world.
Most helpful comment
It's a good question. Unfortunately despite being deprecated, it's still a required component of the URL. Elasticsearch 6.x allows _any_ type name so long as there is only one type per index, but doesn't actually provide a default. E.g. if you try create a document with
PUT /foo/1it will fail because there is no type.The 6.x docs tend to use the type
"_doc"as the convention because the 7.x syntax will bePUT /{index_name}/_doc/{id}so it will match the new version nicely. But technically you can set it to anything you want (foo,my_type, etc). See: https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html#_schedule_for_removal_of_mapping_typesBecause of those two points we still require the type to be specified since it's technically still required.
I suppose we could set a default in the client (
_doclike the documentation suggests)... but we try to keep the client opinion-less and that injects at least a temporary opinion on how your data is structured in 6.x.Let me poke a few other client authors and see what they're thoughts on defaulting to
_docare. Setting a default seems reasonable to me, thanks for the ticket!