Search code examples
phpelasticsearchelasticsearch-php

Elasticsearch Mapping Types in PHP


I want to connect to our elasticsearch Server (V7.0.0) using the official PHP Client. The elasticsearch Documentation states that mapping types have been removed in Version 6.0.0.

But in the whole official PHP Client documentation types are still mentioned and seem necessary (e.g.):

// Set the index and type
$params = [
    'index' => 'my_index',
    'type' => 'my_type2',
    'body' => [
        'my_type2' => [
            '_source' => [
                'enabled' => true
            ],
            'properties' => [
                'first_name' => [
                    'type' => 'keyword',
                    'analyzer' => 'standard'
                ],
                'age' => [
                    'type' => 'integer'
                ]
            ]
        ]
    ]
];

// Update the index mapping
$client->indices()->putMapping($params);

Source

Can anyone explain to me why I still have to use types when they have been removed?


Solution

  • Mapping types were removed in Elasticsearch 7.x. In previous version (Elasticsearch 6.x you need to specify only ONE type per index), while in version 2.x - 5.6 you can use more than one type per index. Please check your documentation versions.

    Since you have Elasticsearch 6.0.0, you need to specify mappings type, and I'm not quite sure this API will even work with newer version of Elasticsearch 7.X

    Here's version matrix for php API:

    Elasticsearch Version   Elasticsearch-PHP Branch
    >= 6.6, < 7.0                              6.7.x
    >= 6.0, < 6.6                              6.5.x
    >= 5.0, < 6.0                                5.0
    >= 2.0, < 5.0                         1.0 or 2.0
    >= 1.0, < 2.0                         1.0 or 2.0
    <= 0.90.x                                    0.4