question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Easy way to bulk index a JSON Document?

See original GitHub issue

Hi, is there an easy way to bulk index a normal JSON document rather than formatting data to look like

[
    // action description
    { index:  { _index: 'myindex', _type: 'mytype', _id: 1 } },
     // the document to index
    { title: 'foo' },
    // action description
    { update: { _index: 'myindex', _type: 'mytype', _id: 2 } },
    // the document to update
    { doc: { title: 'foo' } },
    ...
]

as is shown in the elasticsearch-jsAPI Docs?

So basically I’m trying to omit the action description object, so my body would look like

[ 
   { data_source_1 },
   { data_source_2 },
   ...
]

I don’t mind the _id being auto generated (unless that has some negative consequences that I’m not aware of). I thought the bulk method also takes in the index and type in the parameters so it seems redundant to specify those for each document if you’re just indexing one type in one index. I guess you do still need the action verb, but it would be nice if you could specify that in the parameters as well.

I feel like a lot of JSON data out there doesn’t have the action description object, and so would have to be added after, which seems like a painful task. What are people doing when they have to index lots of documents at once?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
samechiksoncommented, Mar 9, 2017

Hi @adilld , es-json-load loads a normal JSON array directly into Elasticsearch. It does not generate a file which you can then use with the bulk API, which is what you seem to want to do.

In terms of usage, if you install it globally from npm (npm install es-json-load -g), then you should be able to use it in the same way as a normal binary. Something like this

es-json-load --data --file=/absolute/path/to/file --index=<index-name> --type=<type-name>

Make sense?

0reactions
samechiksoncommented, Mar 10, 2017

@adilld Sounds like you’re trying pipe data into ES, so consider using Logstash which is a dedicated tool written by Elastic for this. You can use CSV files directly.

If you are to use es-json-load, transforming a CSV file into a JSON file should work. Just make sure that the JSON file that you use is a JSON Array of objects. This would look something like [{},{},{},...]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Elasticsearch Bulk Index JSON Data - Stack Overflow
The first property/field in my JSON object is the RequestedCountry property that's why I use it in this example. productModel is my ...
Read more >
How to Bulk Index Elasticsearch Documents From A JSON ...
This article will demonstrate how to bulk index JSON documents from a file using Python.
Read more >
Elasticsearch Bulk Insert JSON Data | by Onexlab - Medium
In this article, We will show you how to insert bulk JSON data to Elasticsearch. We hope you are familiar with Elasticsearch if...
Read more >
Bulk API | Elasticsearch Guide [8.5] | Elastic
Provides a way to perform multiple index , create , delete , and update actions in a ... make sure that the JSON...
Read more >
24 Indexes for JSON Data - Oracle Help Center
To index multiple fields of a JSON object, you first create virtual columns for them. Then you create a composite B-tree index on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found