{"id":23794,"date":"2026-12-06T22:05:59","date_gmt":"2026-12-06T22:05:59","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=23794"},"modified":"2026-12-06T22:05:59","modified_gmt":"2026-12-06T22:05:59","slug":"elasticsearch-lab2-bulk-indexing-document-using-mget-bulk-api","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/elasticsearch-lab2-bulk-indexing-document-using-mget-bulk-api\/","title":{"rendered":"Elasticsearch Lab#2 \u2013 Bulk indexing document using mget &#038; bulk api"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This lab uses the Elasticsearch <code>_mget<\/code> API to fetch several documents in one request and the <code>_bulk<\/code> API to index, create, update and delete many documents in one request, including loading a whole NDJSON file. The commands in the example above were written for older typed versions of Elasticsearch, so this page also gives corrected versions that run on Elasticsearch 7.x and 8.x with security enabled.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Data<\/h2>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">$ wget https:<span class=\"hljs-comment\">\/\/gist.githubusercontent.com\/devops-school\/0a09b9e55efb45bcf397d501feb38965\/raw\/92179a491c6a717c70280619a8a6e3e64b2b0de3\/customers_full.json<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/e9f7fd82d4fadfbdea2111fd545b6289.js\"><\/script>\n\n\n\n<h1 class=\"wp-block-heading\">Reference<\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>Sample Data &amp; Query &#8211; https:\/\/github.com\/devopsschool-demo-labs-projects\/elasticsearch<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What mget and bulk actually do<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Despite the lab title, <code>_mget<\/code> does not index anything. It is a read API that returns several documents by ID in a single round trip, instead of sending one <code>GET \/index\/_doc\/id<\/code> request per document. <code>_bulk<\/code> is the write API: it accepts many index, create, update and delete operations in one request, which is far faster than sending them one at a time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The bulk body is <strong>NDJSON<\/strong> (newline-delimited JSON). Each operation is an action line, and for most actions a source line follows it. Every line, including the last one, must end with a newline character.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Action<\/th><th>Source line<\/th><th>Behaviour<\/th><\/tr><\/thead><tbody><tr><td><code>index<\/code><\/td><td>Full document<\/td><td>Creates the document, or replaces it if the ID already exists<\/td><\/tr><tr><td><code>create<\/code><\/td><td>Full document<\/td><td>Creates the document; that item fails with 409 if the ID exists<\/td><\/tr><tr><td><code>update<\/code><\/td><td><code>{&quot;doc&quot;: {...}}<\/code> or a script<\/td><td>Partially updates an existing document; fails with 404 if it is missing<\/td><\/tr><tr><td><code>delete<\/code><\/td><td>None<\/td><td>Deletes the document by ID<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">What changed since the example above was written<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The gist uses <code>_type<\/code> (<code>mobiles<\/code>, <code>shoes<\/code>, <code>personal<\/code>) and typed URLs such as <code>\/products\/mobiles\/_mget<\/code> and <code>\/customers\/personal\/_bulk<\/code>. Mapping types were limited to one per index in 6.x, deprecated in 7.x and removed in 8.x. On a current cluster these requests fail.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Elasticsearch 8.x:<\/strong> remove <code>_type<\/code> from every action line and request body, and drop the type segment from the URL (<code>\/products\/_bulk<\/code>, not <code>\/products\/shoes\/_bulk<\/code>).<\/li>\n\n\n<li><strong>Elasticsearch 6.x and 7.x:<\/strong> an index can hold only one type. The lab indexes <code>mobiles<\/code> and then <code>shoes<\/code> into the same <code>products<\/code> index, and the second request is rejected with *final mapping would have more than 1 type*.<\/li>\n\n\n<li><strong>Security on by default in 8.x:<\/strong> port 9200 serves HTTPS and needs credentials. Plain <code>curl localhost:9200<\/code> returns <code>curl: (52) Empty reply from server<\/code> or a 401 error.<\/li>\n\n\n<li>The first <code>_mget<\/code> call uses the auto-generated ID <code>nL_Fd3EBQb932Ywx993J<\/code>, which only existed on the author&#039;s cluster. On your cluster it returns <code>&quot;found&quot;: false<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Connect to a secured cluster<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Set a few shell variables once, so the commands below stay short. On first start, Elasticsearch 8.x prints the <code>elastic<\/code> password and generates <code>http_ca.crt<\/code>. Archive installs keep it in <code>config\/certs\/<\/code> and package installs keep it in <code>\/etc\/elasticsearch\/certs\/<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">export<\/span> ES_URL=https:<span class=\"hljs-comment\">\/\/localhost:9200<\/span>\n<span class=\"hljs-keyword\">export<\/span> ES_CA=<span class=\"hljs-regexp\">\/etc\/<\/span>elasticsearch\/certs\/http_ca.crt\n<span class=\"hljs-keyword\">export<\/span> ELASTIC_PASSWORD=<span class=\"hljs-string\">'your-elastic-password'<\/span>\n\ncurl -s --cacert <span class=\"hljs-string\">\"$ES_CA\"<\/span> -u <span class=\"hljs-string\">\"elastic:$ELASTIC_PASSWORD\"<\/span> <span class=\"hljs-string\">\"$ES_URL\/_cluster\/health?pretty\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> On a throwaway lab VM you can replace <code>--cacert &quot;$ES_CA&quot;<\/code> with <code>-k<\/code> to skip certificate verification. Do not do this against shared or production clusters. If you are on a 6.x\/7.x cluster without security, use <code>ES_URL=http:\/\/localhost:9200<\/code> and leave out <code>--cacert<\/code> and <code>-u<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Corrected bulk examples<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run these before the mget examples so that documents 1 to 4 exist. The first request indexes documents with explicit IDs. The <code>_index<\/code> is in the action line, so the URL is just <code>\/_bulk<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">curl -s --cacert <span class=\"hljs-string\">\"$ES_CA\"<\/span> -u <span class=\"hljs-string\">\"elastic:$ELASTIC_PASSWORD\"<\/span> -X POST <span class=\"hljs-string\">\"$ES_URL\/_bulk?pretty\"<\/span> \\\n  -H <span class=\"hljs-string\">'Content-Type: application\/x-ndjson'<\/span> -d<span class=\"hljs-string\">'\n{ \"index\" : { \"_index\" : \"products\", \"_id\" : \"1\" } }\n{ \"name\": \"Adidas\", \"size\": 10, \"color\": \"white\" }\n{ \"index\" : { \"_index\" : \"products\", \"_id\" : \"2\" } }\n{ \"name\": \"Reebok\", \"size\": 7, \"color\": \"blue\" }\n{ \"index\" : { \"_index\" : \"products\", \"_id\" : \"3\" } }\n{ \"name\": \"Puma\", \"size\": 9, \"color\": \"black\" }\n{ \"index\" : { \"_index\" : \"products\", \"_id\" : \"4\" } }\n{ \"name\": \"New Balance\", \"size\": 8, \"color\": \"black\" }\n'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">To let Elasticsearch generate IDs, put the index in the URL and send an empty action object:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">curl -s --cacert <span class=\"hljs-string\">\"$ES_CA\"<\/span> -u <span class=\"hljs-string\">\"elastic:$ELASTIC_PASSWORD\"<\/span> -X POST <span class=\"hljs-string\">\"$ES_URL\/products\/_bulk?pretty\"<\/span> \\\n  -H <span class=\"hljs-string\">'Content-Type: application\/x-ndjson'<\/span> -d<span class=\"hljs-string\">'\n{ \"index\" : {} }\n{ \"name\": \"Puma\", \"size\": 9, \"color\": \"black\" }\n{ \"index\" : {} }\n{ \"name\": \"New Balance\", \"size\": 8, \"color\": \"black\" }\n'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Mixed operations can be sent in one request, as the gist intended. The gist&#039;s note to paste them one at a time is not needed. Elasticsearch runs the items in order, and each item succeeds or fails on its own.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">curl -s --cacert <span class=\"hljs-string\">\"$ES_CA\"<\/span> -u <span class=\"hljs-string\">\"elastic:$ELASTIC_PASSWORD\"<\/span> -X POST <span class=\"hljs-string\">\"$ES_URL\/products\/_bulk?pretty\"<\/span> \\\n  -H <span class=\"hljs-string\">'Content-Type: application\/x-ndjson'<\/span> -d<span class=\"hljs-string\">'\n{ \"delete\" : { \"_id\" : \"2\" } }\n{ \"create\" : { \"_id\" : \"5\" } }\n{ \"name\": \"Nike Power\", \"size\": 12, \"color\": \"black\" }\n{ \"update\" : { \"_id\" : \"1\" } }\n{ \"doc\" : { \"color\" : \"orange\" } }\n'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Run the mixed request a second time and the <code>create<\/code> item returns status 409 (<code>version_conflict_engine_exception<\/code>), because document 5 now exists. The <code>delete<\/code> item returns <code>not_found<\/code>. Both results are expected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Corrected mget examples<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Without types, each entry needs only <code>_index<\/code> and <code>_id<\/code>. You can also limit the fields returned with <code>_source<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">curl -s --cacert <span class=\"hljs-string\">\"$ES_CA\"<\/span> -u <span class=\"hljs-string\">\"elastic:$ELASTIC_PASSWORD\"<\/span> -X GET <span class=\"hljs-string\">\"$ES_URL\/_mget?pretty\"<\/span> \\\n  -H <span class=\"hljs-string\">'Content-Type: application\/json'<\/span> -d<span class=\"hljs-string\">'\n{\n  \"docs\": &#91;\n    { \"_index\": \"products\", \"_id\": \"1\" },\n    { \"_index\": \"products\", \"_id\": \"2\", \"_source\": &#91;\"name\", \"color\"] }\n  ]\n}\n'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">When every document is in the same index, put the index in the URL and use the shorter <code>ids<\/code> form:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">curl -s --cacert <span class=\"hljs-string\">\"$ES_CA\"<\/span> -u <span class=\"hljs-string\">\"elastic:$ELASTIC_PASSWORD\"<\/span> -X GET <span class=\"hljs-string\">\"$ES_URL\/products\/_mget?pretty\"<\/span> \\\n  -H <span class=\"hljs-string\">'Content-Type: application\/json'<\/span> -d<span class=\"hljs-string\">'{ \"ids\": &#91;\"1\", \"2\", \"3\"] }'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The response contains a <code>docs<\/code> array in the same order as the request. If you ran the mixed bulk request first, document 2 was deleted. It comes back as <code>&quot;found&quot;: false<\/code> instead of failing the whole request.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Loading a JSON file with the bulk API<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Download the sample file with one of the <code>wget<\/code> commands above, then look at the first two lines: <code>head -n 2 customers_full.json<\/code>. Line 1 must be an action line and line 2 a document.<\/li>\n\n\n<li>If the action lines contain <code>&quot;_type&quot;<\/code> and you are on 8.x, remove it, for example with <code>sed -i &#039;s\/&quot;_type&quot; *: *&quot;[^&quot;]*&quot; *, *\/\/&#039; customers_full.json<\/code>. Then check the result with <code>head<\/code> again.<\/li>\n\n\n<li>Make sure the file ends with a newline: <code>[ -n &quot;$(tail -c1 customers_full.json)&quot; ] &amp;&amp; echo &gt;&gt; customers_full.json<\/code>. This fixes the *must be terminated by a newline* error shown in the gist.<\/li>\n\n\n<li>Optionally create the index first with your own mappings. If you don&#039;t, it is created automatically with dynamic mappings.<\/li>\n\n\n<li>Send the file with <code>--data-binary<\/code>, not <code>-d<\/code>, and print only the error summary so a large response does not flood the terminal.<\/li>\n\n\n<li>Verify the document count.<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">curl -s --cacert <span class=\"hljs-string\">\"$ES_CA\"<\/span> -u <span class=\"hljs-string\">\"elastic:$ELASTIC_PASSWORD\"<\/span> -X PUT <span class=\"hljs-string\">\"$ES_URL\/customers?pretty\"<\/span>\n\ncurl -s --cacert <span class=\"hljs-string\">\"$ES_CA\"<\/span> -u <span class=\"hljs-string\">\"elastic:$ELASTIC_PASSWORD\"<\/span> -X POST \\\n  <span class=\"hljs-string\">\"$ES_URL\/customers\/_bulk?refresh=wait_for&amp;filter_path=errors,items.*.error\"<\/span> \\\n  -H <span class=\"hljs-string\">'Content-Type: application\/x-ndjson'<\/span> --data-binary @customers_full.json\n\ncurl -s --cacert <span class=\"hljs-string\">\"$ES_CA\"<\/span> -u <span class=\"hljs-string\">\"elastic:$ELASTIC_PASSWORD\"<\/span> <span class=\"hljs-string\">\"$ES_URL\/_cat\/indices\/customers?v\"<\/span>\ncurl -s --cacert <span class=\"hljs-string\">\"$ES_CA\"<\/span> -u <span class=\"hljs-string\">\"elastic:$ELASTIC_PASSWORD\"<\/span> <span class=\"hljs-string\">\"$ES_URL\/customers\/_count?pretty\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">A clean load prints <code>{&quot;errors&quot;:false}<\/code>. <code>-d @file<\/code> strips newlines from the file, which corrupts NDJSON. <code>--data-binary<\/code> sends the bytes unchanged. The inline <code>-d&#039;...&#039;<\/code> examples work only because the newlines are typed into the command itself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> The gist also posts <code>sam.json<\/code>, a file that is never created in the lab. Skip that command, or replace it with your own NDJSON file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Reading the response and fixing common errors<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A bulk request returns HTTP 200 even when some items fail. Always check the top-level <code>&quot;errors&quot;<\/code> flag, then look at the <code>status<\/code> and <code>error<\/code> of each entry in <code>items<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Error<\/th><th>Cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td><code>The bulk request must be terminated by a newline [\\n]<\/code><\/td><td>The last line has no trailing newline, or <code>-d @file<\/code> stripped the newlines<\/td><td>Append a newline and use <code>--data-binary<\/code><\/td><\/tr><tr><td><code>Action\/metadata line [1] contains an unknown parameter [_type]<\/code><\/td><td>Typed bulk syntax sent to 8.x<\/td><td>Remove <code>_type<\/code> from action lines and URLs<\/td><\/tr><tr><td><code>final mapping would have more than 1 type<\/code><\/td><td>Two types sent to one index on 6.x\/7.x<\/td><td>Use one type per index, or better, a separate index per entity<\/td><\/tr><tr><td><code>curl: (52) Empty reply from server<\/code><\/td><td>Plain HTTP sent to an HTTPS port on 8.x<\/td><td>Use <code>https:\/\/<\/code> with <code>--cacert<\/code> and credentials<\/td><\/tr><tr><td>401 <code>security_exception<\/code><\/td><td>Missing or wrong credentials<\/td><td>Pass <code>-u elastic:password<\/code> or an API key header<\/td><\/tr><tr><td>406 <code>Content-Type header [...] is not supported<\/code><\/td><td>No <code>Content-Type<\/code> header<\/td><td>Add <code>-H &#039;Content-Type: application\/x-ndjson&#039;<\/code> (or <code>application\/json<\/code>)<\/td><\/tr><tr><td>413 Request Entity Too Large<\/td><td>Body exceeds <code>http.max_content_length<\/code> (100 MB by default)<\/td><td>Split the file into smaller requests<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Best practices for bulk loading<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Size batches by bytes, not by document count. Start with a few megabytes to around 15 MB per request, measure throughput, and adjust.<\/li>\n\n\n<li>To split a large file, use an even line count so that action and source lines stay together: <code>split -l 20000 customers_full.json part_<\/code>. Make sure every part ends with a newline.<\/li>\n\n\n<li>Use <code>refresh=wait_for<\/code> or <code>refresh=true<\/code> only in labs or small loads. For large imports, leave refresh off, or set <code>index.refresh_interval<\/code> to <code>-1<\/code> during the load and restore it afterwards.<\/li>\n\n\n<li>Use <code>create<\/code> instead of <code>index<\/code> when re-running a load must not overwrite existing documents.<\/li>\n\n\n<li>Define mappings before loading production data. Dynamic mapping can guess field types wrongly, and a wrong type cannot be changed without reindexing.<\/li>\n\n\n<li>Use a dedicated user or API key with write privileges on the target index instead of the <code>elastic<\/code> superuser, and keep passwords out of shell history.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Can the mget API be used to index documents?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>_mget<\/code> only retrieves documents by ID. To index, update or delete many documents in one request, use <code>_bulk<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why does the bulk API return 200 even though some documents failed?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Each item in a bulk request succeeds or fails on its own, so the HTTP status describes the request as a whole. Check the top-level <code>errors<\/code> field and the <code>status<\/code> of each item to find failures.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I still use _type in Elasticsearch 8?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Mapping types were removed in 8.x, so <code>_type<\/code> in bulk or mget bodies and typed URLs such as <code>\/index\/type\/_bulk<\/code> are rejected. Use one index per kind of data instead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why should I use &#8211;data-binary instead of -d with curl for bulk files?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>curl -d @file<\/code> strips carriage returns and newlines from the file, which breaks the NDJSON format the bulk API requires. <code>--data-binary<\/code> sends the file exactly as it is.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How big should a bulk request be?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">There is no single correct size. Start with a few megabytes up to about 15 MB per request, measure indexing throughput, and adjust. Stay well below the <code>http.max_content_length<\/code> limit, which is 100 MB by default.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/what-is-elasticsearch-and-use-cases-of-elasticsearch\/\">What is Elasticsearch and use cases of Elasticsearch?<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/top-50-elasticsearch-interview-questions-and-answers\/\">Top 50 Elasticsearch Interview Questions and Answers<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/what-is-elk-stack-and-use-cases-of-elk-stack\/\">What is ELK Stack and use cases of ELK Stack?<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/monitoring-observability\/elastic\/\">More Elastic Stack (ELK) tutorials<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This lab uses the Elasticsearch _mget API to fetch several documents in one request and the _bulk API to index, create, update and delete many documents in&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5936],"tags":[4666],"class_list":["post-23794","post","type-post","status-publish","format-standard","hentry","category-elastic","tag-elasticsearch"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/23794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=23794"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/23794\/revisions"}],"predecessor-version":[{"id":80705,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/23794\/revisions\/80705"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=23794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=23794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=23794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}