# Import specific fields only - Elasticsearch bulk import

**URL:** <https://discuss.elastic.co/t/import-specific-fields-only-elasticsearch-bulk-import/123012>\
**Category:** Elasticsearch\
**Created:** [March 8, 2018, 6:42am UTC](https://discuss.elastic.co/t/import-specific-fields-only-elasticsearch-bulk-import/123012 "2018-03-08T06:42:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhilash\_Sathe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhilash_sathe/32/28555_2.png) [@Abhilash\_Sathe](https://discuss.elastic.co/u/Abhilash_Sathe)\
**Post date:** [March 8, 2018, 6:42am UTC](https://discuss.elastic.co/t/import-specific-fields-only-elasticsearch-bulk-import/123012/1 "2018-03-08T06:42:05Z")

</div>

Is there a way where we can **_ignore certain JSON keys_** inside a JSON dump while doing a `bulk` import in **elasticsearch**.

I'm currently working with Node JS. As mentioned in the below code, `data.json` contains certain `JSON keys` that I would want `elasticsearch` to ignore while importing. These keys can be of any type, example an Object, a string, a boolean, etc.

```
var bulkIndex = function bulkIndex(index, type, data) {
    let bulkBody = [];

    data.forEach(item => {
        bulkBody.push({
            index: {
                _index: index,
                _type: type,
                _id: item.id
            }
        });

        bulkBody.push(item);
    });

    esClient.bulk({
            body: bulkBody
        })
        .then(response => {
            let errorCount = 0;
            response.items.forEach(item => {
                if (item.index && item.index.error) {
                    console.log(++errorCount, item.index.error);
                }
            });
            console.log(`Successfully indexed ${data.length - errorCount} out of ${data.length} items`);
        })
        .catch(console.err);
};
const test = function test() {
    const rawJSON = fs.readFileSync('data.json');
    const processedJSON = JSON.parse(rawJSON);
    console.log(`${processedJSON.length} items parsed from data file`);
    bulkIndex('myIndex', 'myType', processedJSON);
};
test();
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 8, 2018, 11:12am UTC](https://discuss.elastic.co/t/import-specific-fields-only-elasticsearch-bulk-import/123012/2 "2018-03-08T11:12:46Z")

</div>

Can't you do that in your JS code?

---

<div class="post-metadata">

**Author:** ![Abhilash\_Sathe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhilash_sathe/32/28555_2.png) [@Abhilash\_Sathe](https://discuss.elastic.co/u/Abhilash_Sathe)\
**Post date:** [March 8, 2018, 12:04pm UTC](https://discuss.elastic.co/t/import-specific-fields-only-elasticsearch-bulk-import/123012/3 "2018-03-08T12:04:35Z")

</div>

Yes, that's what I'm going to do now. The JSON is basically Shopify's storefront product data. I've decided to use GraphQL and get specific fields only from the corresponding API.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 5, 2018, 12:04pm UTC](https://discuss.elastic.co/t/import-specific-fields-only-elasticsearch-bulk-import/123012/4 "2018-04-05T12:04:36Z")

</div>

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