# How to perform atomic operations using a java client

**URL:** https://discuss.elastic.co/t/how-to-perform-atomic-operations-using-a-java-client/363769
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [July 25, 2024, 9:01am UTC](https://discuss.elastic.co/t/how-to-perform-atomic-operations-using-a-java-client/363769 "2024-07-25T09:01:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kotomi\_Ichinose](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kotomi_ichinose/32/136298_2.png) [@Kotomi\_Ichinose](https://discuss.elastic.co/u/Kotomi_Ichinose)
#### Post date: [July 25, 2024, 9:01am UTC](https://discuss.elastic.co/t/how-to-perform-atomic-operations-using-a-java-client/363769/1 "2024-07-25T09:01:58Z")

</div>

java client

> **[Introduction | Elasticsearch Java API Client \[8.14\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/introduction.html)**

I want to do the following with a java client.  
I couldn't find a way to do it in the documentation.

```auto
POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "logs-nginx.access-prod",
        "alias": "logs"
      }
    },
    {
      "add": {
        "index": "logs-my_app-default",
        "alias": "logs"
      }
    }
  ]
}

```

---

<div class="post-metadata">

### Author: ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)
#### Post date: [July 25, 2024, 12:47pm UTC](https://discuss.elastic.co/t/how-to-perform-atomic-operations-using-a-java-client/363769/2 "2024-07-25T12:47:52Z")

</div>

From #Elastic Search to #Elasticsearch

---

<div class="post-metadata">

### Author: ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)
#### Post date: [July 25, 2024, 12:47pm UTC](https://discuss.elastic.co/t/how-to-perform-atomic-operations-using-a-java-client/363769/3 "2024-07-25T12:47:52Z")

</div>

Added #language-clients

---

<div class="post-metadata">

### Author: ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)
#### Post date: [July 25, 2024, 3:35pm UTC](https://discuss.elastic.co/t/how-to-perform-atomic-operations-using-a-java-client/363769/4 "2024-07-25T15:35:06Z")

</div>

Hello and welcome! This endpoint is a bit hard to find in the client, but here it is:

```java
esClient.indices()
    .updateAliases(u -> u
        .actions(
            Action.of(a -> a
                .remove(r -> r
                    .index("logs-nginx.access-prod")
                    .alias("logs"))),
            Action.of(a -> a
                .add(ad -> ad
                    .index("logs-my_app-default")
                    .alias("logs")))));

```

---

<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: [August 22, 2024, 3:35pm UTC](https://discuss.elastic.co/t/how-to-perform-atomic-operations-using-a-java-client/363769/5 "2024-08-22T15:35:51Z")

</div>

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