G
G
great_772020-03-08 07:32:50
PHP
great_77, 2020-03-08 07:32:50

Can't create index in ElaticSearch: Types cannot be provided in put mapping requests, what's the problem?

error:

Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true.

Technologies : PHP, Elastica
When adding mapping to the created index:
$elasticaType = $elasticaIndex->getType('single');

        $params = [
            'id' => [
                'type' => 'integer',
            ],
            'user' => [
            	'type' => 'object',
            	'properties' => [
            		'name' => [
            			'type' => 'keyword',
            		],
            		'fullName' => [
            			'type' => 'keyword',
            		]
            	]
            ],
            'name' => [
                'type' => 'keyword',
                'boost' => 2
            ],
            'description' => [
                'type' => 'text'
            ],
            'price' => [
                'type' => 'integer'
            ],
            'date' => [
            	'type' => 'date'                        
            ]
        ];

        $mapping = new \Elastica\Type\Mapping();
        $mapping->setType($elasticaType); 
        $mapping->setProperties($params);
        $mapping->send();


Creating an index:
$hosts = [
            'host' => 'elasticsearch',
            'port' => 9200
        ];

        $client = new Client($hosts);

        $elasticaIndex = $client->getIndex('track');

        $params = [
            'settings' => [
                'number_of_shards' => 2,
                'number_of_replicas' => 1,
    			'analysis' => [
    	            'analyzer' => [
    	                'default' => [
    	                    'type' => 'custom',
    	                    'tokenizer' => 'standard',
    	                    'filter' => ['lowercase', 'mySnowball']
    	                ],
    	                'default_search' => [
    	                    'type' => 'custom',
    	                    'tokenizer' => 'standard',
    	                    'filter' => ['standard', 'lowercase', 'mySnowball']
    	                ]
    	            ],
    	            'filter' => [
    	                'mySnowball' => [
    	                    'type' => 'snowball',
    	                    'language' => 'English'
    	                ]
    	            ]
                ]
            ]
      ];
        $elasticaIndex->create($params, true);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
great_77, 2020-03-08
@great_77

Turn on: include_type_name
https://stackoverflow.com/questions/56803895/elast...

$mapping = new \Elastica\Type\Mapping();
        $mapping->setType($elasticaType); 
        $mapping->setProperties($params);

        $mapping->send(['include_type_name' => true]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question