{"action":"created","issue":{"url":"https://api.github.com/repos/elasticsearch/elasticsearch-php/issues/177","labels_url":"https://api.github.com/repos/elasticsearch/elasticsearch-php/issues/177/labels{/name}","comments_url":"https://api.github.com/repos/elasticsearch/elasticsearch-php/issues/177/comments","events_url":"https://api.github.com/repos/elasticsearch/elasticsearch-php/issues/177/events","html_url":"https://github.com/elasticsearch/elasticsearch-php/issues/177","id":54119392,"number":177,"title":"Bulk Indexing","user":{"login":"Blackhawk2165","id":10506701,"avatar_url":"https://avatars.githubusercontent.com/u/10506701?v=3","gravatar_id":"","url":"https://api.github.com/users/Blackhawk2165","html_url":"https://github.com/Blackhawk2165","followers_url":"https://api.github.com/users/Blackhawk2165/followers","following_url":"https://api.github.com/users/Blackhawk2165/following{/other_user}","gists_url":"https://api.github.com/users/Blackhawk2165/gists{/gist_id}","starred_url":"https://api.github.com/users/Blackhawk2165/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Blackhawk2165/subscriptions","organizations_url":"https://api.github.com/users/Blackhawk2165/orgs","repos_url":"https://api.github.com/users/Blackhawk2165/repos","events_url":"https://api.github.com/users/Blackhawk2165/events{/privacy}","received_events_url":"https://api.github.com/users/Blackhawk2165/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-12T22:55:02Z","updated_at":"2015-01-13T14:24:46Z","closed_at":null,"body":"Hello,\r\n\r\nMy name is Austin Harmon and I am new to elastic search. I am looking to index a couple hundred thousand documents with elastic search and I would like to use the php client to do it. I have my index set up with one shard and one replica since I have a smaller amount of documents. I have looked over all the syntax on the elastic search site and github. \r\nThis is what my index.php file looks like:\r\n\r\n<?php\r\nrequire 'vendor/autoload.php';\r\n\r\n$client = new Elasticsearch\\Client();\r\n$indexParams['index'] = 'rvuehistoricaldocuments2009-2013'; //mapping code\r\n\r\n\tfor ($i = 0; $i <= 50; $i++) {\r\n\t\t$params ['body'][] = array(\r\n\t\t\t'index' => array(\r\n\t\t\t\t'index' => 'rvuehistoricaldocuments2009-2013',\r\n\t\t\t\t'type' => 'documents',\r\n\t\t\t\t'_id' => $i,\r\n\t\t\t\t'body' => array(\r\n\t\t\t\t\t'_source' => array( //everthing in body is mapping code\r\n\t\t\t\t\t\t'enabled' => true\r\n\t\t\t\t\t),\r\n\t\t\t\t\t'properties' => array(\r\n\t\t\t\t\t\t'doc_name' => array(\r\n\t\t\t\t\t\t\t'type' => 'string',\r\n\t\t\t\t\t\t\t'analyzer' => 'standard'\r\n\t\t\t\t\t\t),\r\n\t\t\t\t\t\t'description' => array(\r\n\t\t\t\t\t\t\t'type' => 'string'\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t)\r\n\t\t);\r\n\r\n\t\t$params['body'][] = array (\r\n\t\t\t'rVuedoc'$i => 'ID'$i\r\n\t\t\t\r\n\t\t);\r\n\t\t\r\n\t\t$indexParams['body']['mappings']['documents'] = $myTypeMapping; //mapping code\r\n\t}\r\n\t\r\n\tjson_encode($params);\r\n\t\r\n\t$client->indices()->create($indexParams); //mapping code\r\n\t$responses = $client->bulk($params);\r\n\t\r\n?>\r\n\r\nI'm not sure if I have everything I need or if I'm doing this right so if you could let me know if this looks correct that would be very helpful.\r\n\r\nThank you,\r\nAustin Harmon"},"comment":{"url":"https://api.github.com/repos/elasticsearch/elasticsearch-php/issues/comments/69750841","html_url":"https://github.com/elasticsearch/elasticsearch-php/issues/177#issuecomment-69750841","issue_url":"https://api.github.com/repos/elasticsearch/elasticsearch-php/issues/177","id":69750841,"user":{"login":"polyfractal","id":1224228,"avatar_url":"https://avatars.githubusercontent.com/u/1224228?v=3","gravatar_id":"","url":"https://api.github.com/users/polyfractal","html_url":"https://github.com/polyfractal","followers_url":"https://api.github.com/users/polyfractal/followers","following_url":"https://api.github.com/users/polyfractal/following{/other_user}","gists_url":"https://api.github.com/users/polyfractal/gists{/gist_id}","starred_url":"https://api.github.com/users/polyfractal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/polyfractal/subscriptions","organizations_url":"https://api.github.com/users/polyfractal/orgs","repos_url":"https://api.github.com/users/polyfractal/repos","events_url":"https://api.github.com/users/polyfractal/events{/privacy}","received_events_url":"https://api.github.com/users/polyfractal/received_events","type":"User","site_admin":false},"created_at":"2015-01-13T14:24:46Z","updated_at":"2015-01-13T14:24:46Z","body":"You've mixed index/mapping creation with bulk indexing.  That syntax won't work.  First you need to [create the index with mappings](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html#mappings), then start bulk indexing into the newly created index.\r\n\r\nNon-tested code, but something like this is more what you are looking for:\r\n\r\n```php\r\nrequire 'vendor/autoload.php';\r\n\r\n$client = new Elasticsearch\\Client();\r\n\r\n// Create the index and mappings\r\n$mapping['index'] = 'rvuehistoricaldocuments2009-2013'; //mapping code\r\n$mapping['body'] = array(\r\n    'mappings' => array(\r\n        'documents' => array(\r\n            '_source' => array(\r\n                'enabled' => true\r\n            ),\r\n            'properties' => array(\r\n                'doc_name' => array(\r\n                    'type' => 'string',\r\n                    'analyzer' => 'standard'\r\n                ),\r\n                'description' => array(\r\n                    'type' => 'string'\r\n                )\r\n            )\r\n        )\r\n    )\r\n);\r\n\r\n$client->indices()->create($mapping);\r\n\r\n\r\n// Now index the documents\r\nfor ($i = 0; $i <= 10000; $i++) {\r\n    $params ['body'][] = array(\r\n        'index' => array(\r\n            'index' => 'rvuehistoricaldocuments2009-2013',\r\n            'type' => 'documents',\r\n            '_id' => $i,\r\n            'body' => array(\r\n                'foo' => 'bar'// Document body goes here\r\n            )\r\n        )\r\n    );\r\n\r\n    // Every 1000 documents stop and send the bulk request\r\n    if ($i % 1000) {\r\n        $responses = $client->bulk($params);\r\n\r\n        // erase the old bulk request\r\n        $params = array();\r\n\r\n        // unset the bulk response when you are done to save memory\r\n        unset($responses);\r\n    }\r\n}\r\n```"}}