How to set mapping before indexing records?

I want to set my custom mapping before index, how can i use it?

My mapping:
> $client = \Elasticsearch\ClientBuilder::create()->build();

$mappingFields = [
  'index' => 'staff',
    'body' => [
      'mapping' => [
        'person' => [
          'properties' => [
            'first-name' => [
              'type' => 'string'
             ],
           ]
         ]
       ]
     ]
   ]
    $client->indices()->create($mappingFields);
   $params = [
            '_index' => 'staff',
            '_type' => 'person',
            '_id' => 1,
            'body' => [
                'first-name' => 'ABC',
            ]
        ];
  $client->index($params);

And i always get this error message "error":"IndexAlreadyExistsException[[staff] already exists]","status":400}", Do i config or write something wrong? Could someone help me?

Thanks

Does the index exist? Check with _cat/indices.

Yes, it does.

Then you need to delete it, you cannot update an existing mapping like that.

Yes, i have delete it already, but it errors when i work with new index

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.