elastic创建文档时报错 "{"error":"Incorrect HTTP method for uri [//product] and method [PUT], allowed: [POST]","status":405}"
代码
$params = [ 'index' => 'product', 'body' => [ 'settings' => [ 'number_of_shards' => 1, 'number_of_replicas' => 0 ], 'mappings' => [ '_doc' => [ '_source' => [ 'enabled' => true ], 'properties' => [ 'name' => [ 'type' => 'text', 'analyzer' => 'ik_max_word', 'search_analyzer' => 'ik_max_word' ], 'description' => [ 'type' => 'text', 'analyzer' => 'ik_max_word', 'search_analyzer' => 'ik_max_word' ] ] ] ] ] ]; $hosts = [ 'http://192.168.153.17:9200/', ]; $client = ClientBuilder::create() ->setHosts($hosts) ->build(); // Create the index with mappings and settings now $response = $client->indices()->create($params);
执行报错:
检查代码
发现是elastic地址多了斜杠、去除即可