Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Elasticsearch is an open source, distributed search and analytics engine, used to store, index, and query complex data types like JSON structures. It's a powerful tool that helps you manage large amounts of data in near real-time. Laravel Scout is an official package for Laravel that enables seamless integration with Elasticsearch. However, recent changes in Elasticsearch have brought new challenges while using mapping types.
The Issue: In previous versions of Elasticsearch (< 6.0), indices could have multiple mapping types to support different data structures and document types. However, these types will be removed completely in Elasticsearch 7.x. This change affects how Laravel Scout's Elasticsearch driver interacts with the search engine.
The Solution: If you're using the Scout-Elasticsearch driver, Ivan Babenko provides two suggested methods to work around this issue. First, you can explicitly include the type_name parameter when creating indices using PUT requests:
PUT index?include_type_name=true // This is method 1
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"properties": {
"foo": "text"
}
}
}
An Alternative Approach: Secondly, you can create the _doc index template by simply placing a document with desired mapping in your Elasticsearch index. Using this method will have the downside of having to manually assign IDs for each new document. Here's an example:
PUT index/_doc/1
{
"foo": "baz"
}
How to Use Laravel Scout with Mapping Types: To use the new mapping types in your Elasticsearch indices, you can extend IndexConfigurator. An example configuration is shown below:
class TestIndexConfigurator extends IndexConfigurator
{
use Migratable;
/**
* @var array
*/
protected $settings = [
"number_of_shards" => 3,
"number_of_replicas" => 0
];
protected $name = 'test';
}
Conclusion: To work with indices without mapping types, you can choose either one of the above methods depending on your preference. If you're using Laravel Scout, you should extend the IndexConfigurator class and define the desired settings according to your Elasticsearch indices.
Note: When using Laravel 8+ and updating the driver from scout-elasticsearch-driver, ensure you use the newly provided methods. They make it easier to work with Elasticsearch indices and mapping types.
Additional Resources: For additional help, check out the Laravel Company Blog on Elasticsearch and Laravel integration or refer to the Elasticsearch documentation for further information on mapping types.
Summary: In summary, to use the driver for Laravel Scout with Elasticsearch in a way that supports the removal of mapping types, you can either set the include_type_name parameter or create the _doc index template. Alternatively, you can extend the IndexConfigurator class in your project, where you define the settings for your indices. The most important aspect is to stay updated with Laravel and Elasticsearch best practices.