# Unable to index a json string (array of json objects) to elastic search

**URL:** <https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851>\
**Category:** Elasticsearch\
**Created:** [February 19, 2021, 12:14pm UTC](https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851 "2021-02-19T12:14:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![schawla](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@schawla](https://discuss.elastic.co/u/schawla)\
**Post date:** [February 19, 2021, 12:14pm UTC](https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851/1 "2021-02-19T12:14:46Z")

</div>

I have an array of objects in the form of a single json string something like

`"[{"id": 1, "name":"test"}, {"id": 2, "name":"test2"}]"`

I want to be able to bulk index this json string directly to elastic search without having to deserialize it into a model since the usual client.IndexMany() takes in an IEnumerable as parameter.

`var response = client.Bulk<StringResponse>("indexname", jsonString);`

I am getting a 400 response on trying to do the above.

---

<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:** [February 19, 2021, 12:27pm UTC](https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851/2 "2021-02-19T12:27:25Z")

</div>

You can't do that.

You must index individual documents.

Note that the Bulk API is expecting aother format with header and body. See

> **[Bulk API | Elasticsearch Reference \[7.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html)**

---

<div class="post-metadata">

**Author:** ![schawla](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@schawla](https://discuss.elastic.co/u/schawla)\
**Post date:** [February 19, 2021, 12:39pm UTC](https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851/3 "2021-02-19T12:39:51Z")

</div>

Assume i am successfully using the above format , can i still send a json string to the Bulk api or the IndexMany() method ?? Did you mean passing a json string works only for a single document at a time ?

Or do i have to first convert the json string (right format) i have to an `IEnumerable<object>` and then pass it something like this -

`IEnumerable<object>` objsToIndex = something;  
var response= client.Bulk("indexname", PostData.MultiJson(objsToIndex));

---

<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:** [February 19, 2021, 1:12pm UTC](https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851/4 "2021-02-19T13:12:41Z")

</div>

You need to convert it to something elasticsearch can understand. I don't know the method you mentioned.

---

<div class="post-metadata">

**Author:** ![schawla](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@schawla](https://discuss.elastic.co/u/schawla)\
**Post date:** [February 19, 2021, 1:29pm UTC](https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851/5 "2021-02-19T13:29:00Z")

</div>

Can you please share an example of what conversion you are referring to.

---

<div class="post-metadata">

**Author:** ![schawla](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@schawla](https://discuss.elastic.co/u/schawla)\
**Post date:** [February 19, 2021, 1:49pm UTC](https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851/6 "2021-02-19T13:49:12Z")

</div>

also, are you aware if can we use `Elasticsearch.Net` or `NEST` to interact with aws managed elastic search instance ?

---

<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:** [February 19, 2021, 5:46pm UTC](https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851/7 "2021-02-19T17:46:10Z")

</div>

That might work but we can't support you here as it's not official.

BTW did you look at [Cloud by Elastic](https://www.elastic.co/cloud), also available if needed from [AWS Marketplace](https://aws.amazon.com/marketplace/pp/B01N6YCISK) ?

Cloud by elastic is one way to have access to **all features** , all managed by us. Think about what is there yet like Security, Monitoring, Reporting, SQL, Canvas, Maps UI, Alerting and built-in solutions named [Observability](https://www.elastic.co/observability), [Security](https://www.elastic.co/security), [Enterprise Search](https://www.elastic.co/enterprise-search) and what is coming next 🙂 ...

---

<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:** [February 19, 2021, 5:47pm UTC](https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851/8 "2021-02-19T17:47:10Z")

</div>

Not an array but something which is described in the bulk api link I shared.

I don't know what are the other options for .net though.

---

<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:** [March 19, 2021, 5:47pm UTC](https://discuss.elastic.co/t/unable-to-index-a-json-string-array-of-json-objects-to-elastic-search/264851/9 "2021-03-19T17:47:31Z")

</div>

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