# EsHadoopRemoteException: illegal\_argument\_exception: only write ops with an op\_type of create are allowed in data streams?

**URL:** https://discuss.elastic.co/t/eshadoopremoteexception-illegal-argument-exception-only-write-ops-with-an-op-type-of-create-are-allowed-in-data-streams/340267
**Category:** Elasticsearch
**Tags:** elastic-stack-monitoring, es-hadoop
**Created:** [August 7, 2023, 12:13pm UTC](https://discuss.elastic.co/t/eshadoopremoteexception-illegal-argument-exception-only-write-ops-with-an-op-type-of-create-are-allowed-in-data-streams/340267 "2023-08-07T12:13:56Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Zephery\_Wen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zephery_wen/32/124417_2.png) [@Zephery\_Wen](https://discuss.elastic.co/u/Zephery_Wen)
#### Post date: [August 7, 2023, 12:13pm UTC](https://discuss.elastic.co/t/eshadoopremoteexception-illegal-argument-exception-only-write-ops-with-an-op-type-of-create-are-allowed-in-data-streams/340267/1 "2023-08-07T12:13:56Z")

</div>

I want to use Spark to save data to a data stream.

```java
JavaEsSparkSQL.saveToEs(result, dataStream, map);

```

It seems like 'saveToEs' only allows index.

```plaintext
EsHadoopRemoteException: illegal_argument_exception: only write ops with an op_type of create are allowed in data streams?

```

How to solve it?

Thanks!

---

<div class="post-metadata">

### Author: ![Zephery\_Wen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zephery_wen/32/124417_2.png) [@Zephery\_Wen](https://discuss.elastic.co/u/Zephery_Wen)
#### Post date: [August 8, 2023, 8:52am UTC](https://discuss.elastic.co/t/eshadoopremoteexception-illegal-argument-exception-only-write-ops-with-an-op-type-of-create-are-allowed-in-data-streams/340267/3 "2023-08-08T08:52:01Z")

</div>

Anyone can help?

---

<div class="post-metadata">

### Author: ![Keith\_Massey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/keith_massey/32/83666_2.png) [@Keith\_Massey](https://discuss.elastic.co/u/Keith_Massey)
#### Post date: [August 8, 2023, 10:02pm UTC](https://discuss.elastic.co/t/eshadoopremoteexception-illegal-argument-exception-only-write-ops-with-an-op-type-of-create-are-allowed-in-data-streams/340267/4 "2023-08-08T22:02:38Z")

</div>

Hi @Zephery_Wen. I think that you just need to set the hadoop configuration property [`es.write.operation`](https://www.elastic.co/guide/en/elasticsearch/hadoop/current/configuration.html#_operation) to `create`. That is set to `index` by default. [Data streams require this to be set to `create`](https://www.elastic.co/guide/en/elasticsearch/reference/current/set-up-a-data-stream.html#create-data-stream) since they are append only. See [Index API | Elasticsearch Guide [8.9] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#docs-index-api-op_type) for additional information about this.

---

<div class="post-metadata">

### Author: ![Zephery\_Wen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zephery_wen/32/124417_2.png) [@Zephery\_Wen](https://discuss.elastic.co/u/Zephery_Wen)
#### Post date: [August 9, 2023, 2:02am UTC](https://discuss.elastic.co/t/eshadoopremoteexception-illegal-argument-exception-only-write-ops-with-an-op-type-of-create-are-allowed-in-data-streams/340267/5 "2023-08-09T02:02:41Z")

</div>

Hi @Keith_Massey . I'm sorry for not describing my problem clearly. I want to merge or insert my data.

> known as _merge_ or insert if the data does not exist, updates if the data exists (based on its id).

So I have to set the hadoop configuration property [`es.write.operation`](https://www.elastic.co/guide/en/elasticsearch/hadoop/current/configuration.html#_operation) to `upsert` . Seems like `JavaEsSparkSQL.saveToEs` not support it?

---

<div class="post-metadata">

### Author: ![Keith\_Massey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/keith_massey/32/83666_2.png) [@Keith\_Massey](https://discuss.elastic.co/u/Keith_Massey)
#### Post date: [August 9, 2023, 1:07pm UTC](https://discuss.elastic.co/t/eshadoopremoteexception-illegal-argument-exception-only-write-ops-with-an-op-type-of-create-are-allowed-in-data-streams/340267/6 "2023-08-09T13:07:05Z")

</div>

I don't think that that is a limitation of `JavaEsSparkSQL.saveToEs` -- it's [a limitation of data streams](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams.html#data-streams-append-only). For example, I think even just hitting the Elasticsearch API directly you cannot upsert a document in a data stream.

---

<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: [September 6, 2023, 1:07pm UTC](https://discuss.elastic.co/t/eshadoopremoteexception-illegal-argument-exception-only-write-ops-with-an-op-type-of-create-are-allowed-in-data-streams/340267/7 "2023-09-06T13:07:32Z")

</div>

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